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.model.Parameter; 10 import org.exoplatform.faces.core.event.ExoActionEvent; 11 import org.exoplatform.faces.core.event.ExoActionListener; 12 import org.exoplatform.services.communication.message.*; 13 18 public class UIAccount extends UIExoCommand { 19 public final static String COMPOSE_ACTION = "compose" ; 20 public final static String SYNCHRONIZE_ACTION = "synchronize" ; 21 public final static String CHANGE_FOLDER_ACTION = "changeFolder" ; 22 23 public final static String FOLDER_NAME = "folderName" ; 24 public static Parameter[] composeParams_ = {new Parameter(ACTION, COMPOSE_ACTION)} ; 25 public static Parameter[] synchronizeParams_ = {new Parameter(ACTION, SYNCHRONIZE_ACTION)} ; 26 public static Parameter changeFolderParam_ = new Parameter(ACTION, CHANGE_FOLDER_ACTION) ; 27 28 private MessageService service_ ; 29 private Account account_ ; 30 private List folders_ ; 31 private Folder selectFolder_ ; 32 33 public UIAccount(MessageService service , 34 UIViewMessage uiViewMessage, 35 UIMessageForm uiMessageForm, 36 UISummary uiSummary) { 37 setId("UIAccount") ; 38 setClazz("UIAccount"); 39 setRendererType("AccountRenderer"); 40 service_ = service ; 41 List children = getChildren() ; 42 43 uiMessageForm.setRendered(false) ; 44 children.add(uiMessageForm) ; 45 uiViewMessage.setRendered(false) ; 46 children.add(uiViewMessage) ; 47 uiSummary.setRendered(true) ; 48 children.add(uiSummary) ; 49 50 addActionListener(SynchronizeActionListener.class, SYNCHRONIZE_ACTION) ; 51 addActionListener(ComposeActionListener.class, COMPOSE_ACTION) ; 52 addActionListener(ChangeFolderActionListener.class, CHANGE_FOLDER_ACTION) ; 53 } 54 55 public Account getAccount() { return account_ ; } 56 57 public List getFolders() { return folders_ ; } 58 59 public Folder getSelectFolder() { return selectFolder_ ; } 60 61 public void setAccount(Account account) throws Exception { 62 account_ = account ; 63 if(account != null) { 64 folders_ = service_.getFolders(account.getId()) ; 65 setSelectFolder(MessageService.INBOX_FOLDER) ; 66 UISummary uiSummary = 67 (UISummary)getChildComponentOfType(UISummary.class) ; 68 uiSummary.changeAccount(this) ; 69 uiSummary.changeFolder(selectFolder_) ; 70 setRenderedComponent(UISummary.class) ; 71 } 72 } 73 74 public void setSelectFolder(String name) throws Exception { 75 selectFolder_ = getFolder(name) ; 76 } 77 78 public Folder getFolder(String name) { 79 for(int i = 0 ; i < folders_.size() ; i++) { 80 Folder folder = (Folder) folders_.get(i) ; 81 if(name.equals(folder.getName())) { 82 return folder ; 83 } 84 } 85 return null ; 86 } 87 88 static public class ComposeActionListener extends ExoActionListener { 89 public void execute(ExoActionEvent event) throws Exception { 90 UIAccount uiAccount = (UIAccount) event.getSource() ; 91 UIMessageForm uiMessageForm = 92 (UIMessageForm)uiAccount.getChildComponentOfType(UIMessageForm.class) ; 93 uiMessageForm.setFormData(uiAccount.account_, null) ; 94 uiAccount.setRenderedComponent(UIMessageForm.class) ; 95 } 96 } 97 98 static public class SynchronizeActionListener extends ExoActionListener { 99 public void execute(ExoActionEvent event) throws Exception { 100 UIAccount uiAccount = (UIAccount) event.getSource() ; 101 uiAccount.service_.synchronizeAccount(uiAccount.account_) ; 102 UISummary uiSummary = 103 (UISummary)uiAccount.getChildComponentOfType(UISummary.class) ; 104 uiAccount.setSelectFolder(MessageService.INBOX_FOLDER) ; 105 uiSummary.changeFolder(uiAccount.selectFolder_) ; 106 uiAccount.setRenderedComponent(UISummary.class) ; 107 } 108 } 109 110 static public class ChangeFolderActionListener extends ExoActionListener { 111 public void execute(ExoActionEvent event) throws Exception { 112 UIAccount uiAccount = (UIAccount) event.getSource() ; 113 String folderName = event.getParameter(FOLDER_NAME) ; 114 uiAccount.setSelectFolder(folderName) ; 115 UISummary uiSummary = 116 (UISummary)uiAccount.getChildComponentOfType(UISummary.class) ; 117 uiSummary.changeFolder(uiAccount.selectFolder_) ; 118 uiAccount.setRenderedComponent(UISummary.class) ; 119 } 120 } 121 122 public String getFamily() { 123 return "org.exoplatform.portlets.communication.message.component.UIAccount" ; 124 } 125 } | Popular Tags |