1 5 package org.exoplatform.portlets.communication.message.component; 6 7 import java.util.List ; 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 21 public class UIMessages extends UIExoCommand { 22 public final static String VIEW_MESSAGE_ACTION = "viewMessage" ; 23 public final static String 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 children = getChildren() ; 37 children.add(uiPageIterator_); 38 addActionListener(ViewMessageActionListener.class, VIEW_MESSAGE_ACTION) ; 39 } 40 41 public void changeFolder(Folder folder) throws Exception { 42 folder_ = folder ; 43 uiPageIterator_.setPageList(service_.getMessages(folder)) ; 44 } 45 46 public void update() throws Exception { 47 uiPageIterator_.setPageList(service_.getMessages(folder_)) ; 48 } 49 50 public List 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 { 56 UIMessages uiMessages = (UIMessages) event.getSource(); 57 String 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 getFamily() { return "org.exoplatform.portlets.communication.message.component.UIMessages" ; } 72 73 } | Popular Tags |