KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > exoplatform > portlets > nav > component > UIMenu


1 package org.exoplatform.portlets.nav.component;
2
3 import java.util.List JavaDoc;
4 import java.util.ResourceBundle JavaDoc;
5 import javax.faces.component.UIComponent;
6 import org.exoplatform.container.SessionContainer;
7 import org.exoplatform.faces.core.component.UIToolbar;
8 import org.exoplatform.faces.core.component.model.Button;
9 import org.exoplatform.faces.core.component.model.Parameter;
10 import org.exoplatform.faces.core.event.ExoActionEvent;
11 import org.exoplatform.faces.core.event.ExoActionListener;
12 import org.exoplatform.portal.PortalConstants;
13 import org.exoplatform.portal.session.ExoPortal;
14 import org.exoplatform.services.portal.model.Node;
15 /**
16  * @version $Revision: 1.8 $ $Date: 2004/10/19 13:20:03 $
17  * @author Tuan Nguyen
18  */

19 public class UIMenu extends UINavigation {
20   final static public String JavaDoc VIEW_MODE_RENDERER = "ExoMenuRenderer" ;
21   final static public String JavaDoc EDIT_PORTAL_MODE_RENDERER = "ExoEditPortalModeMenuRenderer" ;
22   final static public String JavaDoc EDIT_PAGE_MODE_RENDERER = "ExoEditPageModeMenuRenderer" ;
23   final static public String JavaDoc EDIT_NAVIGATION_MODE_RENDERER = "ExoEditNavigationModeMenuRenderer" ;
24   
25   final static public Parameter[] addNodeParams = {new Parameter(ACTION, PortalConstants.ADD_NODE_ACTION) };
26   final static public Parameter[] saveNavigationParams = {new Parameter(ACTION, PortalConstants.SAVE_NODE_ACTION) };
27   final static public Parameter[] browsePageParams = {new Parameter(ACTION, PortalConstants.BROWSE_PAGE_ACTION) };
28   final static public Parameter[] savePageParams = {new Parameter(ACTION, PortalConstants.SAVE_PAGE_ACTION) };
29   final static public Parameter[] editPortalParams = {new Parameter(ACTION, PortalConstants.EDIT_PORTAL_ACTION) };
30   final static public Parameter[] savePortalParams = {new Parameter(ACTION, PortalConstants.SAVE_PORTAL_ACTION) };
31   private UIToolbar uiToolbarView_;
32   private UIToolbar uiToolbarPortal_;
33   private UIToolbar uiToolbarNav_;
34   private UIToolbar uiToolbarPage_;
35   private boolean showToolBar_ ;
36   
37     public UIMenu(ResourceBundle JavaDoc res) throws Exception JavaDoc {
38         super(res) ;
39         setId("UIMenu");
40         setRendererType(VIEW_MODE_RENDERER);
41     
42     List JavaDoc children = getChildren() ;
43     uiToolbarView_ = new UIToolbar("UIToolbarView");
44     uiToolbarView_.setRendered(true);
45     ExoPortal portal = (ExoPortal) SessionContainer.getComponent(ExoPortal.class) ;
46     
47     if(portal.hasEditPortalCapability()) {
48       uiToolbarView_.addRightButton(new Button("#{UIMenu.button.portal-mode}", editPortalModeParams));
49       uiToolbarPortal_ = new UIToolbar("UIToolbarPortal");
50       uiToolbarPortal_.addLeftButton(new Button("#{UIMenu.button.edit-portal-properties}", editPortalParams));
51       uiToolbarPortal_.addLeftButton(new Button("#{UIMenu.button.save-portal}", savePortalParams));
52       uiToolbarPortal_.addRightButton(new Button("#{UIMenu.button.view-mode}", viewModeParams));
53       uiToolbarPortal_.setRendered(true);
54     }
55     
56     if(portal.hasEditNavigationCapability()) {
57       uiToolbarView_.addRightButton(new Button("#{UIMenu.button.navigation-mode}", editNavigationModeParams));
58       uiToolbarNav_ = new UIToolbar("UIToolbarNav");
59       uiToolbarNav_.addLeftButton(new Button("#{UIMenu.button.browse-pages}", browsePageParams));
60       uiToolbarNav_.addLeftButton(new Button("#{UIMenu.button.save-navigation}", saveNavigationParams));
61       uiToolbarNav_.addRightButton(new Button("#{UIMenu.button.view-mode}", viewModeParams));
62       uiToolbarNav_.setRendered(true);
63       
64       uiToolbarView_.addRightButton(new Button("#{UIMenu.button.page-mode}", editPageModeParams));
65       uiToolbarPage_ = new UIToolbar("UIToolbarPage");
66       uiToolbarPage_.addLeftButton(new Button("#{UIMenu.button.browse-pages}", browsePageParams));
67       uiToolbarPage_.addLeftButton(new Button("#{UIMenu.button.save-page}", savePageParams));
68       uiToolbarPage_.addRightButton(new Button("#{UIMenu.button.view-mode}", viewModeParams));
69       uiToolbarPage_.setRendered(true);
70     }
71     
72     showToolBar_ = portal.hasEditPortalCapability() || portal.hasEditNavigationCapability() ;
73     if(showToolBar_) {
74       children.add(uiToolbarView_);
75     }
76     addActionListener(ForwardPortalEventActionListener.class, PortalConstants.SAVE_PAGE_ACTION) ;
77     addActionListener(ForwardPortalEventActionListener.class, PortalConstants.EDIT_PORTAL_ACTION) ;
78     addActionListener(ForwardPortalEventActionListener.class, PortalConstants.SAVE_PORTAL_ACTION) ;
79     
80     addActionListener(ForwardNodeEventActionListener.class, PortalConstants.ADD_NODE_ACTION) ;
81     addActionListener(ForwardPortalEventActionListener.class, PortalConstants.BROWSE_PAGE_ACTION) ;
82     addActionListener(ForwardNodeEventActionListener.class, PortalConstants.MOVE_UP_NODE_ACTION) ;
83     addActionListener(ForwardNodeEventActionListener.class, PortalConstants.MOVE_DOWN_NODE_ACTION) ;
84     addActionListener(ForwardNodeEventActionListener.class, PortalConstants.DELETE_NODE_ACTION) ;
85     addActionListener(ForwardNodeEventActionListener.class, PortalConstants.EDIT_NODE_ACTION) ;
86     addActionListener(ForwardPortalEventActionListener.class, PortalConstants.SAVE_NODE_ACTION) ;
87     }
88     
89   public boolean isShowAdminButton() { return showToolBar_; }
90   
91     public void setViewModeRenderer() {
92     setRendererType(VIEW_MODE_RENDERER);
93     List JavaDoc children = getChildren() ;
94     children.remove(0);
95     children.add(uiToolbarView_);
96   }
97     
98     public void setEditPortalModeRenderer() {
99     setRendererType(EDIT_PORTAL_MODE_RENDERER);
100     List JavaDoc children = getChildren() ;
101     children.remove(0);
102     children.add(uiToolbarPortal_);
103   }
104     
105     public void setEditPageModeRenderer() {
106     setRendererType(EDIT_PAGE_MODE_RENDERER );
107     List JavaDoc children = getChildren() ;
108     children.remove(0);
109     children.add(uiToolbarPage_);
110   }
111     
112     public void setEditNavigationModeRenderer() {
113     setRendererType(EDIT_NAVIGATION_MODE_RENDERER );
114     List JavaDoc children = getChildren() ;
115     children.remove(0);
116     children.add(uiToolbarNav_);
117   }
118   
119   public UIToolbar getUIToolbarNav() {
120     return uiToolbarNav_;
121   }
122   
123   public UIToolbar getUIToolbarPage() {
124     return uiToolbarPage_;
125   }
126
127   public UIToolbar getUIToolbarPortal() {
128     return uiToolbarPortal_;
129   }
130     
131   public UIToolbar getUIToolbarView() {
132     return uiToolbarView_;
133   }
134   
135   static public class ForwardPortalEventActionListener extends ExoActionListener {
136     public void execute(ExoActionEvent event) throws Exception JavaDoc {
137       ExoPortal portal = (ExoPortal) SessionContainer.getComponent(ExoPortal.class) ;
138       ExoActionEvent portalEvent = new ExoActionEvent((UIComponent)portal, getActionName()) ;
139       portal.queueEvent(portalEvent) ;
140     }
141   }
142   
143   static public class ForwardNodeEventActionListener extends ExoActionListener {
144     public void execute(ExoActionEvent event) throws Exception JavaDoc {
145       ExoPortal portal = (ExoPortal) SessionContainer.getComponent(ExoPortal.class) ;
146       ExoActionEvent portalEvent = new ExoActionEvent((UIComponent)portal, getActionName()) ;
147       String JavaDoc nodeURI =event.getParameter(PortalConstants.NODE_URI) ;
148       Node node = portal.getRootNode().findNode(nodeURI) ;
149       portal.setSelectedNode(node) ;
150       portalEvent.addParameter(PortalConstants.NODE_URI, nodeURI) ;
151       portal.queueEvent(portalEvent) ;
152     }
153   }
154   
155   public String JavaDoc getFamily( ) { return "org.exoplatform.portlets.nav.component.UIMenu" ; }
156   
157 }
Popular Tags