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.spi.debugger.ContextProvider; 27 import org.netbeans.spi.viewmodel.ModelEvent; 28 import org.netbeans.spi.viewmodel.NodeActionsProvider; 29 import org.netbeans.spi.viewmodel.NodeModel; 30 import org.netbeans.spi.viewmodel.TableModel; 31 import org.netbeans.spi.viewmodel.TreeModel; 32 import org.netbeans.spi.viewmodel.ModelListener; 33 import org.netbeans.spi.viewmodel.UnknownTypeException; 34 import org.netbeans.spi.debugger.ui.Constants; 35 import org.openide.text.Annotatable; 36 37 import org.openide.text.Line; 38 39 43 public class CallStackModel implements TreeModel, NodeModel, 44 NodeActionsProvider, TableModel { 45 46 public static final String CALL_STACK = 47 "org/netbeans/modules/debugger/resources/callStackView/NonCurrentFrame"; 48 public static final String CURRENT_CALL_STACK = 49 "org/netbeans/modules/debugger/resources/callStackView/CurrentFrame"; 50 51 private AntDebugger debugger; 52 private Vector listeners = new Vector (); 53 54 55 public CallStackModel (ContextProvider contextProvider) { 56 debugger = (AntDebugger) contextProvider.lookupFirst 57 (null, AntDebugger.class); 58 } 59 60 61 63 68 public Object getRoot () { 69 return ROOT; 70 } 71 72 88 public Object [] getChildren (Object parent, int from, int to) 89 throws UnknownTypeException { 90 if (parent == ROOT) 91 return debugger.getCallStack (); 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 TargetLister.Target) 106 return true; 107 if (node instanceof Task) 108 return true; 109 throw new UnknownTypeException (node); 110 } 111 112 126 public int getChildrenCount (Object node) throws UnknownTypeException { 127 if (node == ROOT) 128 return debugger.getCallStack ().length; 129 throw new UnknownTypeException (node); 130 } 131 132 137 public void addModelListener (ModelListener l) { 138 listeners.add (l); 139 } 140 141 146 public void removeModelListener (ModelListener l) { 147 listeners.remove (l); 148 } 149 150 151 153 162 public String getDisplayName (Object node) throws UnknownTypeException { 163 if (node instanceof TargetLister.Target) 164 return ((TargetLister.Target) node).getName (); 165 if (node instanceof Task) 166 return ((Task) node).getTaskStructure ().getName (); 167 if (node == ROOT) { 168 return ROOT; 169 } 170 throw new UnknownTypeException (node); 171 } 172 173 182 public String getIconBase (Object node) throws UnknownTypeException { 183 if (node instanceof TargetLister.Target) 184 return CALL_STACK; 185 if (node instanceof Task) 186 return CURRENT_CALL_STACK; 187 if (node == ROOT) { 188 return null; 189 } 190 throw new UnknownTypeException (node); 191 } 192 193 202 public String getShortDescription (Object node) 203 throws UnknownTypeException { 204 if (node instanceof TargetLister.Target) 205 return null; 206 if (node instanceof Task) 207 return null; 208 throw new UnknownTypeException (node); 209 } 210 211 212 214 221 public void performDefaultAction (Object node) 222 throws UnknownTypeException { 223 if (node instanceof TargetLister.Target) { 224 Utils.showLine (Utils.getLine ((TargetLister.Target) node, null)); 225 return; 226 } 227 if (node instanceof Task) { 228 Utils.showLine (((Task) node).getLine ()); 229 return; 230 } 231 throw new UnknownTypeException (node); 232 } 233 234 241 public Action [] getActions (Object node) 242 throws UnknownTypeException { 243 return new Action [] {}; 244 } 245 246 247 249 265 public Object getValueAt (Object node, String columnID) throws 266 UnknownTypeException { 267 if (columnID == Constants.CALL_STACK_FRAME_LOCATION_COLUMN_ID) { 268 if (node instanceof TargetLister.Target) { 269 TargetLister.Target target = (TargetLister.Target) node; 270 return target.getScript ().getFile ().getName () + ":" + 271 Utils.getLineNumber ( 272 Utils.getLine ((TargetLister.Target) node, null) 273 ); 274 } 275 if (node instanceof Task) { 276 Task task = (Task) node; 277 return task.getFile ().getName () + ":" + 278 Utils.getLineNumber (task.getLine ()) + 1; 279 } 280 } 281 throw new UnknownTypeException (node); 282 } 283 284 297 public boolean isReadOnly (Object node, String columnID) throws 298 UnknownTypeException { 299 if (columnID == Constants.CALL_STACK_FRAME_LOCATION_COLUMN_ID) { 300 if (node instanceof TargetLister.Target) { 301 return true; 302 } 303 if (node instanceof Task) { 304 return true; 305 } 306 } 307 throw new UnknownTypeException (node); 308 } 309 310 322 public void setValueAt (Object node, String columnID, Object value) 323 throws UnknownTypeException { 324 throw new UnknownTypeException (node); 325 } 326 327 328 330 void fireChanges () { 331 Vector v = (Vector ) listeners.clone (); 332 int i, k = v.size (); 333 for (i = 0; i < k; i++) 334 ((ModelListener) v.get (i)).modelChanged ( 335 new ModelEvent.TreeChanged (this) 336 ); 337 } 338 } 339 | Popular Tags |