KickJava   Java API By Example, From Geeks To Geeks.

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


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
6 package org.exoplatform.portlets.portletregistery.component;
7
8
9 import java.util.Collection JavaDoc;
10 import java.util.Map JavaDoc;
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 /**
23  * Created y the eXo platform team
24  * User: Benjamin Mestrallet
25  * Date: 18 juin 2004
26  */

27 public class UIPortletList extends UIExoCommand{
28   private Map JavaDoc 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 JavaDoc getAllPortletMetaData() { return allPortletMetaData_ ; }
43
44   public String JavaDoc 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 JavaDoc{
58         UIPortletList uiList = (UIPortletList) event.getComponent() ;
59       Map JavaDoc paramValuesMap =
60         FacesContext.getCurrentInstance().getExternalContext().getRequestParameterValuesMap() ;
61       String JavaDoc[] portletId = (String JavaDoc[]) paramValuesMap.get("portletId") ;
62       PortletCategory portletCategory = portletCategoryData_.getPortletCategory() ;
63       for (int i = 0; i < portletId.length; i++) {
64         String JavaDoc windowId = portletId[i];
65         String JavaDoc[] 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 JavaDoc 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 JavaDoc {
80       UIPortletRegistry uiPortlet = (UIPortletRegistry) getParent();
81       uiPortlet.setRenderedComponent(UIPortletCategories.class);
82     }
83   }
84 }
Popular Tags