KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > console > component > UIListCache


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.console.component;
6
7 import org.exoplatform.faces.core.component.UIGrid;
8 import org.exoplatform.faces.core.component.model.*;
9 import org.exoplatform.faces.core.event.ExoActionEvent;
10 import org.exoplatform.faces.core.event.ExoActionListener;
11 import org.exoplatform.services.cache.CacheService;
12 import org.exoplatform.services.cache.ExoCache;
13 /**
14  * Created y the eXo platform team
15  * User: Benjamin Mestrallet
16  * Date: 22 juin 2004
17  */

18 public class UIListCache extends UIGrid {
19   final static public String JavaDoc CLEAR_ACTION = "clear" ;
20   final static public String JavaDoc REFRESH_ACTION = "refresh" ;
21   private static Parameter[] CLEAR_PARAMS = {new Parameter(ACTION , CLEAR_ACTION) } ;
22   private static Parameter[] REFRESH_PARAMS = {new Parameter(ACTION , REFRESH_ACTION) } ;
23
24   private ExoCacheDataHandler dataHandler_ ;
25   private CacheService service_ ;
26   private boolean adminRole_ ;
27
28   public UIListCache(CacheService cservice) throws Exception JavaDoc {
29     setId("UIListCache") ;
30     service_ = cservice ;
31     dataHandler_ = new ExoCacheDataHandler() ;
32     dataHandler_.setDatas(service_.getAllCacheInstances()) ;
33     adminRole_ = hasRole("admin") ;
34     add(new Rows(dataHandler_, "even", "odd").
35         add(new Column("#{UIListCache.header.name}", "name").setCellClass("left-indent")).
36         add(new Column("#{UIListCache.header.cache-size}", "cacheSize")).
37         add(new Column("#{UIListCache.header.max-size}", "maxSize")).
38         add(new Column("#{UIListCache.header.cache-hit}", "cacheHit")).
39         add(new Column("#{UIListCache.header.cache-miss}", "cacheMiss")).
40         add(new ActionColumn("#{UIListCache.header.action}", "name").
41             add(adminRole_ ,new Button("#{UIListCache.button.clear}", CLEAR_PARAMS)))) ;
42     add(new Row().setClazz("footer").
43         add(new ActionCell().
44             add(adminRole_, new Button("#{UIListCache.button.refresh}", REFRESH_PARAMS)).
45             addColspan("6").addAlign("center")));
46     addActionListener(ClearActionListener.class, CLEAR_ACTION) ;
47     addActionListener(RefreshActionListener.class, REFRESH_ACTION) ;
48   }
49
50   static public class ExoCacheDataHandler extends CollectionDataHandler {
51     private ExoCache instance ;
52     
53     public String JavaDoc getData(String JavaDoc fieldName) {
54       if("name".equals(fieldName)) return instance.getName() ;
55       if("cacheHit".equals(fieldName)) return Integer.toString(instance.getCacheHit()) ;
56       if("cacheMiss".equals(fieldName)) return Integer.toString(instance.getCacheMiss()) ;
57       if("cacheSize".equals(fieldName)) return Integer.toString(instance.getCacheSize()) ;
58       if("maxSize".equals(fieldName)) return Integer.toString(instance.getMaxSize()) ;
59         return "unknown" ;
60     }
61     
62     public void setCurrentObject(Object JavaDoc o) { instance = (ExoCache) o; }
63   }
64   
65   static public class ClearActionListener extends ExoActionListener {
66     public void execute(ExoActionEvent event) throws Exception JavaDoc {
67       UIListCache uiComp = (UIListCache) event.getSource() ;
68       String JavaDoc name = event.getParameter(OBJECTID) ;
69       ExoCache cache = uiComp.service_.getCacheInstance(name) ;
70       cache.clear() ;
71     }
72   }
73   
74   static public class RefreshActionListener extends ExoActionListener {
75     public void execute(ExoActionEvent event) throws Exception JavaDoc {
76       UIListCache uiComp = (UIListCache) event.getSource() ;
77       uiComp.dataHandler_.setDatas(uiComp.service_.getAllCacheInstances()) ;
78     }
79   }
80 }
Popular Tags