KickJava   Java API By Example, From Geeks To Geeks.

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


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
8 import java.util.* ;
9 import org.exoplatform.faces.core.component.UIExoCommand;
10 import org.exoplatform.faces.core.event.ExoActionEvent;
11 import org.exoplatform.faces.core.event.ExoActionListener;
12 import org.exoplatform.portal.faces.component.model.PortletCategoryData;
13 import org.exoplatform.portal.faces.listener.share.ShowLastBodyComponentActionListener;
14 import org.exoplatform.services.portletregistery.*;
15 /**
16  * Created y the eXo platform team
17  * User: Benjamin Mestrallet
18  * Date: 17 juin 2004
19  */

20 public class UIPortletCategories extends UIExoCommand {
21   
22   public static final String JavaDoc SELECT_PORTLET_CATEGORY = "selectPortletCategory";
23   public static final String JavaDoc SHOW_PORTLET_CATEGORY_MONITOR = "showPortletCategory";
24   public static final String JavaDoc SHOW_PORTLET_MONITOR = "showPortlet";
25
26   public static final String JavaDoc PORTLET_CATEGORY_NAME_PARAM = "portletCategoryName";
27   public static final String JavaDoc PORTLET_NAME_PARAM = "portletName";
28   
29   protected UIPortletCategory uiPortletCategory_ ;
30   protected UIPortletInfo uiPortletInfo_ ;
31   protected PortletRegisteryService portletRegisteryService;
32   protected Map portletCaterories = new HashMap() ;
33
34   public UIPortletCategories(PortletRegisteryService portletRegisteryService,
35                              UIPortletCategory uiPortletCategory,
36                                                          UIPortletInfo uiPortletInfo) throws Exception JavaDoc {
37     setRendererType("PortletCategoriesRenderer");
38     setId("UIPortletCategories");
39     this.portletRegisteryService = portletRegisteryService;
40     uiPortletCategory_ = uiPortletCategory ;
41     List children = getChildren();
42     uiPortletCategory.setRendered(true);
43     children.add(uiPortletCategory);
44     uiPortletInfo_ = uiPortletInfo ;
45     uiPortletInfo_.setRendered(false) ;
46     children.add(uiPortletInfo) ;
47     addActionListener(ShowLastBodyComponentActionListener.class, CANCEL_ACTION);
48     addActionListener(SelectCategoryActionListener.class, SELECT_PORTLET_CATEGORY);
49     addActionListener(ShowCategoryActionListener.class, SHOW_PORTLET_CATEGORY_MONITOR);
50     addActionListener(ShowPortletActionListener.class, SHOW_PORTLET_MONITOR);
51     reset() ;
52   }
53
54   public String JavaDoc getFamily() {
55     return "org.exoplatform.portal.faces.component.UIPortletCategories" ;
56   }
57   
58   
59   public void reset() throws Exception JavaDoc {
60     portletCaterories.clear() ;
61     Iterator i = portletRegisteryService.getPortletCategories().iterator();
62     while(i.hasNext()){
63         PortletCategory portletCategory = (PortletCategory) i.next();
64         Collection portlets = portletRegisteryService.getPortlets(portletCategory.getId()) ;
65         PortletCategoryData data = new PortletCategoryData(portletCategory, portlets) ;
66       portletCaterories.put(portletCategory.getPortletCategoryName(), data) ;
67     }
68     if(portletCaterories.size() > 0) {
69         PortletCategoryData select =
70             (PortletCategoryData)portletCaterories.values().iterator().next() ;
71         select.setSelect(true) ;
72         uiPortletCategory_.setPortletCategoryData(select) ;
73     }
74   }
75   
76   public Map getPortletCaterories() { return portletCaterories; }
77   
78   public boolean hasCategory() {
79     if(portletCaterories.isEmpty()) return false;
80     return true;
81   }
82   
83   static public class SelectCategoryActionListener extends ExoActionListener {
84     public void execute(ExoActionEvent event) throws Exception JavaDoc {
85         UIPortletCategories uiCategories = (UIPortletCategories) event.getComponent() ;
86         String JavaDoc categoryName = event.getParameter(PORTLET_CATEGORY_NAME_PARAM) ;
87         PortletCategoryData portletCategoryData =
88             (PortletCategoryData) uiCategories.portletCaterories.get(categoryName) ;
89         portletCategoryData.setSelect(!portletCategoryData.isSelect()) ;
90     }
91   }
92
93   static public class ShowCategoryActionListener extends ExoActionListener {
94     public void execute(ExoActionEvent event) throws Exception JavaDoc {
95         UIPortletCategories uiCategories = (UIPortletCategories) event.getComponent() ;
96         String JavaDoc categoryName = event.getParameter(PORTLET_CATEGORY_NAME_PARAM) ;
97         PortletCategoryData portletCategoryData =
98             (PortletCategoryData) uiCategories.portletCaterories.get(categoryName) ;
99         portletCategoryData.setSelect(true) ;
100         uiCategories.uiPortletCategory_.setPortletCategoryData(portletCategoryData) ;
101         uiCategories.setRenderedComponent(UIPortletCategory.class);
102     }
103   }
104
105   static public class ShowPortletActionListener extends ExoActionListener {
106     public void execute(ExoActionEvent event) throws Exception JavaDoc {
107         UIPortletCategories uiCategories = (UIPortletCategories) event.getComponent() ;
108         String JavaDoc categoryName = event.getParameter(PORTLET_CATEGORY_NAME_PARAM) ;
109       String JavaDoc portletName = event.getParameter(PORTLET_NAME_PARAM) ;
110       PortletCategoryData categoryData =
111         (PortletCategoryData)uiCategories.portletCaterories.get(categoryName) ;
112       Portlet portlet = categoryData.findPortlet(portletName) ;
113       uiCategories.uiPortletInfo_.setPortletData(portlet);
114       uiCategories.setRenderedComponent(UIPortletInfo.class);
115     }
116   }
117 }
Popular Tags