KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > portletregistery > component > UIPortletInfo


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.portletregistery.component;
6
7 import java.util.Collection JavaDoc;
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 /**
18  * Created y the eXo platform team
19  * User: Benjamin Mestrallet
20  * Date: 18 juin 2004
21  */

22 public class UIPortletInfo
23     extends org.exoplatform.portal.faces.component.UIPortletInfo {
24     
25   public static final String JavaDoc EDIT_PORTLET = "editPortlet";
26   public static final String JavaDoc ADD_ROLE = "addRole";
27   public static final String JavaDoc 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 JavaDoc 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 JavaDoc {
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 JavaDoc {
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 JavaDoc {
78       portletRegisteryService.removePortlet(portlet_.getId());
79       UIPortletCategory uiCategory = (UIPortletCategory)getSibling(UIPortletCategory.class) ;
80       PortletCategoryData categoryData = uiCategory.getPortletCategoryData() ;
81       PortletCategory portletCategory = categoryData.getPortletCategory() ;
82       Collection JavaDoc portlets = portletRegisteryService.getPortlets(portletCategory.getId()) ;
83       categoryData.reset(portletCategory, portlets) ;
84       setRenderedSibling(UIPortletCategory.class) ;
85     }
86   }
87 }
Popular Tags