KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.faces.context.ExternalContext;
8 import javax.faces.context.FacesContext;
9 import javax.portlet.ActionResponse;
10 import org.exoplatform.container.SessionContainer;
11 import org.exoplatform.faces.core.component.UIExoCommand;
12 import org.exoplatform.faces.core.component.UIExoComponent;
13 import org.exoplatform.faces.core.component.model.Parameter;
14 import org.exoplatform.faces.core.event.CheckRoleInterceptor;
15 import org.exoplatform.faces.core.event.ExoActionEvent;
16 import org.exoplatform.faces.core.event.ExoActionListener;
17 import org.exoplatform.faces.core.event.UIComponentObserver;
18 import org.exoplatform.portal.filter.AdminRequestFilter;
19 import org.exoplatform.portal.session.RequestInfo;
20 import org.exoplatform.services.organization.Group;
21 import org.exoplatform.services.portal.community.CommunityConfigService;
22 import org.exoplatform.services.portal.community.CommunityNavigation;
23 import org.exoplatform.services.portal.community.CommunityPortal;
24 /**
25  * Sat, Jan 03, 2004 @ 11:16
26  * @author: Tuan Nguyen
27  * @email: tuan08@users.sourceforge.net
28  * @version: $Id: UIUserProfile.java,v 1.14 2004/09/28 18:19:23 tuan08 Exp $
29  */

