KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > communication > message > component > UIMessages


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.communication.message.component;
6
7 import java.util.List JavaDoc;
8 import org.exoplatform.faces.core.component.UIExoCommand;
9 import org.exoplatform.faces.core.component.UIPageListIterator;
10 import org.exoplatform.faces.core.component.model.PageListDataHandler;
11 import org.exoplatform.faces.core.component.model.Parameter;
12 import org.exoplatform.faces.core.event.ExoActionEvent;
13 import org.exoplatform.faces.core.event.ExoActionListener;
14 import org.exoplatform.services.communication.message.*;
15
16 /**
17  * @author Tuan Nguyen (tuan08@users.sourceforge.net)
18  * @since Aug 27, 2004
19  * @version $Id: UIMessages.java,v 1.3 2004/11/03 04:24:54 tuan08 Exp $
20  */

21 public class UIMessages extends UIExoCommand {
22   public final static String JavaDoc VIEW_MESSAGE_ACTION = "viewMessage" ;
23   public final static String JavaDoc MESSAGE_ID = "messageId" ;
24   public static Parameter viewMessageParam_ = new Parameter(ACTION, VIEW_MESSAGE_ACTION) ;
25   
26   private Folder folder_ ;
27   private UIPageListIterator uiPageIterator_ ;
28   private MessageService service_ ;
29   
30   public UIMessages(MessageService service) {
31     setId("UIMessageFolder") ;
32     setClazz("UIMessageFolder");
33     setRendererType("MessagesRenderer");
34     service_ = service ;
35     uiPageIterator_ = new UIPageListIterator(new PageListDataHandler()) ;
36     List JavaDoc children = getChildren() ;
37     children.add(uiPageIterator_);
38     addActionListener(ViewMessageActionListener.class, VIEW_MESSAGE_ACTION) ;
39   }
40   
41   public void changeFolder(Folder folder) throws Exception JavaDoc {
42     folder_ = folder ;
43     uiPageIterator_.setPageList(service_.getMessages(folder)) ;
44   }
45   
46   public void update() throws Exception JavaDoc {
47     uiPageIterator_.setPageList(service_.getMessages(folder_)) ;
48   }
49   
50   public List JavaDoc getMessages() { return uiPageIterator_.getObjectInCurrentPage() ; }
51   
52   public Folder getFolder() { return folder_ ; }
53   
54   static public class ViewMessageActionListener extends ExoActionListener {
55     public void execute(ExoActionEvent event) throws Exception JavaDoc {
56       UIMessages uiMessages = (UIMessages) event.getSource();
57       String JavaDoc messageId = event.getParameter(MESSAGE_ID) ;
58       Message message = uiMessages.service_.getMessage(messageId) ;
59       if(message.hasFlag(MessageHeader.RECENT_FLAG)) {
60         message.removeFlag(MessageHeader.RECENT_FLAG) ;
61         message.addFlag(MessageHeader.SEEN_FLAG);
62         uiMessages.service_.updateMessage(message);
63       }
64       UIAccount uiAccount = (UIAccount) uiMessages.getAncestorOfType(UIAccount.class) ;
65       UIViewMessage uiView = (UIViewMessage) uiAccount.getChildComponentOfType(UIViewMessage.class) ;
66       uiView.setMessage(message) ;
67       uiAccount.setRenderedComponent(UIViewMessage.class) ;
68     }
69   }
70   
71   public String JavaDoc getFamily() { return "org.exoplatform.portlets.communication.message.component.UIMessages" ; }
72   
73 }
Popular Tags