1 5 6 package org.exoplatform.portlets.portletregistery.component; 7 8 9 import java.util.Collection ; 10 import java.util.Map ; 11 import javax.faces.context.FacesContext; 12 import org.apache.commons.lang.StringUtils; 13 import org.exoplatform.faces.core.component.UIExoCommand; 14 import org.exoplatform.faces.core.event.CheckRoleInterceptor; 15 import org.exoplatform.faces.core.event.ExoActionEvent; 16 import org.exoplatform.faces.core.event.ExoActionListener; 17 import org.exoplatform.portal.faces.component.model.PortletCategoryData; 18 import org.exoplatform.services.portletcontainer.PortletContainerService; 19 import org.exoplatform.services.portletregistery.Portlet; 20 import org.exoplatform.services.portletregistery.PortletCategory; 21 import org.exoplatform.services.portletregistery.PortletRegisteryService; 22 27 public class UIPortletList extends UIExoCommand{ 28 private Map allPortletMetaData_; 29 private PortletRegisteryService portletRegisteryService; 30 private PortletCategoryData portletCategoryData_; 31 32 public UIPortletList(PortletContainerService portletContainerService, 33 PortletRegisteryService portletRegisteryService) { 34 setId("UIPortletList") ; 35 setRendererType("AddPortletRenderer") ; 36 allPortletMetaData_ = portletContainerService.getAllPortletMetaData() ; 37 this.portletRegisteryService = portletRegisteryService; 38 addFacesListener(new SaveActionListener().setActionToListen(SAVE_ACTION)); 39 addFacesListener(new CancelActionListener().setActionToListen(CANCEL_ACTION)); 40 } 41 42 public Map getAllPortletMetaData() { return allPortletMetaData_ ; } 43 44 public String getFamily() { 45 return "org.exoplatform.portlets.portletregistery.component.UIPortletList" ; 46 } 47 48 public void setPortletCategoryData(PortletCategoryData category) { 49 portletCategoryData_ = category ; 50 } 51 52 private class SaveActionListener extends ExoActionListener { 53 public SaveActionListener() { 54 addInterceptor(new CheckRoleInterceptor("admin")) ; 55 } 56 57 public void execute(ExoActionEvent event) throws Exception { 58 UIPortletList uiList = (UIPortletList) event.getComponent() ; 59 Map paramValuesMap = 60 FacesContext.getCurrentInstance().getExternalContext().getRequestParameterValuesMap() ; 61 String [] portletId = (String []) paramValuesMap.get("portletId") ; 62 PortletCategory portletCategory = portletCategoryData_.getPortletCategory() ; 63 for (int i = 0; i < portletId.length; i++) { 64 String windowId = portletId[i]; 65 String [] keys = StringUtils.split(windowId, "/") ; 66 Portlet portlet = portletRegisteryService.createPortletInstance(); 67 portlet.setDisplayName(keys[1]); 68 portlet.setPortletApplicationName(keys[0]); 69 portlet.setPortletName(keys[1]); 70 portletRegisteryService.addPortlet(portletCategory, portlet); 71 } 72 Collection portlets = portletRegisteryService.getPortlets(portletCategory.getId()) ; 73 portletCategoryData_.reset(portletCategory, portlets) ; 74 uiList.setRenderedSibling(UIPortletCategories.class) ; 75 } 76 } 77 78 private class CancelActionListener extends ExoActionListener { 79 public void execute(ExoActionEvent event) throws Exception { 80 UIPortletRegistry uiPortlet = (UIPortletRegistry) getParent(); 81 uiPortlet.setRenderedComponent(UIPortletCategories.class); 82 } 83 } 84 } | Popular Tags |