30 public class UIGroupCommunityInfo extends UIExoCommand {
31   static public Parameter[] ADMIN_PORTAL = {new Parameter(ACTION , "adminPortal") } ;
32   static public Parameter[] ADD_EDIT_PORTAL = {new Parameter(ACTION , "addEditPortal") } ;
33   static public Parameter[] DELETE_PORTAL = {new Parameter(ACTION , "deletePortal") } ;
34   
35   static public Parameter[] ADMIN_NAV = {new Parameter(ACTION , "adminNav") } ;
36   static public Parameter[] ADD_EDIT_NAV = {new Parameter(ACTION , "addEditNav") } ;
37   static public Parameter[] DELETE_NAV = {new Parameter(ACTION , "deleteNav") } ;
38   
39   private CommunityConfigService service_ ;
40   private CommunityPortal communityPortal_ ;
41   private CommunityNavigation communityNav_ ;
42    
43   public UIGroupCommunityInfo(CommunityConfigService service) throws Exception JavaDoc {
44     setRendererType("GroupCommunityInfoRenderer") ;
45     service_ = service ;
46     addActionListener(AdminPortalActionListener.class, "adminPortal") ;
47     addActionListener(AddEditPortalActionListener.class, "addEditPortal") ;
48     addActionListener(DeletePortalActionListener.class, "deletePortal") ;
49     
50     addActionListener(AdminNavActionListener.class, "adminNav") ;
51     addActionListener(AddEditNavActionListener.class, "addEditNav") ;
52     addActionListener(DeleteNavActionListener.class, "deleteNav") ;
53   }
54   
55   public void registerComponentObserver(UIExoComponent parent) {
56     UIGroupExplorer uiExplorer =
57       (UIGroupExplorer) parent.getAncestorOfType(UIGroupExplorer.class) ;
58     uiExplorer.addObserver(new GroupChangeObserver());
59   }
60   
61   public CommunityPortal getCommunityPortal() { return communityPortal_ ; }
62   public void setCommunityPortal(CommunityPortal cp) {
63     communityPortal_ = cp ;
64   }
65   
66   public CommunityNavigation getCommunityNavigation() { return communityNav_ ; }
67   public void setCommunityNavigation(CommunityNavigation cn) {
68     communityNav_ = cn ;
69   }
70   
71   class GroupChangeObserver extends UIComponentObserver {
72     public void onChange(UIExoComponent target) throws Exception JavaDoc {
73       UIGroupExplorer uiExplorer = (UIGroupExplorer) target ;
74       Group group = uiExplorer.getCurrentGroup();
75       if(group != null) {
76         communityPortal_ = service_.getCommunityPortal(group) ;
77         communityNav_ = service_.getCommunityNavigation(group) ;
78       }
79     }
80   }
81   
82   static public class AdminPortalActionListener extends ExoActionListener {
83     public AdminPortalActionListener() {
84       addInterceptor(new CheckRoleInterceptor("admin")) ;
85     }
86     
87     public void execute(ExoActionEvent event) throws Exception JavaDoc {
88       UIGroupCommunityInfo uiInfo = (UIGroupCommunityInfo) event.getComponent() ;
89       RequestInfo rinfo = (RequestInfo) SessionContainer.getComponent(RequestInfo.class);
90       String JavaDoc path = rinfo.getContextPath() + "/faces/admin/" +
91                     uiInfo.communityPortal_.getPortal() +
92                     "?" + AdminRequestFilter.ACTION + "=" + AdminRequestFilter.ADMIN ;
93       ExternalContext eContext = FacesContext.getCurrentInstance().getExternalContext();
94       ActionResponse response = (ActionResponse) eContext.getResponse();
95       response.sendRedirect(path);
96     }
97   }
98   
99   static public class AddEditPortalActionListener extends ExoActionListener {
100     public AddEditPortalActionListener() {
101       addInterceptor(new CheckRoleInterceptor("admin")) ;
102     }
103     
104     public void execute(ExoActionEvent event) throws Exception JavaDoc {
105       UIGroupCommunityInfo uiInfo = (UIGroupCommunityInfo) event.getComponent() ;
106       UICommunityPortalForm uiForm =
107         (UICommunityPortalForm) uiInfo.getSibling(UICommunityPortalForm.class) ;
108       uiForm.setCommunityPortal(uiInfo.communityPortal_) ;
109       uiInfo.setRenderedSibling(UICommunityPortalForm.class) ;
110     }
111   }
112   
113   static public class DeletePortalActionListener extends ExoActionListener {
114     public DeletePortalActionListener() {
115       addInterceptor(new CheckRoleInterceptor("admin")) ;
116     }
117     
118     public void execute(ExoActionEvent event) throws Exception JavaDoc {
119       UIGroupCommunityInfo uiInfo = (UIGroupCommunityInfo) event.getComponent() ;
120       if(uiInfo.communityPortal_ != null) {
121         uiInfo.service_.removeCommunityPortal(uiInfo.communityPortal_);
122         uiInfo.communityPortal_ = null ;
123       }
124     }
125   }
126   
127   static public class AddEditNavActionListener extends ExoActionListener {
128     public AddEditNavActionListener() {
129       addInterceptor(new CheckRoleInterceptor("admin")) ;
130     }
131     
132     public void execute(ExoActionEvent event) throws Exception JavaDoc {
133       UIGroupCommunityInfo uiInfo = (UIGroupCommunityInfo) event.getComponent() ;
134       UICommunityNavForm uiForm =
135         (UICommunityNavForm) uiInfo.getSibling(UICommunityNavForm.class) ;
136       uiForm.setCommunityNavigation(uiInfo.communityNav_) ;
137       uiInfo.setRenderedSibling(UICommunityNavForm.class) ;
138     }
139   }
140   
141   static public class DeleteNavActionListener extends ExoActionListener {
142     public DeleteNavActionListener() {
143       addInterceptor(new CheckRoleInterceptor("admin")) ;
144     }
145     
146     public void execute(ExoActionEvent event) throws Exception JavaDoc {
147       UIGroupCommunityInfo uiInfo = (UIGroupCommunityInfo) event.getComponent() ;
148       if(uiInfo.communityNav_ != null) {
149         uiInfo.service_.removeCommunityNavigation(uiInfo.communityNav_);
150         uiInfo.communityNav_ = null ;
151       }
152     }
153   }
154   
155   static public class AdminNavActionListener extends ExoActionListener {
156     public AdminNavActionListener() {
157       addInterceptor(new CheckRoleInterceptor("admin")) ;
158     }
159     
160     public void execute(ExoActionEvent event) throws Exception JavaDoc {
161       UIGroupCommunityInfo uiInfo = (UIGroupCommunityInfo) event.getComponent() ;
162       RequestInfo rinfo = (RequestInfo) SessionContainer.getComponent(RequestInfo.class);
163       String JavaDoc path = rinfo.getContextPath() + "/faces/admin/" +
164                     uiInfo.communityNav_.getNavigation() +
165                     "?" + AdminRequestFilter.ACTION + "=" + AdminRequestFilter.ADMIN ;
166       ExternalContext eContext = FacesContext.getCurrentInstance().getExternalContext();
167       ActionResponse response = (ActionResponse) eContext.getResponse();
168       response.sendRedirect(path);
169     }
170   }
171   
172   public String JavaDoc getFamily() { return getClass().getName() ; }
173 }
Popular Tags