1 5 package org.exoplatform.portlets.user.component; 6 7 import java.util.Collection ; 8 9 import org.exoplatform.faces.core.component.UIExoCommand; 10 import org.exoplatform.faces.core.event.ExoActionEvent; 11 import org.exoplatform.faces.core.event.ExoActionListener; 12 import org.exoplatform.services.organization.OrganizationService; 13 import org.exoplatform.services.organization.User; 14 15 21 public class UIUserInfo extends UIExoCommand { 22 23 private User user_ ; 24 private Collection memberships_ ; 25 private OrganizationService service_ ; 26 private boolean adminRole_ ; 27 private UIAccountForm uiAccountForm_ ; 28 private UIMembershipForm uiMembershipForm_ ; 29 30 public UIUserInfo(OrganizationService service) throws Exception { 31 setId("UIUserInfo") ; 32 setRendererType("UserInfoRenderer") ; 33 service_ = service ; 34 35 uiAccountForm_ = (UIAccountForm)addChild(UIAccountForm.class) ; 36 uiAccountForm_.setClazz("UICompactForm") ; 37 uiAccountForm_.customizeUpdateAccountForm() ; 38 39 uiMembershipForm_ = (UIMembershipForm) addChild(UIMembershipForm.class) ; 40 uiMembershipForm_.setClazz("UICompactForm") ; 41 uiMembershipForm_.setId("UIMembershipFormForUser") ; 42 43 addActionListener(BackActionListener.class, "back") ; 44 addActionListener(AddMembershipActionListener.class, "addMembership"); 45 addActionListener(DeleteMembershipActionListener.class, "deleteMembership"); 46 adminRole_ = hasRole("admin") ; 47 } 48 49 public User getUser() { return user_ ; } 50 public Collection getMemberships() { return memberships_ ; } 51 public boolean hasAdminRole() { return adminRole_ ; } 52 public UIAccountForm getUIAccountForm() { return uiAccountForm_ ; } 53 public UIMembershipForm getUIMembershipForm() { return uiMembershipForm_ ; } 54 55 public void changeUser(String userName) throws Exception { 56 user_ = service_.findUserByName(userName) ; 57 memberships_ = service_.findMembershipsByUser(userName) ; 58 UIAccountForm ui = 59 (UIAccountForm) getChildComponentOfType(UIAccountForm.class); 60 ui.setEditingUser(user_) ; 61 uiMembershipForm_.populateFormByUser(userName) ; 62 } 63 64 public void update() throws Exception { 65 if (user_ != null) { 66 String userName = user_.getUserName() ; 67 user_ = service_.findUserByName(userName) ; 68 memberships_ = service_.findMembershipsByUser(userName) ; 69 } 70 } 71 static public class AddMembershipActionListener extends ExoActionListener { 72 public void execute(ExoActionEvent event) throws Exception { 73 UIUserInfo uiInfo = (UIUserInfo) event.getComponent() ; 74 UIMembershipForm uiForm = 75 (UIMembershipForm)uiInfo.getSibling(UIMembershipForm.class) ; 76 uiForm.populateFormByUser(uiInfo.user_.getUserName()) ; 77 uiInfo.setRenderedSibling(UIMembershipForm.class) ; 78 } 79 } 80 81 static public class DeleteMembershipActionListener extends ExoActionListener { 82 public void execute(ExoActionEvent event) throws Exception { 83 UIUserInfo uiInfo = (UIUserInfo) event.getComponent() ; 84 String membershipId = event.getParameter("membershipId") ; 85 uiInfo.service_.removeMembership(membershipId) ; 86 uiInfo.update() ; 87 } 88 } 89 90 static public class BackActionListener extends ExoActionListener { 91 public void execute(ExoActionEvent event) throws Exception { 92 UIUserInfo uiInfo = (UIUserInfo) event.getComponent() ; 93 uiInfo.setRenderedSibling(UIListUser.class) ; 94 } 95 } 96 } | Popular Tags |