1 23 24 package com.sun.enterprise.tools.admingui.tree; 25 26 import java.io.*; 27 import java.lang.reflect.*; 28 import java.util.*; 29 import javax.servlet.*; 30 import javax.servlet.http.*; 31 import javax.management.ObjectName ; 32 33 import com.iplanet.jato.*; 34 import com.iplanet.jato.model.*; 35 import com.iplanet.jato.util.*; 36 import com.iplanet.jato.view.*; 37 import com.iplanet.jato.view.event.*; 38 import com.iplanet.jato.view.html.*; 39 40 import com.sun.enterprise.tools.admingui.util.Util; 41 import com.sun.enterprise.tools.admingui.util.MBeanUtil; 42 import com.sun.enterprise.tools.admingui.handlers.TargetHandlers; 43 import com.sun.enterprise.tools.guiframework.exception.FrameworkException; 44 45 46 public class IndexTreeView extends RequestHandlingTreeViewBase { 47 public static final String CHILD_NAME = "name"; 48 public static final String CHILD_SHOW_ROOT = "root"; 49 public static final String CHILD_SHOW_LEAF = "showLeaf"; 50 public static final String CHILD_SHOW_CONTAINER = "showContainer"; 51 52 public static final String CHILD_SHOW_ROOT_I = "Iroot"; 53 public static final String CHILD_SHOW_LEAF_I = "IshowLeaf"; 54 public static final String CHILD_SHOW_CONTANER_I = "IshowContainer"; 55 56 public static final String CHILD_HANDLE_IMAGE = "Handle"; 57 58 private NewTagsText newTags = null; 59 60 public IndexTreeView(View parent, String name) { 61 super(parent, name, Util.getCurrentTreeModel().getStateDataName()); 63 64 setPrimaryModel(Util.getCurrentTreeModel()); 65 registerChildren(); 66 } 67 68 protected IndexTreeModel getIndexTreeModel() { 69 return (IndexTreeModel)getPrimaryModel(); 70 } 71 72 protected void registerChildren() { 73 registerChild(CHILD_NAME, StaticTextField.class); 74 registerChild(CHILD_SHOW_ROOT, HREF.class); 75 registerChild(CHILD_SHOW_LEAF, HREF.class); 76 registerChild(CHILD_SHOW_CONTAINER, HREF.class); 77 78 registerChild(CHILD_SHOW_ROOT_I, ImageField.class); 79 registerChild(CHILD_SHOW_LEAF_I, ImageField.class); 80 registerChild(CHILD_SHOW_CONTANER_I,ImageField.class); 81 registerChild(CHILD_HANDLE_IMAGE, ImageField.class); 82 } 83 84 protected View createChild(String name) { 85 if (name.equals(CHILD_NAME)) { 86 StaticTextField child = new StaticTextField(this, getIndexTreeModel(), CHILD_NAME, 87 IndexTreeModel.FIELD_NAME, "", null); 88 return child; 89 } 90 else if (name.equals(CHILD_SHOW_ROOT) || 91 name.equals(CHILD_SHOW_LEAF) || 92 name.equals(CHILD_SHOW_CONTAINER)) { 93 return new HREF(this, name, null); 94 } 95 else if (name.equals(CHILD_SHOW_ROOT_I) || 96 name.equals(CHILD_HANDLE_IMAGE) || 97 name.equals(CHILD_SHOW_LEAF_I) || 98 name.equals(CHILD_SHOW_CONTANER_I)) { 99 return new ImageField(this, name, null); 100 } 101 else 102 return null; 103 } 104 105 private static Object osync = new Object (); 107 class NewTagsText { 109 public final String beginTD1 = "<td align=\"left\" valign=\"center\" width=\"24\" nowrap=\"nowrap\">"; 110 public final String beginTD2 = "<td align=\"left\" valign=\"center\" nowrap=\"nowrap\">"; 111 public final String endTD = "</td>\n"; 112 public final String restartImg = "<img SRC=\"../images/restartServer.gif\" alt=\"restart\" border=\"0\"/>"; 113 public final String hrefExtras = "title=\"@@@@\" " + 114 "onmouseover=\"window.status='@@@@'; return true\" " + 115 "onmouseout=\"window.status=''; return true\" " + 116 "onkeypress=\"javascript: this.onClick();\" " + 117 "onblur=\"window.status=''; return true\" " + 118 "onfocus=\"window.status='@@@@'; return true\" "; 119 120 private String imgTag; 121 private String hrefTag; 122 private Stack sibs; 123 public boolean rootNode; 124 125 public NewTagsText() { 126 reset(); 127 } 128 private void reset() { 129 imgTag = null; 130 hrefTag = null; 131 sibs = null; 132 rootNode = false; 133 } 134 public boolean hasNextSibling() { 135 if (sibs == null) { 136 synchronized (osync) { 137 sibs = new Stack(); 141 IndexTreeModel model = (IndexTreeModel)getPrimaryModel(); 142 IndexTreeNode node = (IndexTreeNode)(model.getCurrentNode()); 143 int level = ((IndexTreeModel)getPrimaryModel()).getNodeLevel(); 144 while (node != null) { 146 if (level > 1 && node.getParent() == null) { 148 break; 151 } 152 Boolean bool = new Boolean (node.getNextSibling() != null); 153 155 sibs.push(bool); 158 sibs.push(bool); 159 node = node.getParent(); 160 } 161 } 162 } 163 if (sibs.empty()) { 164 if (Util.isLoggableFINE()) { 166 Util.logFINE("IndexTreeView.hasNextSibling: Next Sibling Stack is Empty!", null); 167 } 168 return false; 169 } 170 Boolean answer = (Boolean )sibs.pop(); 171 return answer.booleanValue(); 172 } 173 public void setImgTag(String s) { 174 imgTag = s; 175 } 176 public void setHrefTag(String s) { 177 hrefTag = s; 178 } 179 private String addHref(String text, String hrefTag) { 180 if (hrefTag == null) 181 return text; 182 int i = hrefTag.indexOf('>'); 183 if (i<0) 184 return text; 185 return hrefTag.substring(0, i+1)+"\n"+text+"</a>"; 186 } 187 188 public String toString() { 189 String id = ((IndexTreeModel)getPrimaryModel()).getNodeHID(); 191 boolean expanded = getStateData().isNodeExpanded(getPrimaryModel().getNodeID()); 192 String icon = ((IndexTreeModel)getPrimaryModel()).getIconName(expanded); 193 194 IndexTreeNode node = ((IndexTreeNode)((IndexTreeModel)getPrimaryModel()).getCurrentNode()); 195 196 if (imgTag == null && hrefTag == null) 198 return ""; 199 if (imgTag != null && hrefTag == null) 200 return imgTag; 201 if (imgTag == null && hrefTag != null) 202 return hrefTag; 203 204 String status = ""; 206 String showStatus = (String ) node.getAttribute("showStatus", false); 207 try { 208 if (showStatus != null && showStatus.equalsIgnoreCase("true")) { 209 String objName = (String ) node.getAttribute("objectName", false); 210 status = " "+TargetHandlers.getStatusIconHtml(new ObjectName (objName)); 211 } 212 } catch (Exception ex) { 213 } 215 216 hrefTag = hrefTag.replaceAll("this", id); 218 219 String displayName = (String ) 221 node.getAttribute(IndexTreeModel.FIELD_DISPLAYNAME, false); 222 if (displayName == null) { 223 displayName = node.getName(); 224 } 225 226 String adminServerName = (String ) node.getAttribute("adminServerName", false); 228 if (adminServerName != null && displayName.equalsIgnoreCase(adminServerName)) { 229 displayName += " (" + Util.getMessage("tree.adminServer") + ")"; 230 String asIcon = Util.getMessage("tree.adminServerImage"); if (asIcon != null && asIcon.length() > 0) 232 icon = asIcon; 233 } 234 String adminServerConfigName = (String ) node.getAttribute("adminServerConfigName", false); 235 if (adminServerConfigName != null && displayName.equalsIgnoreCase("server-config")) { 236 displayName += " (" + Util.getMessage("tree.adminServerConfig") + ")"; 237 String asIcon = Util.getMessage("tree.adminServerConfigImage"); 238 if (asIcon != null && asIcon.length() > 0) 239 icon = asIcon; 240 } 241 if (displayName.equals(node.getName()) == false) { hrefTag = addHref(displayName, hrefTag); 243 } 244 245 hrefTag = Util.addHtmlProp(hrefTag, hrefExtras.replaceAll("@@@@", displayName)); 246 String hrefImageTag = hrefTag; 247 248 String newImgTag = Util.addHtmlProp(Util.removeHtmlProp(imgTag, "name"), ("name=\"i" + id + "\"")); if (rootNode) { 251 Object obj = RequestManager.getRequestContext() 252 .getRequest().getAttribute("restartRequired"); 253 boolean replaceIcon = false; 254 if (obj != null) { 255 if (obj instanceof Boolean ) { 256 replaceIcon = ((Boolean )obj).booleanValue(); 257 } else if (obj instanceof String ) { 258 replaceIcon = "true".equalsIgnoreCase((String )obj); 259 } 260 } 261 if (replaceIcon) { 262 String rrIcon = Util.getMessage("icon.InstanceRestartRequired"); 263 if (rrIcon != null && rrIcon.equals("")==false) 264 icon = rrIcon; 265 266 String rrText = Util.getMessage("masthead.restartRequired"); 267 hrefImageTag = Util.addHtmlProp(Util.removeHtmlProp(hrefTag, "title"), ("title=\"" + rrText + "\"")); 268 hrefImageTag = Util.addHtmlProp(Util.removeHtmlProp(hrefImageTag, "href"), ("href=\"../admingui/restart\"")); 269 } 270 } 271 newImgTag = Util.addHtmlProp(Util.removeHtmlProp(newImgTag, "src"), "src=\"../images/"+icon+"\""); 272 273 String newTag = beginTD1 + addHref(newImgTag, hrefImageTag) + endTD; 275 276 newTag += beginTD2 + Util.addHtmlProp(hrefTag, "id=\"a"+id+"\"") + status + endTD; 278 279 reset(); return newTag.trim(); 281 } 282 } 283 284 public TreeViewStateData getStateData() { 285 String dataName = Util.getCurrentTreeModel().getStateDataName(); 287 if (getStateDataLookupName().equals(dataName) == false) { 288 setStateDataLookupName(dataName); 289 TreeViewStateData data = (TreeViewStateData) 290 getRequestContext().getRequest().getSession().getAttribute(dataName); 291 292 if (data == null) 293 data = new SimpleTreeViewStateData(new HashMap()); 294 295 super.setStateData(data); 296 } 297 return super.getStateData(); 298 } 299 300 public void beginDisplay(DisplayEvent event) throws ModelControlException { 301 IndexTreeModel model = Util.getCurrentTreeModel(); 302 setPrimaryModel(model); 303 304 if (getPrimaryModel()==null) 307 throw new ModelControlException("Primary model is null"); 308 309 super.beginDisplay(event); 310 311 model.beforeRoot(); 312 model.nextNode(); 314 getStateData().setNodeExpanded(model.getNodeID(), true); 315 316 IndexTreeNode root = model.getRoot(); 317 String count = (String )root.getAttribute("kidsToOpen"); 318 if (count != null) { 319 int max = new Integer (count).intValue(); 320 root.setAttribute("kidsToOpen", null); 321 Iterator it = root.getChildren().iterator(); 322 int i = 0; 323 while (it.hasNext()) { 325 if (i >= max) break; 326 getStateData().setNodeExpanded(((IndexTreeNode)it.next()).getPath(), true); 327 i++; 328 } 329 } 330 newTags = new NewTagsText(); 331 } 332 333 public String endIrootDisplay(ChildContentDisplayEvent event) { 336 String content = event.getContent(); 337 newTags.setImgTag(content); 338 return ""; 339 } 340 public String endRootDisplay(ChildContentDisplayEvent event) { 341 String content = event.getContent(); 342 newTags.setHrefTag(content); 343 newTags.rootNode = true; 344 String newContent = newTags.toString(); 345 return newContent; 346 } 347 public String endIshowLeafDisplay(ChildContentDisplayEvent event) { 348 String content = event.getContent(); 349 newTags.setImgTag(content); 350 return ""; 351 } 352 public String endShowLeafDisplay(ChildContentDisplayEvent event) { 353 String content = event.getContent(); 354 newTags.setHrefTag(content); 355 String newContent = newTags.toString(); 356 return newContent; 357 } 358 public String endIshowContainerDisplay(ChildContentDisplayEvent event) { 359 String content = event.getContent(); 360 newTags.setImgTag(content); 361 return ""; 362 } 363 public String endShowContainerDisplay(ChildContentDisplayEvent event) { 364 String content = event.getContent(); 365 newTags.setHrefTag(content); 366 String newContent = newTags.toString(); 367 return newContent; 368 } 369 370 public String endGetIdDisplay(ChildContentDisplayEvent event) { 372 String id = ((IndexTreeModel)getPrimaryModel()).getNodeHID(); 373 return id; 374 } 375 376 public String endTableRowDisplay(ChildContentDisplayEvent event) { 377 String tr = "<tr "; 378 IndexTreeNode node = ((IndexTreeNode)((IndexTreeModel)getPrimaryModel()).getCurrentNode()); 379 380 if (node.getType().equalsIgnoreCase(IndexTreeModel.ROOT)) { 381 String rootClass = (String ) node.getAttribute("rootClass"); 382 if (rootClass == null) 383 rootClass = "TreRotRow"; tr += "height=\"30\" class=\""+rootClass+"\" id=\"r" + node.getHighlightID() + "\">"; 387 } else { 388 tr += "id=\"c" + node.getHighlightID() + "\">"; 389 } 390 return tr; 391 } 392 393 public String endAddTdDisplay(ChildContentDisplayEvent event) { 397 String content = event.getContent(); 398 return newTags.beginTD2 + content.trim() + newTags.endTD; 399 } 400 401 402 public boolean beginHasNextSiblingDisplay(ChildDisplayEvent event) { 403 return newTags.hasNextSibling(); 404 } 405 public boolean beginHasNoNextSiblingDisplay(ChildDisplayEvent event) { 406 return (newTags.hasNextSibling() == false); 407 } 408 409 public boolean beginHasContainerKidsDisplay(ChildDisplayEvent event) { 410 IndexTreeNode node = getIndexTreeModel().getNode(getPrimaryModel().getNodeID()); 411 return node.getChildren().size() > 0; 412 } 413 public boolean beginHasNoContainerKidsDisplay(ChildDisplayEvent event) { 414 return ! beginHasContainerKidsDisplay(event); 415 } 416 417 public boolean beginShowContainerDisplay(ChildDisplayEvent event) { 418 HREF HREF=(HREF)getDisplayField(CHILD_SHOW_CONTAINER); 419 href.setValue(getIndexTreeModel().getValue(IndexTreeModel.FIELD_ID)); 420 421 IndexTreeNode node = getIndexTreeModel().getNode(getPrimaryModel().getNodeID()); 422 node.setIsExpanded(getStateData().isNodeExpanded(getPrimaryModel().getNodeID())); 423 return true; 424 } 425 426 public boolean beginRootDisplay(ChildDisplayEvent event) { 427 HREF HREF=(HREF)getDisplayField(CHILD_SHOW_ROOT); 428 href.setValue(getIndexTreeModel().getValue(IndexTreeModel.FIELD_ID)); 429 430 IndexTreeNode node = getIndexTreeModel().getNode(getPrimaryModel().getNodeID()); 431 node.setIsExpanded(getStateData().isNodeExpanded(getPrimaryModel().getNodeID())); 432 return true; 433 } 434 435 public boolean beginShowLeafDisplay(ChildDisplayEvent event) { 436 HREF HREF=(HREF)getDisplayField(CHILD_SHOW_LEAF); 438 href.setValue(getIndexTreeModel().getValue(IndexTreeModel.FIELD_ID)); 439 440 IndexTreeNode node = getIndexTreeModel().getNode(getPrimaryModel().getNodeID()); 441 node.setIsExpanded(getStateData().isNodeExpanded(getPrimaryModel().getNodeID())); 442 return true; 443 } 444 445 private void handleNode(String nodeID, RequestInvocationEvent event) 446 throws ModelControlException, ClassNotFoundException , ServletException, IOException, NodeNotFoundException { 447 IndexTreeNode selectedNode = getIndexTreeModel().getNode(nodeID); 448 selectedNode.handleSelection(getRequestContext()); 449 } 450 451 public void handleShowLeafRequest(RequestInvocationEvent event) 452 throws ModelControlException, ClassNotFoundException , ServletException, IOException, NodeNotFoundException { 453 handleNode((String )getDisplayFieldValue(CHILD_SHOW_LEAF), event); 454 } 455 456 public void handleRootRequest(RequestInvocationEvent event) 457 throws ModelControlException, ClassNotFoundException , ServletException, IOException, NodeNotFoundException { 458 handleNode((String )getDisplayFieldValue(CHILD_SHOW_ROOT), event); 459 } 460 461 public void handleShowContainerRequest(RequestInvocationEvent event) 462 throws ModelControlException, ClassNotFoundException , ServletException, IOException, NodeNotFoundException { 463 handleNode((String )getDisplayFieldValue(CHILD_SHOW_CONTAINER), event); 464 } 465 } 466 | Popular Tags |