KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > resources > component > UIListResources


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.resources.component;
6
7 import org.exoplatform.faces.core.component.UIGrid;
8 import org.exoplatform.faces.core.component.UIPageListIterator;
9 import org.exoplatform.faces.core.component.model.*;
10 import org.exoplatform.faces.core.event.CheckRoleInterceptor;
11 import org.exoplatform.faces.core.event.ExoActionEvent;
12 import org.exoplatform.faces.core.event.ExoActionListener;
13 import org.exoplatform.services.resources.Query;
14 import org.exoplatform.services.resources.ResourceBundleData;
15 import org.exoplatform.services.resources.ResourceBundleDescription;
16 import org.exoplatform.services.resources.ResourceBundleService;
17 /**
18  * Sat, Jan 03, 2004 @ 11:16
19  * @author: Tuan Nguyen
20  * @email: tuan08@users.sourceforge.net
21  * @version: $Id: UIListResources.java,v 1.6 2004/10/16 21:31:13 tuan08 Exp $
22  */

23 public class UIListResources extends UIGrid {
24    private static Parameter[] VIEW_RESOURCE = { new Parameter(ACTION , VIEW_ACTION) };
25    private static Parameter[] DELETE_RESOURCE = { new Parameter(ACTION , DELETE_ACTION)} ;
26     
27   private UIPageListIterator uiPageIterator_ ;
28   private ResourceBundleService service_ ;
29   private boolean adminRole_ ;
30   private Query query_ ;
31
32   public UIListResources(ResourceBundleService service) throws Exception JavaDoc {
33     setId("UIListResources");
34     service_ = service ;
35     adminRole_ = hasRole("admin") ;
36     uiPageIterator_ = new UIPageListIterator(new ResourceDescriptionDataHandler()) ;
37     add(new Rows(uiPageIterator_.getPageListDataHandler(), "even", "odd").
38         add(new Column("#{UIListResources.header.name}", "name")).
39         add(new Column("#{UIListResources.header.language}", "language")).
40         add(new ActionColumn("#{UIListResources.header.action}", OBJECTID).
41             add(new Button("#{UIListResources.button.view}", VIEW_RESOURCE)).
42             add(adminRole_, new Button("#{UIListResources.button.delete}", DELETE_RESOURCE)).
43              setCellClass("action-column"))) ;
44     add(new Row().
45         add(new ComponentCell(this, uiPageIterator_).
46             addColspan("5").addStyle("text-align: right")));
47     add(new Row().
48         add(new ComponentCell(this, new UISearchForm(adminRole_)).
49             addColspan("5")));
50     addActionListener(ViewActionListener.class, VIEW_ACTION) ;
51     addActionListener(DeleteActionListener.class, DELETE_ACTION) ;
52     query_ = new Query(null, null) ;
53     update() ;
54   }
55  
56   public void update(String JavaDoc name , String JavaDoc lang) throws Exception JavaDoc {
57     query_.setName(name) ;
58     query_.setLanguage(lang) ;
59     uiPageIterator_.setPageList(service_.findResourceDescriptions(query_)) ;
60   }
61   
62   public void update() throws Exception JavaDoc {
63     uiPageIterator_.setPageList(service_.findResourceDescriptions(query_)) ;
64   }
65  
66   static public class ResourceDescriptionDataHandler extends PageListDataHandler {
67     private ResourceBundleDescription desc_ ;
68     
69     public String JavaDoc getData(String JavaDoc fieldName) {
70       if(OBJECTID.equals(fieldName)) return desc_.getId() ;
71       if("name".equals(fieldName)) return desc_.getName() ;
72       if("language".equals(fieldName)) return desc_.getLanguage() ;
73       return "" ;
74     }
75     
76     public void setCurrentObject(Object JavaDoc o) { desc_ = (ResourceBundleDescription) o; }
77   }
78  
79   static public class ViewActionListener extends ExoActionListener {
80     public void execute(ExoActionEvent event) throws Exception JavaDoc {
81         UIListResources uiListResources = (UIListResources) event.getComponent() ;
82         UIResourcesPortlet uiPortlet = (UIResourcesPortlet)uiListResources.getParent() ;
83       UIResource uiResource =
84         (UIResource)uiPortlet.getChildComponentOfType(UIResource.class);
85       String JavaDoc resourceId = event.getParameter(OBJECTID) ;
86       ResourceBundleData data = uiListResources.service_.getResourceBundleData(resourceId) ;
87       uiResource.setResourceBundleData(data) ;
88       uiResource.setMode(UIResource.VIEW_MODE) ;
89       uiPortlet.setRenderedComponent(uiResource.getId()) ;
90     }
91   }
92   
93   static public class DeleteActionListener extends ExoActionListener {
94     public DeleteActionListener() {
95       addInterceptor(new CheckRoleInterceptor("admin")) ;
96     }
97     
98     public void execute(ExoActionEvent event) throws Exception JavaDoc {
99         UIListResources uicomp = (UIListResources) event.getComponent() ;
100         String JavaDoc resourceId = event.getParameter(OBJECTID) ;
101         uicomp.service_.removeResourceBundleData(resourceId) ;
102       uicomp.update();
103     }
104   }
105 }
Popular Tags