1 19 20 package org.netbeans.modules.ant.debugger; 21 22 import java.util.Vector ; 23 import org.apache.tools.ant.module.api.support.TargetLister; 24 import org.apache.tools.ant.module.spi.TaskStructure; 25 import org.netbeans.spi.debugger.ContextProvider; 26 import org.netbeans.spi.viewmodel.ModelEvent; 27 import org.netbeans.spi.viewmodel.NodeModel; 28 import org.netbeans.spi.viewmodel.TableModel; 29 import org.netbeans.spi.viewmodel.TreeModel; 30 import org.netbeans.spi.viewmodel.ModelListener; 31 import org.netbeans.spi.viewmodel.UnknownTypeException; 32 33 37 public class VariablesModel implements TreeModel, NodeModel, TableModel { 38 39 public static final String LOCAL = 40 "org/netbeans/modules/debugger/resources/localsView/LocalVariable"; 41 42 private AntDebugger debugger; 43 private Vector listeners = new Vector (); 44 45 46 public VariablesModel (ContextProvider contextProvider) { 47 debugger = (AntDebugger) contextProvider.lookupFirst 48 (null, AntDebugger.class); 49 } 50 51 52 54 59 public Object getRoot () { 60 return ROOT; 61 } 62 63 79 public Object [] getChildren (Object parent, int from, int to) 80 throws UnknownTypeException { 81 if (parent == ROOT) 82 return debugger.getVariables (); 83 throw new UnknownTypeException (parent); 84 } 85 86 93 public boolean isLeaf (Object node) throws UnknownTypeException { 94 if (node == ROOT) 95 return false; 96 if (node instanceof String ) 97 return true; 98 throw new UnknownTypeException (node); 99 } 100 101 115 public int getChildrenCount (Object node) throws UnknownTypeException { 116 if (node == ROOT) 117 return debugger.getVariables ().length; 118 throw new UnknownTypeException (node); 119 } 120 121 126 public void addModelListener (ModelListener l) { 127 listeners.add (l); 128 } 129 130 135 public void removeModelListener (ModelListener l) { 136 listeners.remove (l); 137 } 138 139 140 142 151 public String getDisplayName (Object node) throws UnknownTypeException { 152 if (node instanceof String ) 153 return (String ) node; 154 throw new UnknownTypeException (node); 155 } 156 157 166 public String getIconBase (Object node) throws UnknownTypeException { 167 if (node instanceof String ) 168 return LOCAL; 169 throw new UnknownTypeException (node); 170 } 171 172 181 public String getShortDescription (Object node) 182 throws UnknownTypeException { 183 if (node instanceof String ) 184 return null; 185 throw new UnknownTypeException (node); 186 } 187 188 189 191 207 public Object getValueAt (Object node, String columnID) throws 208 UnknownTypeException { 209 if ( (node instanceof String ) && 210 (columnID.equals ("LocalsValue")) 211 ) return debugger.getVariableValue ((String ) node); 212 throw new UnknownTypeException (node); 213 } 214 215 228 public boolean isReadOnly (Object node, String columnID) throws 229 UnknownTypeException { 230 if ( (node instanceof String ) && 231 (columnID.equals ("LocalsValue")) 232 ) return true; 233 throw new UnknownTypeException (node); 234 } 235 236 248 public void setValueAt (Object node, String columnID, Object value) 249 throws UnknownTypeException { 250 throw new UnknownTypeException (node); 251 } 252 253 254 256 void fireChanges () { 257 Vector v = (Vector ) listeners.clone (); 258 int i, k = v.size (); 259 for (i = 0; i < k; i++) 260 ((ModelListener) v.get (i)).modelChanged ( 261 new ModelEvent.TreeChanged (this) 262 ); 263 } 264 } 265 | Popular Tags |