1 5 package org.exoplatform.portal.faces.listener.portal; 6 7 import java.util.List ; 8 import org.exoplatform.container.PortalContainer; 9 import org.exoplatform.faces.core.event.ExoActionEvent; 10 import org.exoplatform.faces.core.event.ExoActionListener; 11 import org.exoplatform.portal.PortalConstants; 12 import org.exoplatform.portal.faces.component.*; 13 import org.exoplatform.services.portal.PortalConfigService; 14 import org.exoplatform.services.portal.model.Node; 15 20 public class NodeActionListener extends ExoActionListener { 21 public void execute(ExoActionEvent event) throws Exception { 22 UIPortal uiPortal = (UIPortal) event.getSource() ; 23 String portalAction = event.getAction() ; 24 if (PortalConstants.EDIT_NODE_ACTION.equals(portalAction)) { 25 UIPageNodeForm uiPageNodeForm = 26 (UIPageNodeForm)uiPortal.getPortalComponent(UIPageNodeForm.class) ; 27 uiPageNodeForm.setEditingNavigationNode(uiPortal.getSelectedNode()); 28 uiPortal.setBodyComponent(uiPageNodeForm); 29 } else if (PortalConstants.ADD_NODE_ACTION.equals(portalAction)) { 30 UIPageNodeForm uiPageNodeForm = 31 (UIPageNodeForm)uiPortal.getPortalComponent(UIPageNodeForm.class) ; 32 uiPageNodeForm.setEditingNavigationNode(null); 33 uiPortal.setBodyComponent(uiPageNodeForm); 34 } else if (PortalConstants.DELETE_NODE_ACTION.equals(portalAction)) { 35 uiPortal.removeSelectedNode() ; 36 } else if (PortalConstants.SAVE_NODE_ACTION.equals(portalAction)) { 37 PortalConfigService service = 38 (PortalConfigService)PortalContainer.getInstance(). 39 getComponentInstanceOfType(PortalConfigService.class) ; 40 service.saveNodeNavigation(uiPortal.getOwner(), uiPortal.getRootNode()) ; 41 } else if (PortalConstants.MOVE_UP_NODE_ACTION.equals(portalAction)) { 42 Node root = uiPortal.getRootNode() ; 43 Node node = root.findNode(event.getParameter(PortalConstants.NODE_URI)) ; 44 if(node != null) moveUp(node) ; 45 } else if (PortalConstants.MOVE_DOWN_NODE_ACTION.equals(portalAction)) { 46 Node root = uiPortal.getRootNode() ; 47 Node node = root.findNode(event.getParameter(PortalConstants.NODE_URI)) ; 48 if(node != null) moveDown(node) ; 49 } else if (PortalConstants.BROWSE_PAGE_ACTION.equals(portalAction)) { 50 UIPageBrowser uiPageBrowser = 51 (UIPageBrowser)uiPortal.getPortalComponent(UIPageBrowser.class); 52 uiPageBrowser.setReturnModule(UIPageBrowser.UI_PAGE) ; 53 if (uiPageBrowser != null) { 54 uiPortal.setBodyComponent(uiPageBrowser); 55 } 56 } 57 } 58 59 public void moveUp(Node node) { 60 Node parent = node.getParent(); 61 if(parent == null ) return ; 62 List children = parent.getChildren() ; 63 for (int i = 0; i < children.size(); i++) { 64 Node child = (Node)children.get(i); 65 if (child == node) { 66 if(i != 0) { 67 Object tmp = children.remove(i); 68 children.add(i - 1, tmp); 69 } 70 return; 71 } 72 } 73 } 74 75 public void moveDown(Node node) { 76 Node parent = node.getParent(); 77 if(parent == null ) return ; 78 List children = parent.getChildren() ; 79 for (int i = 0; i < children.size(); i++) { 80 Node child = (Node) children.get(i); 81 if (child == node) { 82 if(i != children.size() - 1) { 83 Object tmp = children.remove(i); 84 children.add(i + 1, tmp); 85 } 86 return; 87 } 88 } 89 } 90 } | Popular Tags |