KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.exoplatform.commons.utils.PageList;
9 import org.exoplatform.faces.core.component.UINode;
10 import org.exoplatform.faces.core.component.UICommandNode;
11 import org.exoplatform.faces.core.event.CheckRoleInterceptor;
12 import org.exoplatform.faces.core.event.ExoActionEvent;
13 import org.exoplatform.faces.core.event.ExoActionListener;
14 import org.exoplatform.services.organization.Group;
15 import org.exoplatform.services.organization.OrganizationService;
16 /**
17  * Sat, Jan 03, 2004 @ 11:16
18  * @author: Tuan Nguyen
19  * @email: tuan08@users.sourceforge.net
20  * @version: $Id: UIGroupExplorer.java,v 1.15 2004/10/22 14:23:30 tuan08 Exp $
21  */

22 public class UIGroupExplorer extends UICommandNode {
23   final static public String JavaDoc GROUP_ID = "groupId" ;
24   
25   private OrganizationService service_ ;
26   private Group currentGroup_ ;
27   private Group parentGroup_ ;
28   private Collection JavaDoc childrenGroup_ ;
29   private boolean adminRole_ ;
30    
31   public UIGroupExplorer(OrganizationService service) throws Exception JavaDoc {
32     setId("UIGroupExplorer") ;
33     setRendererType("GroupExplorerRenderer") ;
34     service_ = service ;
35     customizeGroupDetail() ;
36     childrenGroup_ = service_.findGroups(null) ;
37     addActionListener(ChangeGroupActionListener.class, "changeGroup") ;
38     addActionListener(AddGroupActionListener.class, "addGroup") ;
39     addActionListener(DeleteGroupActionListener.class, "deleteGroup") ;
40     adminRole_ = hasRole("admin") ;
41   }
42   
43   protected void customizeGroupDetail() throws Exception JavaDoc {
44     UINode uiGroupDetail = (UINode)addChild(UINode.class) ;
45     uiGroupDetail.setId("UIGroupDetail") ;
46     uiGroupDetail.setRendererType("SimpleTabRenderer") ;
47     uiGroupDetail.addChild(UIViewUserInGroup.class) ;
48     
49     UINode uiCommunityNode = (UINode)uiGroupDetail.addChild(UINode.class) ;
50     uiCommunityNode.setId("UICommunityNode") ;
51     uiCommunityNode.setRendererType("ChildrenRenderer") ;
52     uiCommunityNode.setRendered(false);
53     uiCommunityNode.addChild(UIGroupCommunityInfo.class) ;
54     uiCommunityNode.addChild(UICommunityPortalForm.class).setRendered(false) ;
55     uiCommunityNode.addChild(UICommunityNavForm.class).setRendered(false) ;
56   }
57   
58   public boolean hasAdminRole() { return adminRole_ ; }
59   public Group getCurrentGroup() { return currentGroup_ ; }
60   public Group getParentGroup() { return parentGroup_ ; }
61   public Collection JavaDoc getChildrenGroup() { return childrenGroup_ ; }
62   
63   public PageList getMemberOfTheCurrentGroup() throws Exception JavaDoc {
64     if(currentGroup_ == null) return PageList.EMPTY_LIST ;
65     return service_.findUsersByGroup(currentGroup_.getId());
66   }
67   
68   public void update() throws Exception JavaDoc {
69     if(currentGroup_ != null ) {
70       currentGroup_ = service_.findGroupById(currentGroup_.getId()) ;
71       parentGroup_ = service_.findGroupById(currentGroup_.getParentId()) ;
72       childrenGroup_ = service_.findGroups(parentGroup_) ;
73     } else {
74       currentGroup_ = null ;
75       childrenGroup_ = service_.findGroups(null) ;
76       parentGroup_ = null ;
77     }
78   }
79   
80   private void changeGroup(String JavaDoc groupId) throws Exception JavaDoc {
81     if(groupId != null && groupId.length() > 0) {
82         currentGroup_ = service_.findGroupById(groupId) ;
83       if(currentGroup_.getParentId() != null) {
84         parentGroup_ = service_.findGroupById(currentGroup_.getParentId()) ;
85       } else {
86         parentGroup_ = null ;
87       }
88         childrenGroup_ = service_.findGroups(currentGroup_) ;
89     } else {
90         currentGroup_ = null ;
91         childrenGroup_ = service_.findGroups(null) ;
92         parentGroup_ = null ;
93     }
94     broadcastOnChange();
95   }
96   
97   static public class ChangeGroupActionListener extends ExoActionListener {
98     public void execute(ExoActionEvent event) throws Exception JavaDoc {
99       UIGroupExplorer uiExplorer = (UIGroupExplorer) event.getComponent() ;
100         String JavaDoc groupName = event.getParameter(GROUP_ID) ;
101         uiExplorer.changeGroup(groupName) ;
102     }
103   }
104   
105   static public class AddGroupActionListener extends ExoActionListener {
106     public AddGroupActionListener() {
107       addInterceptor(new CheckRoleInterceptor("admin")) ;
108     }
109     
110     public void execute(ExoActionEvent event) throws Exception JavaDoc {
111       UIGroupExplorer uiExplorer = (UIGroupExplorer) event.getComponent() ;
112         String JavaDoc parentGroupId = event.getParameter(GROUP_ID) ;
113         UIGroupForm uiForm =
114             (UIGroupForm)uiExplorer.getSibling(UIGroupForm.class) ;
115         uiForm.setParentGroup(parentGroupId) ;
116         uiExplorer.setRenderedSibling(UIGroupForm.class);
117     }
118   }
119   
120   static public class DeleteGroupActionListener extends ExoActionListener {
121     public DeleteGroupActionListener() {
122       addInterceptor(new CheckRoleInterceptor("admin")) ;
123     }
124     
125     public void execute(ExoActionEvent event) throws Exception JavaDoc {
126       UIGroupExplorer uiExplorer = (UIGroupExplorer) event.getComponent() ;
127         if(uiExplorer.currentGroup_ != null) {
128           uiExplorer.service_.removeGroup(uiExplorer.currentGroup_) ;
129           uiExplorer.currentGroup_ = uiExplorer.parentGroup_ ;
130           uiExplorer.update() ;
131         }
132     }
133   }
134 }
Popular Tags