1 5 package org.exoplatform.portlets.communication.message.component; 6 7 import java.util.ArrayList ; 8 import java.util.List ; 9 import org.exoplatform.container.SessionContainer; 10 import org.exoplatform.faces.core.component.UISelectBox; 11 import org.exoplatform.faces.core.component.UISimpleForm; 12 import org.exoplatform.faces.core.component.model.ComponentCell; 13 import org.exoplatform.faces.core.component.model.Row; 14 import org.exoplatform.faces.core.component.model.SelectItem; 15 import org.exoplatform.faces.core.event.ExoActionEvent; 16 import org.exoplatform.faces.core.event.ExoActionListener; 17 import org.exoplatform.services.communication.message.Account; 18 import org.exoplatform.services.communication.message.MessageService; 19 24 public class UISelectAccount extends UISimpleForm { 25 private UISelectBox accountInput_; 26 private Account selectAccount_ ; 27 private List accounts_ ; 28 29 public UISelectAccount(MessageService service) throws Exception { 30 super("selectAccountForm", "post", null) ; 31 setId("UISelectAccount") ; 32 setClazz("UISelectAccount"); 33 String userName = SessionContainer.getInstance().getOwner(); 34 accounts_ = service.getAccounts(userName) ; 35 if(accounts_.size() > 0) selectAccount_ = (Account) accounts_.get(0) ; 36 List options = new ArrayList () ; 37 options.add(new SelectItem("Select an account", "")); 38 for(int i = 0; i < accounts_.size(); i++) { 39 Account account = (Account) accounts_.get(i); 40 String name = account.getAccountName() ; 41 options.add(new SelectItem(name, name)); 42 } 43 accountInput_ = new UISelectBox("account", "", options); 44 accountInput_.setUpdateOnChangeAction("changeAccount"); 45 add(new Row(). 46 add(new ComponentCell(this, accountInput_))); 47 addActionListener(ChangeAccountActionListener.class, "changeAccount") ; 48 } 49 50 public Account getSelectAccount() { return selectAccount_ ; } 51 52 static public class ChangeAccountActionListener extends ExoActionListener { 53 public void execute(ExoActionEvent event) throws Exception { 54 UISelectAccount uiSelectAccount = (UISelectAccount) event.getSource() ; 55 String accountName = uiSelectAccount.accountInput_.getValue() ; 56 List accounts = uiSelectAccount.accounts_ ; 57 for (int i = 0; i < accounts.size(); i++) { 58 Account account = (Account) accounts.get(i) ; 59 if(account.getAccountName().equals(accountName)) { 60 uiSelectAccount.selectAccount_ = account ; 61 UIAccount uiAccount = (UIAccount) uiSelectAccount.getSibling(UIAccount.class) ; 62 uiAccount.setAccount(account) ; 63 break ; 64 } 65 } 66 uiSelectAccount.accountInput_.setValue("") ; 67 } 68 } 69 } | Popular Tags |