1 package org.exoplatform.portlets.nav.component; 2 3 import java.util.ResourceBundle ; 4 import org.exoplatform.container.SessionContainer; 5 import org.exoplatform.container.client.http.HttpClientInfo; 6 import org.exoplatform.faces.core.component.UIExoCommand; 7 import org.exoplatform.faces.core.component.model.Parameter; 8 import org.exoplatform.faces.core.event.ExoActionEvent; 9 import org.exoplatform.faces.core.event.ExoActionListener; 10 import org.exoplatform.portal.session.ExoPortal; 11 import org.exoplatform.portal.session.RequestInfo; 12 import org.exoplatform.services.portal.model.Node; 13 14 18 public class UINavigation extends UIExoCommand { 19 final public static Parameter CHANGE_NODE = new Parameter(ACTION, "changeNode"); 20 final static public Parameter CHANGE_MODE = new Parameter(ACTION, "changeMode"); 21 final static public Parameter[] viewModeParams = {CHANGE_MODE, new Parameter("mode", "normal") }; 22 final static public Parameter[] editNavigationModeParams = 23 {CHANGE_MODE, new Parameter("mode", "edit-navigation") }; 24 final static public Parameter[] editPortalModeParams = {CHANGE_MODE, new Parameter("mode", "edit-portal") }; 25 final static public Parameter[] editPageModeParams = {CHANGE_MODE, new Parameter("mode", "edit-page") }; 26 27 final static public String DEFAULT_RENDERER_TYPE = "HorizontalMenuRenderer" ; 28 29 protected Node rootNode_ ; 30 private boolean adminRole_ = false ; 31 private boolean showReturn_ = false ; 32 private String preferedMimetype_ ; 33 34 public UINavigation(ResourceBundle res) throws Exception { 35 setId("UINavigation"); 36 setRendererType(DEFAULT_RENDERER_TYPE); 37 setTransient(false); 38 HttpClientInfo info = 39 (HttpClientInfo) SessionContainer.getInstance().getMonitor().getClientInfo() ; 40 preferedMimetype_ = info.getPreferredMimeType() ; 41 ExoPortal portal = (ExoPortal)SessionContainer.getComponent(ExoPortal.class) ; 42 rootNode_ = portal.getRootNode() ; 43 RequestInfo rinfo = (RequestInfo) SessionContainer.getComponent(RequestInfo.class) ; 44 String accessibility = rinfo.getAccessibility() ; 45 if(RequestInfo.PRIVATE_ACCESS.equals(accessibility)) { 46 adminRole_ = true ; 47 } else if (RequestInfo.ADMIN_ACCESS.equals(accessibility)) { 48 adminRole_ = true ; showReturn_ = true ; 49 } else { 50 adminRole_ = false ; 51 } 52 53 addActionListener(ChangeNodeActionListener.class, "changeNode") ; 54 addActionListener(ChangeModeActionListener.class, "changeMode") ; 55 } 56 57 public Node getRootNode() { return rootNode_ ; } 58 public Node getSelectedNode() { 59 ExoPortal portal = (ExoPortal)SessionContainer.getComponent(ExoPortal.class) ; 60 return portal.getSelectedNode() ; 61 } 62 63 public String getPreferedMimeType() { return preferedMimetype_ ; } 64 65 public boolean hasAdminRole() { return adminRole_ ; } 66 67 public boolean getShowReturn() { return showReturn_ ; } 68 69 public void setViewModeRenderer() { } 70 71 public void setEditPortalModeRenderer() { } 72 73 public void setEditPageModeRenderer() { } 74 75 public void setEditNavigationModeRenderer() { } 76 77 public String getFamily( ) { return "org.exoplatform.portlets.nav.component.UINavigation" ; } 78 79 static public class ChangeNodeActionListener extends ExoActionListener { 80 public void execute(ExoActionEvent event) throws Exception { 81 String uri = event.getParameter("uri"); 82 ExoPortal portal = (ExoPortal)SessionContainer.getComponent(ExoPortal.class) ; 83 Node node = portal.getRootNode().findNode(uri) ; 84 portal.setSelectedNode(node) ; 85 } 86 } 87 88 static public class ChangeModeActionListener extends ExoActionListener { 89 public void execute(ExoActionEvent event) throws Exception { 90 UINavigation uiNavigation = (UINavigation) event.getSource() ; 91 String mode = event.getParameter("mode"); 92 ExoPortal portal = (ExoPortal)SessionContainer.getComponent(ExoPortal.class) ; 93 if("edit-navigation".equals(mode)) { 94 portal.setPortalMode(ExoPortal.PORTAL_EDIT_NAVIGATION_MODE) ; 95 uiNavigation.setEditNavigationModeRenderer() ; 96 } else if("edit-portal".equals(mode)) { 97 portal.setPortalMode(ExoPortal.PORTAL_EDIT_MODE) ; 98 uiNavigation.setEditPortalModeRenderer() ; 99 } else if("edit-page".equals(mode)) { 100 portal.setPortalMode(ExoPortal.PORTAL_EDIT_PAGE_MODE) ; 101 uiNavigation.setEditPageModeRenderer() ; 102 } else { 103 portal.setPortalMode(ExoPortal.PORTAL_VIEW_MODE) ; 104 uiNavigation.setViewModeRenderer() ; 105 } 106 } 107 } 108 } | Popular Tags |