1 5 package org.exoplatform.portlets.communication.message.component; 6 7 import org.exoplatform.faces.core.component.UIExoCommand; 8 import org.exoplatform.faces.core.component.model.Parameter; 9 import org.exoplatform.faces.core.event.ExoActionEvent; 10 import org.exoplatform.faces.core.event.ExoActionListener; 11 import org.exoplatform.services.communication.message.*; 12 17 public class UIViewMessage extends UIExoCommand { 18 public final static String TEXT_FORMAT = "TEXT_FORMAT" ; 19 public final static String HTML_FORMAT = "HTML_FORMAT" ; 20 21 public final static String FORMAT_TYPE = "format" ; 22 public final static String REPLY_MESSAGE_ACTION = "replyMessage" ; 23 public final static String ARCHIVED_MESSAGE_ACTION = "achieveMessage" ; 24 public final static String CHANGE_FORMAT_ACTION = "changeFormat" ; 25 public static Parameter[] replyMessageParams_ = { 26 new Parameter(ACTION, REPLY_MESSAGE_ACTION) 27 }; 28 public static Parameter[] deleteMessageParams_ = { 29 new Parameter(ACTION, DELETE_ACTION) 30 }; 31 public static Parameter[] archivedMessageParams_ = { 32 new Parameter(ACTION, ARCHIVED_MESSAGE_ACTION) 33 }; 34 public static Parameter[] htmlFormatParams_ = { 35 new Parameter(ACTION, CHANGE_FORMAT_ACTION), 36 new Parameter(FORMAT_TYPE, HTML_FORMAT) 37 }; 38 public static Parameter[] textFormatParams_ = { 39 new Parameter(ACTION, CHANGE_FORMAT_ACTION), 40 new Parameter(FORMAT_TYPE, TEXT_FORMAT) 41 }; 42 public static Parameter[] cancelParams_ = { 43 new Parameter(ACTION, CANCEL_ACTION) 44 }; 45 46 private Message message_ ; 47 private MessageService service_ ; 48 private String format_ = HTML_FORMAT; 49 50 public UIViewMessage(MessageService service) { 51 setId("UIViewMessage") ; 52 setClazz("UIViewMessage"); 53 setRendererType("ViewMessageRenderer") ; 54 service_ = service ; 55 addActionListener(ChangeFormatActionListener.class, CHANGE_FORMAT_ACTION) ; 56 addActionListener(DeleteMessageActionListener.class, DELETE_ACTION) ; 57 addActionListener(ReplyMessageActionListener.class, REPLY_MESSAGE_ACTION) ; 58 addActionListener(ArchivedMessageActionListener.class, ARCHIVED_MESSAGE_ACTION) ; 59 60 addActionListener(CancelActionListener.class, CANCEL_ACTION) ; 61 } 62 63 public void setMessage(Message message) throws Exception { 64 message_ = message ; 65 } 66 67 public Message getMessage() { return message_ ; } 68 69 public String getFormat() { return format_ ; } 70 71 public String getFamily() { 72 return "org.exoplatform.portlets.communication.message.component.UIViewMessage" ; 73 } 74 75 static public class DeleteMessageActionListener extends ExoActionListener { 76 public void execute(ExoActionEvent event) throws Exception { 77 UIViewMessage uiView = (UIViewMessage) event.getSource(); 78 UIAccount uiAccount = (UIAccount) uiView.getParent() ; 79 Folder selectFolder = uiAccount.getSelectFolder() ; 80 if(!(MessageService.TRASH_FOLDER.equals(selectFolder.getName()))) { 81 Folder trash = uiAccount.getFolder(MessageService.TRASH_FOLDER) ; 82 uiView.service_.moveMessage(uiAccount.getAccount(),trash, uiView.message_) ; 83 } else { 84 uiView.service_.removeMessage(uiView.message_) ; 85 } 86 UISummary uiSummary = (UISummary) uiView.getSibling(UISummary.class) ; 87 uiSummary.update() ; 88 uiView.setRenderedSibling(UISummary.class) ; 89 } 90 } 91 92 static public class ArchivedMessageActionListener extends ExoActionListener { 93 public void execute(ExoActionEvent event) throws Exception { 94 UIViewMessage uiView = (UIViewMessage) event.getSource(); 95 UIAccount uiAccount = (UIAccount) uiView.getParent() ; 96 Folder archived = uiAccount.getFolder(MessageService.ARCHIVED_FOLDER) ; 97 uiView.service_.moveMessage(uiAccount.getAccount(), archived,uiView.message_) ; 98 UISummary uiSummary = (UISummary) uiView.getSibling(UISummary.class) ; 99 uiSummary.update() ; 100 uiView.setRenderedSibling(UISummary.class) ; 101 } 102 } 103 104 static public class ReplyMessageActionListener extends ExoActionListener { 105 public void execute(ExoActionEvent event) throws Exception { 106 UIViewMessage uiView = (UIViewMessage) event.getSource(); 107 UIMessageForm uiForm = (UIMessageForm) uiView.getSibling(UIMessageForm.class) ; 108 UIAccount uiAccount = (UIAccount) uiView.getParent() ; 109 uiForm.setFormData(uiAccount.getAccount() , uiView.message_) ; 110 uiView.setRenderedSibling(UIMessageForm.class) ; 111 } 112 } 113 114 static public class ChangeFormatActionListener extends ExoActionListener { 115 public void execute(ExoActionEvent event) throws Exception { 116 UIViewMessage uiView = (UIViewMessage) event.getSource(); 117 uiView.format_ = event.getParameter(FORMAT_TYPE) ; 118 } 119 } 120 121 static public class CancelActionListener extends ExoActionListener { 122 public void execute(ExoActionEvent event) throws Exception { 123 UIViewMessage uiView = (UIViewMessage) event.getSource(); 124 UIAccount uiAccount = (UIAccount) uiView.getParent() ; 125 uiAccount.setSelectFolder(uiAccount.getSelectFolder().getName()); 126 uiView.setRenderedSibling(UISummary.class) ; 127 } 128 } 129 } | Popular Tags |