KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > indexing > component > UIListIndexer


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.indexing.component;
6
7 import java.util.ResourceBundle JavaDoc;
8 import org.exoplatform.faces.application.ExoFacesMessage;
9 import org.exoplatform.faces.core.component.InformationProvider;
10 import org.exoplatform.faces.core.component.UIGrid;
11 import org.exoplatform.faces.core.component.UIPortlet;
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.services.indexing.IndexerPlugin;
17 import org.exoplatform.services.indexing.IndexingService;
18 /**
19  * Sat, Jan 03, 2004 @ 11:16
20  * @author: Tuan Nguyen
21  * @email: tuan08@users.sourceforge.net
22  * @version: $Id: UIListIndexer.java,v 1.2 2004/09/16 20:17:02 tuan08 Exp $
23  */

24 public class UIListIndexer extends UIGrid {
25   final static public String JavaDoc REINDEX_ACTION = "reindex" ;
26   final static public String JavaDoc REMOVE_INDEX_ACTION = "removeIndex" ;
27   final static public String JavaDoc MORE_ACTION = "more" ;
28     static Parameter[] REMOVE_INDEX_PARAMS = { new Parameter(ACTION , REMOVE_INDEX_ACTION) } ;
29   static Parameter[] REINDEX_PARAMS = { new Parameter(ACTION , REINDEX_ACTION) } ;
30   static Parameter[] MORE_PARAMS = { new Parameter(ACTION , MORE_ACTION) } ;
31     
32     private IndexerPluginDataHandler dataHandler_ ;
33   private IndexingService iservice_ ;
34   private ResourceBundle JavaDoc res_ ;
35     
36     public UIListIndexer(IndexingService iservice, ResourceBundle JavaDoc res) throws Exception JavaDoc {
37         setId("UIListIndexer") ;
38     iservice_ = iservice ;
39     res_ = res ;
40         dataHandler_ = new IndexerPluginDataHandler() ;
41     dataHandler_.setDatas(iservice_.getIndexerPlugins()) ;
42         add(new Rows(dataHandler_, "even", "odd").
43                 add(new Column("#{UIListIndexer.header.name}", "name")).
44                 add(new Column("#{UIListIndexer.header.description}", "description")).
45                 add(new ActionColumn("#{UIListIndexer.header.action}", "identifier").
46                         add(true, new Button("#{UIListIndexer.button.reindex}", REINDEX_PARAMS)).
47             add(true, new Button("#{UIListIndexer.button.remove-index}", REMOVE_INDEX_PARAMS)).
48             add(true, new Button("#{UIListIndexer.button.more}", MORE_PARAMS)))) ;
49         
50     addActionListener(ReindexActionListener.class, REINDEX_ACTION ) ;
51     addActionListener(RemoveIndexActionListener.class, REMOVE_INDEX_ACTION ) ;
52         addActionListener(MoreActionListener.class, MORE_ACTION) ;
53     }
54     
55     
56     public class IndexerPluginDataHandler extends CollectionDataHandler {
57         private IndexerPlugin plugin_ ;
58         
59         public String JavaDoc getData(String JavaDoc fieldName) {
60             if("name".equals(fieldName))
61         return res_.getString("UIListIndexer." + plugin_.getPluginIdentifier() + ".name");
62             if("description".equals(fieldName))
63         return res_.getString("UIListIndexer." + plugin_.getPluginIdentifier() + ".description");
64             if("identifier".equals(fieldName))
65         return plugin_.getPluginIdentifier() ;
66             return null ;
67         }
68         
69         public void setCurrentObject(Object JavaDoc o) { plugin_ = (IndexerPlugin) o; }
70     }
71     
72     
73   static public class MoreActionListener extends ExoActionListener {
74     public MoreActionListener() {
75       addInterceptor(new CheckRoleInterceptor("admin")) ;
76     }
77     
78     public void execute(ExoActionEvent event) throws Exception JavaDoc {
79       UIListIndexer uiList= (UIListIndexer) event.getComponent() ;
80       String JavaDoc objectId = event.getParameter(OBJECTID) ;
81       UIPortlet uiPortlet = (UIPortlet) uiList.getParent() ;
82       if(uiPortlet.findComponentById(objectId) == null) {
83         InformationProvider iprovider = findInformationProvider(uiList) ;
84         iprovider.addMessage(new ExoFacesMessage("#{UIListIndexer.msg.not-support-extension}")) ;
85       } else {
86         uiPortlet.setRenderedComponent(objectId) ;
87       }
88     }
89   }
90   
91     static public class ReindexActionListener extends ExoActionListener {
92     public ReindexActionListener() {
93       addInterceptor(new CheckRoleInterceptor("admin")) ;
94     }
95     
96         public void execute(ExoActionEvent event) throws Exception JavaDoc {
97       UIListIndexer uiList = (UIListIndexer) event.getComponent() ;
98       String JavaDoc objectId = event.getParameter(OBJECTID) ;
99       IndexerPlugin plugin = uiList.iservice_.getIndexerPlugin(objectId) ;
100       plugin.reindex() ;
101         }
102     }
103   
104   static public class RemoveIndexActionListener extends ExoActionListener {
105     public RemoveIndexActionListener() {
106       addInterceptor(new CheckRoleInterceptor("admin")) ;
107     }
108     
109     public void execute(ExoActionEvent event) throws Exception JavaDoc {
110       UIListIndexer uiList = (UIListIndexer) event.getComponent() ;
111       String JavaDoc objectId = event.getParameter(OBJECTID) ;
112       IndexerPlugin plugin = uiList.iservice_.getIndexerPlugin(objectId) ;
113       plugin.removeIndex() ;
114     }
115   }
116 }
Popular Tags