1 19 20 package org.netbeans.modules.ant.debugger; 21 22 import java.util.Vector ; 23 import javax.swing.Action ; 24 25 import org.apache.tools.ant.module.api.support.TargetLister; 26 import org.netbeans.api.debugger.DebuggerManager; 27 import org.netbeans.api.debugger.Watch; 28 import org.netbeans.spi.debugger.ContextProvider; 29 import org.netbeans.spi.viewmodel.ModelEvent; 30 import org.netbeans.spi.viewmodel.NodeActionsProvider; 31 import org.netbeans.spi.viewmodel.NodeModel; 32 import org.netbeans.spi.viewmodel.TableModel; 33 import org.netbeans.spi.viewmodel.TreeModel; 34 import org.netbeans.spi.viewmodel.ModelListener; 35 import org.netbeans.spi.viewmodel.UnknownTypeException; 36 import org.netbeans.spi.debugger.ui.Constants; 37 import org.openide.text.Annotatable; 38 39 import org.openide.text.Line; 40 41 45 public class WatchesModel implements TreeModel, NodeModel, TableModel { 46 47 public static final String WATCH = 48 "org/netbeans/modules/debugger/resources/watchesView/Watch"; 49 50 private AntDebugger debugger; 51 private Vector listeners = new Vector (); 52 53 54 public WatchesModel (ContextProvider contextProvider) { 55 debugger = (AntDebugger) contextProvider.lookupFirst 56 (null, AntDebugger.class); 57 } 58 59 60 62 67 public Object getRoot () { 68 return ROOT; 69 } 70 71 87 public Object [] getChildren (Object parent, int from, int to) 88 throws UnknownTypeException { 89 if (parent == ROOT) { 90 return DebuggerManager.getDebuggerManager ().getWatches(); 91 } 92 throw new UnknownTypeException (parent); 93 } 94 95 102 public boolean isLeaf (Object node) throws UnknownTypeException { 103 if (node == ROOT) 104 return false; 105 if (node instanceof Watch) 106 return true; 107 throw new UnknownTypeException (node); 108 } 109 110 124 public int getChildrenCount (Object node) throws UnknownTypeException { 125 if (node == ROOT) 126 return DebuggerManager.getDebuggerManager ().getWatches ().length; 127 throw new UnknownTypeException (node); 128 } 129 130 131 133 142 public String getDisplayName (Object node) throws UnknownTypeException { 143 if (node instanceof Watch) 144 return ((Watch) node).getExpression (); 145 throw new UnknownTypeException (node); 146 } 147 148 157 public String getIconBase (Object node) throws UnknownTypeException { 158 if (node instanceof Watch) 159 return WATCH; 160 throw new UnknownTypeException (node); 161 } 162 163 172 public String getShortDescription (Object node) 173 throws UnknownTypeException { 174 if (node instanceof Watch) { 175 String expression = ((Watch) node).getExpression (); 176 return debugger.getVariableValue (expression); 177 } 178 throw new UnknownTypeException (node); 179 } 180 181 182 184 200 public Object getValueAt (Object node, String columnID) throws 201 UnknownTypeException { 202 if (columnID == Constants.WATCH_TO_STRING_COLUMN_ID || 203 columnID == Constants.WATCH_VALUE_COLUMN_ID 204 ) { 205 if (node instanceof Watch) { 206 String expression = ((Watch) node).getExpression (); 207 return debugger.getVariableValue (expression); 208 } 209 } 210 if (columnID == Constants.WATCH_TYPE_COLUMN_ID && 211 node instanceof Watch 212 ) 213 return ""; 214 throw new UnknownTypeException (node); 215 } 216 217 230 public boolean isReadOnly (Object node, String columnID) throws 231 UnknownTypeException { 232 if (columnID == Constants.WATCH_TO_STRING_COLUMN_ID || 233 columnID == Constants.WATCH_VALUE_COLUMN_ID || 234 columnID == Constants.WATCH_TYPE_COLUMN_ID 235 ) { 236 if (node instanceof Watch) 237 return true; 238 } 239 throw new UnknownTypeException (node); 240 } 241 242 254 public void setValueAt (Object node, String columnID, Object value) 255 throws UnknownTypeException { 256 throw new UnknownTypeException (node); 257 } 258 259 260 265 public void addModelListener (ModelListener l) { 266 listeners.add (l); 267 } 268 269 274 public void removeModelListener (ModelListener l) { 275 listeners.remove (l); 276 } 277 278 279 281 void fireChanges () { 282 Vector v = (Vector ) listeners.clone (); 283 int i, k = v.size (); 284 for (i = 0; i < k; i++) 285 ((ModelListener) v.get (i)).modelChanged ( 286 new ModelEvent.TreeChanged (this) 287 ); 288 } 289 290 } 291 | Popular Tags |