1 22 package org.jboss.console.navtree; 23 24 25 26 import org.jboss.console.manager.interfaces.TreeInfo; 27 28 43 44 public class ConsoleTreeModel implements javax.swing.tree.TreeModel 45 { 46 47 49 51 protected TreeInfo tree = null; 52 protected RootWrapper root = null; 53 protected java.util.Vector treeModelListeners = new java.util.Vector (); 54 protected TreeContext context = null; 57 protected TreeReopenerMemory reopenerMemory = null; 58 59 protected javax.management.ObjectName targetPM = null; 60 61 63 65 public ConsoleTreeModel (TreeContext context) throws Exception 66 { 67 this.targetPM = new javax.management.ObjectName (context.getServiceJmxName()); 69 this.context = context; 71 73 this.tree = loadTree (); 74 this.root = new RootWrapper (this.tree); 75 } 76 77 public boolean refreshTree (boolean force) throws Exception 78 { 79 TreeInfo tmpTree = null; 80 81 if (!force && this.tree != null) 82 { 83 tmpTree = conditionalLoadTree (this.tree.getTreeVersion()); 86 } 87 else 88 { 89 tmpTree = loadTree (); 90 } 91 92 if (tmpTree != null) 93 { 94 RootWrapper oldRoot = this.root; 95 96 this.tree = tmpTree; 97 this.root = new RootWrapper (this.tree); 98 99 fireTreeStructureChanged (oldRoot); 100 return true; 101 } 102 else 103 { 104 return false; 105 } 106 } 107 108 public TreeInfo conditionalLoadTree (long version) throws Exception 109 { 110 return (TreeInfo)context.getRemoteMBeanInvoker ().invoke (targetPM, "getUpdateTreeForProfile", 111 new Object [] {"WEB", new Long (version)}, 112 new String [] {"java.lang.String", "long"}); 113 } 115 116 public TreeInfo loadTree () throws Exception 117 { 118 return (TreeInfo)context.getRemoteMBeanInvoker ().invoke (targetPM, "getTreeForProfile", 119 new Object [] {"WEB"}, 120 new String [] {"java.lang.String"}); 121 } 123 124 131 public void addTreeModelListener (javax.swing.event.TreeModelListener l) 132 { 133 treeModelListeners.addElement(l); 134 } 135 136 148 public Object getChild (Object parent, int index) 149 { 150 NodeWrapper n = (NodeWrapper)parent; 151 return n.getChild (index); 152 } 153 154 163 public int getChildCount (Object parent) 164 { 165 NodeWrapper n = (NodeWrapper)parent; 166 return n.getChildCount (); 167 } 168 169 179 public int getIndexOfChild (Object parent, Object child) 180 { 181 NodeWrapper n = (NodeWrapper)parent; 182 return n.getIndexOfChild (child); 183 } 184 185 191 public Object getRoot () 192 { 193 return this.root; 194 } 195 196 207 public boolean isLeaf (Object node) 208 { 209 NodeWrapper n = (NodeWrapper)node; 210 return n.isLeaf (); 211 } 212 213 220 public void removeTreeModelListener (javax.swing.event.TreeModelListener l) 221 { 222 treeModelListeners.removeElement(l); 223 } 224 225 234 public void valueForPathChanged (javax.swing.tree.TreePath path, Object newValue) 235 { 236 } 238 239 241 243 245 247 249 protected void fireTreeStructureChanged(RootWrapper oldRoot) { 250 int len = treeModelListeners.size(); 251 252 javax.swing.event.TreeModelEvent e = new javax.swing.event.TreeModelEvent (this, 253 new Object [] {oldRoot}); 254 for (int i = 0; i < len; i++) { 255 ((javax.swing.event.TreeModelListener )treeModelListeners.elementAt(i)). 256 treeStructureChanged(e); 257 } 258 } 259 260 264 265 267 269 } 270 | Popular Tags |