KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > user > component > UIUserInfo


1 /***************************************************************************
2  * Copyright 2001-2003 The eXo Platform SARL All rights reserved. *
3  * Please look at license.txt in info directory for more license detail. *
4  **************************************************************************/

5 package org.exoplatform.portlets.user.component;
6
7 import java.util.Collection JavaDoc;
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 /**
16  * Sat, Jan 03, 2004 @ 11:16
17  * @author: Tuan Nguyen
18  * @email: tuan08@users.sourceforge.net
19  * @version: $Id: UIUserInfo.java,v 1.10 2004/07/02 20:48:33 tuan08 Exp $
20  */

21 public class UIUserInfo extends UIExoCommand {
22   
23   private User user_ ;
24   private Collection JavaDoc 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 JavaDoc {
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 JavaDoc 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 JavaDoc userName) throws Exception JavaDoc {
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 JavaDoc {
65     if (user_ != null) {
66       String JavaDoc 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 JavaDoc {
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 JavaDoc {
83       UIUserInfo uiInfo = (UIUserInfo) event.getComponent() ;
84       String JavaDoc 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 JavaDoc {
92       UIUserInfo uiInfo = (UIUserInfo) event.getComponent() ;
93       uiInfo.setRenderedSibling(UIListUser.class) ;
94     }
95   }
96 }
Popular Tags