1 5 package org.exoplatform.portlets.communication.message.component; 6 7 import java.util.List ; 8 import org.exoplatform.container.SessionContainer; 9 import org.exoplatform.faces.core.component.UIExoCommand; 10 import org.exoplatform.faces.core.component.model.Parameter; 11 import org.exoplatform.faces.core.event.ExoActionEvent; 12 import org.exoplatform.faces.core.event.ExoActionListener; 13 import org.exoplatform.services.communication.message.Account; 14 import org.exoplatform.services.communication.message.Folder; 15 import org.exoplatform.services.communication.message.MessageService; 16 21 public class UIAccountConfiguration extends UIExoCommand { 22 public final static String ADD_ACCOUNT_ACTION = "addAccount" ; 23 public final static String EDIT_ACCOUNT_ACTION = "editAccount" ; 24 public final static String DELETE_ACCOUNT_ACTION = "deleteAccount" ; 25 public final static String SELECT_ACCOUNT_ACTION = "selectAccount" ; 26 public final static String SELECT_FOLDER_ACTION = "selectFolder" ; 27 public final static String ADD_FOLDER_ACTION = "addFolder" ; 28 29 public final static String ACCOUNT_NAME = "accountName" ; 30 public final static String FOLDER_NAME = "folderName" ; 31 32 public static Parameter[] addAccountParams_ = {new Parameter(ACTION, ADD_ACCOUNT_ACTION)} ; 33 public static Parameter[] editAccountParams_ = {new Parameter(ACTION, EDIT_ACCOUNT_ACTION)} ; 34 public static Parameter[] deleteAccountParams_ = {new Parameter(ACTION, DELETE_ACCOUNT_ACTION)} ; 35 public static Parameter selectAccountParam = new Parameter(ACTION, SELECT_ACCOUNT_ACTION) ; 36 public static Parameter selectFolderParam = new Parameter(ACTION, SELECT_FOLDER_ACTION) ; 37 public static Parameter[] addFolderParams_ = {new Parameter(ACTION, ADD_FOLDER_ACTION)} ; 38 39 private MessageService service_ ; 40 private String accountOwner_ ; 41 private List accounts_ ; 42 private Account selectAccount_ ; 43 private List selectAccountFolders_ ; 44 45 public UIAccountConfiguration(MessageService service) throws Exception { 46 setId("UIAccountConfiguration") ; 47 setClazz("UIAccountConfiguration"); 48 setRendererType("AccountConfigurationRenderer"); 49 service_ = service ; 50 accountOwner_ = SessionContainer.getInstance().getOwner() ; 51 updateAccountList() ; 52 addActionListener(AddAccountActionListener.class, ADD_ACCOUNT_ACTION) ; 53 addActionListener(EditAccountActionListener.class, EDIT_ACCOUNT_ACTION) ; 54 addActionListener(DeleteAccountActionListener.class, DELETE_ACCOUNT_ACTION) ; 55 addActionListener(SelectAccountActionListener.class, SELECT_ACCOUNT_ACTION) ; 56 addActionListener(SelectFolderActionListener.class, SELECT_FOLDER_ACTION) ; 57 addActionListener(AddFolderActionListener.class, ADD_FOLDER_ACTION) ; 58 } 59 60 public String getAccountOwner() { return accountOwner_ ; } 61 62 public List getAccounts() { return accounts_ ; } 63 64 public Account getSelectAccount() { return selectAccount_ ; } 65 66 public List getSelectAccountFolders() { return selectAccountFolders_ ; } 67 68 public void updateAccountList() throws Exception { 69 accounts_ = service_.getAccounts(accountOwner_) ; 70 if(accounts_.size() > 0) { 71 selectAccount_ = (Account) accounts_.get(0) ; 72 selectAccountFolders_ = service_.getFolders(selectAccount_.getId()) ; 73 } else { 74 selectAccount_ = null; 75 selectAccountFolders_ = null ; 76 } 77 } 78 79 public void updateSelectAccount(String accountName) throws Exception { 80 for(int i = 0 ; i < accounts_.size() ;i++) { 81 Account account = (Account) accounts_.get(i) ; 82 if(accountName.equals(account.getAccountName())) { 83 selectAccount_ = account ; 84 selectAccountFolders_ = service_.getFolders(selectAccount_.getId()) ; 85 return ; 86 } 87 } 88 } 89 90 public String getFamily() { 91 return "org.exoplatform.portlets.communication.message.component.UIAccountConfiguration" ; 92 } 93 94 static public class AddAccountActionListener extends ExoActionListener { 95 public void execute(ExoActionEvent event) throws Exception { 96 UIAccountConfiguration uiAccConfig = (UIAccountConfiguration) event.getSource(); 97 UIAccountForm uiForm = (UIAccountForm) uiAccConfig.getSibling(UIAccountForm.class) ; 98 uiForm.setAccount(null) ; 99 uiAccConfig.setRenderedSibling(UIAccountForm.class) ; 100 } 101 } 102 103 static public class EditAccountActionListener extends ExoActionListener { 104 public void execute(ExoActionEvent event) throws Exception { 105 UIAccountConfiguration uiAccConfig = (UIAccountConfiguration) event.getSource(); 106 UIAccountForm uiForm = (UIAccountForm) uiAccConfig.getSibling(UIAccountForm.class) ; 107 uiForm.setAccount(uiAccConfig.selectAccount_) ; 108 uiAccConfig.setRenderedSibling(UIAccountForm.class) ; 109 } 110 } 111 112 113 static public class DeleteAccountActionListener extends ExoActionListener { 114 public void execute(ExoActionEvent event) throws Exception { 115 UIAccountConfiguration uiAccConfig = (UIAccountConfiguration) event.getSource() ; 116 uiAccConfig.service_.removeAccount(uiAccConfig.selectAccount_) ; 117 uiAccConfig.updateAccountList(); 118 } 119 } 120 121 122 static public class SelectAccountActionListener extends ExoActionListener { 123 public void execute(ExoActionEvent event) throws Exception { 124 UIAccountConfiguration uiAccConfig = (UIAccountConfiguration) event.getSource() ; 125 String accountName = event.getParameter(ACCOUNT_NAME) ; 126 uiAccConfig.updateSelectAccount(accountName) ; 127 } 128 } 129 130 static public class AddFolderActionListener extends ExoActionListener { 131 public void execute(ExoActionEvent event) throws Exception { 132 UIAccountConfiguration uiAccConfig = (UIAccountConfiguration) event.getSource() ; 133 UIFolderForm uiFolderForm = 134 (UIFolderForm) uiAccConfig.getSibling(UIFolderForm.class) ; 135 uiFolderForm.setFormData(uiAccConfig.selectAccount_, null) ; 136 uiAccConfig.setRenderedSibling(UIFolderForm.class) ; 137 } 138 } 139 140 static public class SelectFolderActionListener extends ExoActionListener { 141 public void execute(ExoActionEvent event) throws Exception { 142 UIAccountConfiguration uiAccConfig = (UIAccountConfiguration) event.getSource() ; 143 String folderName = event.getParameter(FOLDER_NAME) ; 144 UIFolderForm uiFolderForm = 145 (UIFolderForm) uiAccConfig.getSibling(UIFolderForm.class) ; 146 List folders = uiAccConfig.selectAccountFolders_ ; 147 for (int i = 0; i < folders.size(); i++) { 148 Folder folder = (Folder) folders.get(i) ; 149 if(folderName.equals(folder.getName())) { 150 uiFolderForm.setFormData(uiAccConfig.selectAccount_, folder) ; 151 uiAccConfig.setRenderedSibling(UIFolderForm.class) ; 152 return ; 153 } 154 } 155 } 156 } 157 } | Popular Tags |