| 1 4 package org.oddjob.webapp.model; 5 6 import java.util.ArrayList ; 7 import java.util.List ; 8 9 import org.oddjob.Structural; 10 import org.oddjob.monitor.model.ExplorerContext; 11 import org.oddjob.monitor.model.ExplorerModel; 12 import org.oddjob.structural.StructuralEvent; 13 import org.oddjob.structural.StructuralListener; 14 15 20 class TreeNode 21 implements StructuralListener { 22 23 24 private static int lastRefId = 0; 25 26 27 private final String refId; 28 29 30 private final Object node; 31 32 33 private final List children = new ArrayList (); 34 35 36 private final JobInfoLookup lookup; 37 38 private final ExplorerContext explorerContext; 39 40 46 TreeNode(ExplorerModel explorerModel, JobInfoLookup lookup) { 47 this.node = explorerModel.getRoot(); 48 this.lookup = lookup; 49 synchronized (TreeNode.class) { 50 this.refId = Integer.toString(lastRefId++); 51 } 52 explorerContext = new ExplorerContext(explorerModel); 53 } 54 55 61 TreeNode(TreeNode parent, Object node) { 62 this.node = node; 63 this.lookup = parent.lookup; 64 synchronized (TreeNode.class) { 65 this.refId = Integer.toString(lastRefId++); 66 } 67 explorerContext = new ExplorerContext(node, parent.explorerContext); 68 } 69 70 75 Object getComponent() { 76 return node; 77 } 78 79 84 String [] getChildRefIds() { 85 return (String []) this.children.toArray(new String [0]); 86 } 87 88 93 String getRefId() { 94 return refId; 95 } 96 97 102 String getNodeName() { 103 return node.toString(); 104 } 105 106 110 public void childAdded(StructuralEvent event) { 111 112 Object child = event.getChild(); 113 int index = event.getIndex(); 114 TreeNode childNode = new TreeNode(this, child); 115 if (child instanceof Structural) { 116 ((Structural) child).addStructuralListener(childNode); 117 } 118 119 synchronized (children) { 120 children.add(index, childNode.refId); 121 } 122 lookup.addChild(childNode); 123 } 124 125 129 public void childRemoved(StructuralEvent event) { 130 int index = event.getIndex(); 131 String childRefId = null; 132 synchronized (children) { 133 childRefId = (String ) children.remove(index); 134 } 135 136 lookup.removeChild(childRefId); 137 } 138 139 142 public ExplorerContext getExplorerContext() { 143 return explorerContext; 144 } 145 146 } | Popular Tags |