1 23 24 28 29 package com.sun.enterprise.tools.admingui.handlers; 30 31 import java.util.ArrayList ; 32 import javax.servlet.http.HttpServletRequest ; 33 import com.iplanet.jato.RequestContext; 34 import com.iplanet.jato.RequestContextImpl; 35 import com.iplanet.jato.RequestManager; 36 import com.iplanet.jato.view.ViewBean; 37 38 import com.sun.enterprise.tools.admingui.util.Util; 39 import com.sun.enterprise.tools.admingui.tree.IndexTreeNode; 40 import com.sun.enterprise.tools.admingui.tree.IndexTreeModelImpl; 41 import com.sun.enterprise.tools.admingui.tree.IndexTreeModel; 42 43 import com.sun.enterprise.tools.guiframework.view.HandlerContext; 44 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 45 46 49 public class TreeHandlers { 50 51 public void refreshTreeNode(RequestContext ctx, HandlerContext handlerCtx) { 52 ctx.getRequest().setAttribute("refreshTree", new Boolean ("true")); 53 Util.getSelectedNode().setRefresh(true); 54 } 55 56 public void refreshTreeNodeById(RequestContext ctx, HandlerContext handlerCtx) { 57 ctx.getRequest().setAttribute("refreshTree", new Boolean ("true")); 58 String nodeId = (String )handlerCtx.getInputValue("nodeId"); 59 IndexTreeNode node = 60 Util.getCurrentTreeModel().getNodeByUniqueID(nodeId, null, null); 61 if (node != null) 62 node.setRefresh(true); 63 } 64 65 public void refreshParentNode(RequestContext ctx, HandlerContext handlerCtx) { 66 ctx.getRequest().setAttribute("refreshTree", new Boolean ("true")); 67 Util.getSelectedNode().getParent().setRefresh(true); 68 } 69 70 public void openTreeNode(RequestContext ctx, HandlerContext handlerCtx) { 71 Util.getSelectedNode().openNode(ctx); 72 } 73 74 public void getNumberOfChildNodes(RequestContext ctx, HandlerContext handlerCtx) { 75 int count = Util.getSelectedNode().getChildren().size(); 76 handlerCtx.setOutputValue("count", new Integer (count)); 77 } 78 79 public void getAttributeFromTree(RequestContext ctx, HandlerContext handlerCtx) { 80 HttpServletRequest req = ctx.getRequest(); 81 String attrName = (String )handlerCtx.getInputValue("attrName"); 82 boolean lookInHierarchy = true; 83 Boolean look = (Boolean )handlerCtx.getInputValue("lookInHierarchy"); 84 if (look != null) 85 lookInHierarchy = look.booleanValue(); 86 Object attrValue = Util.getSelectedNode().getAttribute(attrName, lookInHierarchy); 87 handlerCtx.setOutputValue(VALUE, attrValue); 88 } 89 90 public void changeTreeModel(RequestContext ctx, HandlerContext handlerCtx) { 91 Util.setCurrentTreeModelType(ctx, (String )handlerCtx.getInputValue("modelName")); 92 ctx.getRequest().setAttribute("refreshRightSide", new Boolean ("true")); 94 } 95 96 public void getTreeModelType(RequestContext ctx, HandlerContext handlerCtx) { 97 handlerCtx.setOutputValue(VALUE, Util.getCurrentTreeModelType(ctx)); 98 } 99 100 public void moveSelectedNode(RequestContext ctx, HandlerContext handlerCtx) { 104 String childName = (String )handlerCtx.getInputValue("editKeyValue"); 105 if (childName == null) { 106 throw new FrameworkException("\"editKeyValue\" not defined!", 107 null, handlerCtx.getView()); 108 } 109 IndexTreeNode selectedNode = Util.getSelectedNode(); 110 IndexTreeNode childNode = selectedNode.getChild(childName); 111 if (childNode == null) { 112 if (Util.isLoggableFINE()) { 113 Util.logFINE("Child node ("+childName+") not found!"); 114 } 115 handlerCtx.setOutputValue(OBJECT_NAME, null); 116 return; 117 } 120 Util.setSelectedNode(childNode); 121 handlerCtx.setOutputValue(OBJECT_NAME, childNode.getAttribute(OBJECT_NAME, false)); 122 } 123 124 public void warpToNode(RequestContext ctx, HandlerContext handlerCtx) { 125 ArrayList parentIDs = (ArrayList )handlerCtx.getInputValue("parentID"); 126 if (parentIDs == null) { 127 throw new FrameworkException("warpToNode: \"parentID\" not defined!", 128 null, handlerCtx.getView()); 129 } 130 String childName = (String )handlerCtx.getInputValue("childName"); 131 132 IndexTreeNode childNode = null; 133 for (int i=0; i<parentIDs.size(); i++) { 134 String parentID = (String )parentIDs.get(i); 135 childNode = 136 Util.getCurrentTreeModel().getNodeByUniqueID(parentID, childName, null); 137 if (childNode != null) 138 break; 139 } 140 if (childNode == null) 141 return; 142 143 String grandChildId = (String )handlerCtx.getInputValue("grandChildId"); 144 if (grandChildId != null) { 145 IndexTreeNode node = Util.getCurrentTreeModel(). 146 getNodeByUniqueID(grandChildId, null, childNode); 147 if (node != null) 148 childNode = node; 149 } 150 151 IndexTreeNode parentNode = childNode.getParent(); 152 if (parentNode != null) { parentNode.setRefresh(true); 154 parentNode.openNode(ctx); 155 } 156 Util.setSelectedNode(childNode); 157 handlerCtx.setOutputValue(OBJECT_NAME, childNode.getAttribute(OBJECT_NAME, false)); 158 } 159 160 public void moveSelectedNodeToParent(RequestContext ctx, HandlerContext handlerCtx) { 162 IndexTreeNode selectedNode = Util.getSelectedNode(); 163 IndexTreeNode parent = selectedNode.getParent(); 164 Util.setSelectedNode(parent); 165 if (parent != null) 166 handlerCtx.setOutputValue(OBJECT_NAME, parent.getAttribute(OBJECT_NAME, false)); 167 else 168 handlerCtx.setOutputValue(OBJECT_NAME, null); 170 } 171 172 public void initializeCurrentNode(RequestContext ctx, HandlerContext handlerCtx) { 177 IndexTreeModel model = Util.getCurrentTreeModel(); 178 IndexTreeNode root = model.getRoot(); 179 if (root != null) { 180 model.setCurrentNode(root); 181 Util.setSelectedNode(root); 182 } 183 } 184 185 192 public void syncTreeView(RequestContext ctx, HandlerContext handlerCtx) { 193 Object [] keys = (Object [])handlerCtx.getInputValue("keys"); 194 if (keys == null) 195 return; 196 197 IndexTreeNode node = Util.getSelectedNode(); 198 if (node == null) 199 return; 200 201 if (node.getChildren().size() != keys.length) { 202 ctx.getRequest().setAttribute("refreshTree", new Boolean ("true")); 203 node.setRefresh(true); 204 } 205 } 206 207 public static final String VALUE = "value"; 208 public static final String OBJECT_NAME = "objectName"; 209 } 210 | Popular Tags |