KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > portal > component > UIAvailablePortal


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.portal.component;
6
7 import javax.faces.context.ExternalContext;
8 import javax.faces.context.FacesContext;
9 import javax.portlet.ActionResponse;
10 import org.exoplatform.faces.core.component.UIGrid;
11 import org.exoplatform.faces.core.component.UIPageListIterator;
12 import org.exoplatform.faces.core.component.model.*;
13 import org.exoplatform.faces.core.event.CheckRoleInterceptor;
14 import org.exoplatform.faces.core.event.ExoActionEvent;
15 import org.exoplatform.faces.core.event.ExoActionListener;
16 import org.exoplatform.container.SessionContainer ;
17 import org.exoplatform.portal.filter.AdminRequestFilter;
18 import org.exoplatform.portal.session.RequestInfo;
19 import org.exoplatform.services.portal.PortalConfigDescription;
20 import org.exoplatform.services.portal.PortalConfigService;
21 import org.exoplatform.services.portal.Query;
22 /**
23  * Sat, Jan 03, 2004 @ 11:16
24  * @author: Tuan Nguyen
25  * @email: tuan08@users.sourceforge.net
26  * @version: $Id: UIListUser.java,v 1.18 2004/10/22 14:23:30 tuan08 Exp $
27  */

28 public class UIAvailablePortal extends UIGrid {
29     static Parameter[] VIEW = { new Parameter(ACTION , "view") } ;
30     static Parameter[] EDIT = { new Parameter(ACTION , "edit") } ;
31   static Parameter[] ADMIN = { new Parameter(ACTION , "admin") } ;
32     
33     private UIPageListIterator uiPageIterator_ ;
34     private boolean adminRole_ ;
35     private PortalConfigService service_ ;
36     public UIAvailablePortal(UISearchForm uiSearchForm,
37                            PortalConfigService service) throws Exception JavaDoc {
38         setId("UIAvailablePortal") ;
39     service_ = service ;
40         uiPageIterator_ = new UIPageListIterator(new PortalDataHandler()) ;
41     adminRole_ = hasRole("admin") ;
42     adminRole_ = true ;
43         add(new Rows(uiPageIterator_.getPageListDataHandler(), "even", "odd").
44                 add(new Column("#{UIAvailablePortal.header.owner}", "owner")).
45         add(new Column("#{UIAvailablePortal.header.edit-permission}", "editPermission")).
46         add(new Column("#{UIAvailablePortal.header.view-permission}", "viewPermission")).
47                 add(new ActionColumn("#{UIAvailablePortal.header.action}", "owner").
48                         //add(adminRole_,new Button("#{UIAvailablePortal.button.view}", VIEW)).
49
//add(adminRole_,new Button("#{UIAvailablePortal.button.edit}", EDIT)).
50
add(adminRole_,new Button("#{UIAvailablePortal.button.admin}", ADMIN)))) ;
51         add(new Row().
52                 add(new ComponentCell(this, uiPageIterator_).
53                         addColspan("4").addClazz("footer")));
54     add(new Row().
55         add(new ComponentCell(this, uiSearchForm).
56             addColspan("4")));
57
58         addActionListener(ViewActionListener.class, "view") ;
59     addActionListener(AdminActionListener.class, "admin") ;
60     refresh(new Query(null, null, null)) ;
61     }
62
63   public void refresh(Query q) throws Exception JavaDoc {
64     uiPageIterator_.setPageList(service_.findAllPortalConfigDescriptions(q)) ;
65   }
66     
67     static public class PortalDataHandler extends PageListDataHandler {
68         private PortalConfigDescription desc_ ;
69         
70         public String JavaDoc getData(String JavaDoc fieldName) {
71             if("owner".equals(fieldName)) return desc_.getOwner() ;
72       if("viewPermission".equals(fieldName)) return desc_.getViewPermission() ;
73       if("editPermission".equals(fieldName)) return desc_.getEditPermission() ;
74             return null ;
75         }
76         
77         public void setCurrentObject(Object JavaDoc o) { desc_ = (PortalConfigDescription) o; }
78     }
79     
80   static public class AdminActionListener extends ExoActionListener {
81     public AdminActionListener() {
82       addInterceptor(new CheckRoleInterceptor("admin")) ;
83     }
84     
85     public void execute(ExoActionEvent event) throws Exception JavaDoc {
86       String JavaDoc owner = event.getParameter(OBJECTID) ;
87       RequestInfo rinfo = (RequestInfo) SessionContainer.getComponent(RequestInfo.class);
88       String JavaDoc path = rinfo.getContextPath() + "/faces/admin/" + owner +
89                     "?" + AdminRequestFilter.ACTION + "=" + AdminRequestFilter.ADMIN ;
90       ExternalContext eContext = FacesContext.getCurrentInstance().getExternalContext();
91       ActionResponse response = (ActionResponse) eContext.getResponse();
92       response.sendRedirect(path);
93     }
94   }
95   
96     static public class ViewActionListener extends ExoActionListener {
97     public ViewActionListener() {
98       addInterceptor(new CheckRoleInterceptor("admin")) ;
99     }
100     
101         public void execute(ExoActionEvent event) throws Exception JavaDoc {
102         }
103     }
104 }
Popular Tags