1 5 package org.exoplatform.portlets.portletregistery.component; 6 7 import java.util.Collection ; 8 9 10 import org.exoplatform.faces.core.event.CheckRoleInterceptor; 11 import org.exoplatform.faces.core.event.ExoActionEvent; 12 import org.exoplatform.faces.core.event.ExoActionListener; 13 import org.exoplatform.portal.faces.component.model.PortletCategoryData; 14 import org.exoplatform.services.portletregistery.PortletCategory; 15 import org.exoplatform.services.portletregistery.PortletRegisteryService; 16 17 22 public class UIPortletInfo 23 extends org.exoplatform.portal.faces.component.UIPortletInfo { 24 25 public static final String EDIT_PORTLET = "editPortlet"; 26 public static final String ADD_ROLE = "addRole"; 27 public static final String DELETE_PORTLET = "deletePortlet"; 28 29 private PortletRegisteryService portletRegisteryService; 30 31 public UIPortletInfo(PortletRegisteryService portletRegisteryService) { 32 super() ; 33 this.portletRegisteryService = portletRegisteryService; 34 addActionListener(new EditActionListener().setActionToListen(EDIT_PORTLET)); 35 addActionListener(new AddRoleActionListener().setActionToListen(ADD_ROLE)); 36 addActionListener(new DeleteActionListener().setActionToListen(DELETE_PORTLET)); 37 } 38 39 public String getFamily() { 40 return "org.exoplatform.portlets.portletregistery.component.UIPortletInfo"; 41 } 42 43 public class EditActionListener extends ExoActionListener { 44 public EditActionListener() { 45 addInterceptor(new CheckRoleInterceptor("admin")) ; 46 } 47 48 public void execute(ExoActionEvent event) throws Exception { 49 UIPortletRegistry uiPortlet = 50 (UIPortletRegistry) getAncestorOfType(UIPortletRegistry.class) ; 51 UIPortletForm uiForm = 52 (UIPortletForm)uiPortlet.getChildComponentOfType(UIPortletForm.class); 53 uiForm.setPortletData(portlet_) ; 54 uiPortlet.setRenderedComponent(UIPortletForm.class) ; 55 } 56 } 57 58 private class AddRoleActionListener extends ExoActionListener { 59 public AddRoleActionListener() { 60 addInterceptor(new CheckRoleInterceptor("admin")) ; 61 } 62 63 public void execute(ExoActionEvent event) throws Exception { 64 UIPortletRegistry uiPortlet = 65 (UIPortletRegistry) getAncestorOfType(UIPortletRegistry.class) ; 66 UIPortletRole uiForm = (UIPortletRole) uiPortlet.getChildComponentOfType(UIPortletRole.class) ; 67 uiForm.setCurrentPortlet(portlet_) ; 68 uiPortlet.setRenderedComponent(uiForm.getId()) ; 69 } 70 } 71 72 private class DeleteActionListener extends ExoActionListener { 73 public DeleteActionListener() { 74 addInterceptor(new CheckRoleInterceptor("admin")) ; 75 } 76 77 public void execute(ExoActionEvent event) throws Exception { 78 portletRegisteryService.removePortlet(portlet_.getId()); 79 UIPortletCategory uiCategory = (UIPortletCategory)getSibling(UIPortletCategory.class) ; 80 PortletCategoryData categoryData = uiCategory.getPortletCategoryData() ; 81 PortletCategory portletCategory = categoryData.getPortletCategory() ; 82 Collection portlets = portletRegisteryService.getPortlets(portletCategory.getId()) ; 83 categoryData.reset(portletCategory, portlets) ; 84 setRenderedSibling(UIPortletCategory.class) ; 85 } 86 } 87 } | Popular Tags |