KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portal > faces > component > UIPageList


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.portal.faces.component;
6
7 import org.exoplatform.commons.exception.ExoPermissionException;
8 import org.exoplatform.container.SessionContainer;
9 import org.exoplatform.faces.application.ExoFacesMessage;
10 import org.exoplatform.faces.core.component.InformationProvider;
11 import org.exoplatform.faces.core.component.UIGrid;
12 import org.exoplatform.faces.core.component.UIPageListIterator;
13 import org.exoplatform.faces.core.component.UIToolbar;
14 import org.exoplatform.faces.core.component.model.*;
15 import org.exoplatform.faces.core.event.ExoActionEvent;
16 import org.exoplatform.faces.core.event.ExoActionListener;
17 import org.exoplatform.services.portal.PageDescription;
18 import org.exoplatform.services.portal.PortalACL;
19 import org.exoplatform.services.portal.PortalConfigService;
20 import org.exoplatform.services.portal.Query;
21 import org.exoplatform.services.portal.model.Page;
22 /**
23  * @email: tuan08@users.sourceforge.net
24  * @version: $Id: UIPageList.java,v 1.13 2004/10/19 13:20:02 benjmestrallet Exp $
25  */

26 public class UIPageList extends UIGrid {
27   public static Parameter[] PREVIEW_PAGE = { new Parameter(ACTION , "preview") } ;
28   public static Parameter[] SELECT_PAGE = { new Parameter(ACTION , "select") } ;
29   public static Parameter[] DELETE_PAGE = { new Parameter(ACTION , DELETE_ACTION) } ;
30   public static Parameter NEW_PAGE = new Parameter(ACTION , "newPage") ;
31   public static Parameter RETURN_PAGE = new Parameter(ACTION , "return") ;
32   
33   public static Parameter[] newParams = { NEW_PAGE} ;
34   public static Parameter[] returnParams = { RETURN_PAGE } ;
35   
36   private UIPageListIterator uiPageIterator_ ;
37   private UISearchForm uiSearchForm_ ;
38   private Query query_ ;
39   
40   public UIPageList() throws Exception JavaDoc {
41     setId("UIPageList") ;
42     UIToolbar uiToolbar = new UIToolbar();
43     uiToolbar.addLeftButton(new Button("#{UIPageList.button.new-page}", newParams));
44     uiToolbar.addRightButton(new Button("#{UIPageList.button.cancel}", returnParams));
45     uiPageIterator_ = new UIPageListIterator(new PageDescriptionHandler()) ;
46     uiSearchForm_ = new UISearchForm() ;
47     add(new Row().
48         add(new ComponentCell(this, uiToolbar).
49             addColspan("5")));
50     add(new Rows(uiPageIterator_.getPageListDataHandler(), "even", "odd").
51         add(new Column("#{UIPageList.header.owner}", "owner")).
52         add(new Column("#{UIPageList.header.name}", "name")).
53         add(new Column("#{UIPageList.header.view-permission}", "viewPermission")).
54         add(new Column("#{UIPageList.header.edit-permission}", "editPermission")).
55         add(new ActionColumn("#{UIPageList.header.action}", OBJECTID).
56             add(true, new Button("#{UIPageList.button.preview}", PREVIEW_PAGE )).
57             add(true, new Button("#{UIPageList.button.select}", SELECT_PAGE )).
58             add(true,new Button("#{UIPageList.button.delete}",DELETE_PAGE)).
59             setCellClass("action-column"))) ;
60     add(new Row().
61         add(new ComponentCell(this, uiPageIterator_).
62             addColspan("5").addStyle("text-align: right")));
63     add(new Row().
64         add(new ComponentCell(this, uiSearchForm_).
65             addColspan("5")));
66
67
68     addActionListener(DeleteActionListener.class, DELETE_ACTION) ;
69     addActionListener(SelectActionListener.class, "select") ;
70     addActionListener(PreviewActionListener.class, "preview") ;
71     addActionListener(NewPageActionListener.class, "newPage") ;
72     addActionListener(ReturnActionListener.class, "return") ;
73   }
74   
75   
76   public void queryDescriptions(String JavaDoc owner, String JavaDoc viewPerm, String JavaDoc editPerm) throws Exception JavaDoc {
77     uiSearchForm_.setOwner(owner) ;
78     uiSearchForm_.setViewPermission(viewPerm) ;
79     uiSearchForm_.setEditPermission(editPerm) ;
80     PortalConfigService service = ((UIPageBrowser) getParent()).getPortalConfigService() ;
81     query_= new Query(owner, viewPerm, editPerm) ;
82     uiPageIterator_.setPageList(service.findAllPageDescriptions(query_)) ;
83   }
84   
85   public void update() throws Exception JavaDoc {
86     PortalConfigService service = ((UIPageBrowser) getParent()).getPortalConfigService() ;
87     uiPageIterator_.setPageList(service.findAllPageDescriptions(query_)) ;
88   }
89   
90   static public class PageDescriptionHandler extends PageListDataHandler {
91     private PageDescription desc_ ;
92     
93     public String JavaDoc getData(String JavaDoc fieldName) {
94       if(OBJECTID.equals(fieldName)) return desc_.getId() ;
95       if("owner".equals(fieldName)) return desc_.getOwner() ;
96       if("name".equals(fieldName)) return desc_.getName() ;
97       if("viewPermission".equals(fieldName)) return desc_.getViewPermission() ;
98       if("editPermission".equals(fieldName)) return desc_.getEditPermission() ;
99       return null ;
100     }
101     
102     public void setCurrentObject(Object JavaDoc o) { desc_ = (PageDescription) o; }
103   }
104   
105   static public class PreviewActionListener extends ExoActionListener {
106     public void execute(ExoActionEvent event) throws Exception JavaDoc {
107       UIPageList uiList = (UIPageList) event.getComponent() ;
108       UIPortal uiPortal = (UIPortal) uiList.getAncestorOfType(UIPortal.class) ;
109       UIPagePreview uiPagePreview =
110         (UIPagePreview)uiPortal.getPortalComponent(UIPagePreview.class) ;
111       String JavaDoc pageId = event.getParameter(OBJECTID) ;
112       if(uiPagePreview.setPage(uiPortal, pageId)) {
113         uiPortal.setBodyComponent(uiPagePreview) ;
114       }
115     }
116   }
117   
118   static public class SelectActionListener extends ExoActionListener {
119         public void execute(ExoActionEvent event) throws Exception JavaDoc {
120       UIPageList uiList = (UIPageList) event.getComponent() ;
121             String JavaDoc pageId = event.getParameter(OBJECTID);
122             UIPageBrowser uiPageBrowser = (UIPageBrowser) uiList.getParent() ;
123             uiPageBrowser.setSelectNodeReferencePage(pageId);
124         }
125     }
126   
127   static public class DeleteActionListener extends ExoActionListener {
128     public DeleteActionListener() {
129       
130     }
131     
132         public void execute(ExoActionEvent event) throws Exception JavaDoc {
133       UIPageList uiList = (UIPageList) event.getComponent() ;
134             UIPageBrowser uiPageBrowser = (UIPageBrowser) uiList.getParent();
135       UIPortal uiPortal = (UIPortal) uiPageBrowser.getAncestorOfType(UIPortal.class) ;
136             PortalConfigService service = uiPageBrowser.getPortalConfigService();
137             String JavaDoc pageId = event.getParameter(OBJECTID);
138       Page page = service.getPage(pageId) ;
139       PortalACL acl = service.getPortalACL() ;
140       if(!acl.hasEditPagePermission(page, uiPortal.getOwner())) {
141         throw new ExoPermissionException(getActionName(), "onwer") ;
142       }
143             service.removePage(pageId);
144        PortalComponentCache cache =
145           (PortalComponentCache) SessionContainer.getComponent(PortalComponentCache.class) ;
146             cache.removeUIPageFromCache(pageId) ;
147             uiList.queryDescriptions(uiList.uiSearchForm_.getOwner(),
148                                uiList.uiSearchForm_.getViewPermission(),
149                                          uiList.uiSearchForm_.getEditPermission());
150             InformationProvider ip = findInformationProvider(event.getComponent());
151             ip.addMessage(new ExoFacesMessage("#{UIPageList.msg.delete-page-success}"));
152         }
153     }
154  
155   static public class ReturnActionListener extends ExoActionListener {
156     public void execute(ExoActionEvent event) throws Exception JavaDoc {
157       UIPageList uiList = (UIPageList) event.getSource() ;
158       UIPageBrowser uiPageBrowser = (UIPageBrowser)uiList.getParent() ;
159       uiPageBrowser.goBack() ;
160     }
161   }
162
163   static public class NewPageActionListener extends ExoActionListener {
164     public void execute(ExoActionEvent event) throws Exception JavaDoc {
165       UIPageList uiList = (UIPageList) event.getSource() ;
166       UIPageBrowser uiPageBrowser = (UIPageBrowser)uiList.getParent() ;
167       uiPageBrowser.setRenderedComponent(UIPageModelForm.class) ;
168     }
169   }
170   
171 }
Popular Tags