1 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 20 public class UIPortletCategories extends UIExoCommand { 21 22 public static final String SELECT_PORTLET_CATEGORY = "selectPortletCategory"; 23 public static final String SHOW_PORTLET_CATEGORY_MONITOR = "showPortletCategory"; 24 public static final String SHOW_PORTLET_MONITOR = "showPortlet"; 25 26 public static final String PORTLET_CATEGORY_NAME_PARAM = "portletCategoryName"; 27 public static final String 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 { 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 getFamily() { 55 return "org.exoplatform.portal.faces.component.UIPortletCategories" ; 56 } 57 58 59 public void reset() throws Exception { 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 { 85 UIPortletCategories uiCategories = (UIPortletCategories) event.getComponent() ; 86 String 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 { 95 UIPortletCategories uiCategories = (UIPortletCategories) event.getComponent() ; 96 String 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 { 107 UIPortletCategories uiCategories = (UIPortletCategories) event.getComponent() ; 108 String categoryName = event.getParameter(PORTLET_CATEGORY_NAME_PARAM) ; 109 String 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 |