1 19 20 package org.netbeans.modules.ant.debugger.breakpoints; 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.DebuggerEngine; 27 import org.netbeans.api.debugger.DebuggerManager; 28 import org.netbeans.modules.ant.debugger.AntDebugger; 29 import org.netbeans.modules.ant.debugger.Utils; 30 import org.netbeans.spi.debugger.ContextProvider; 31 import org.netbeans.spi.viewmodel.ModelEvent; 32 import org.netbeans.spi.viewmodel.NodeActionsProvider; 33 import org.netbeans.spi.viewmodel.NodeModel; 34 import org.netbeans.spi.viewmodel.TableModel; 35 import org.netbeans.spi.viewmodel.TreeModel; 36 import org.netbeans.spi.viewmodel.ModelListener; 37 import org.netbeans.spi.viewmodel.UnknownTypeException; 38 import org.netbeans.spi.debugger.ui.Constants; 39 import org.openide.filesystems.FileObject; 40 import org.openide.text.Annotatable; 41 42 import org.openide.text.Line; 43 44 48 public class BreakpointModel implements NodeModel, TableModel, Constants { 49 50 public static final String LINE_BREAKPOINT = 51 "org/netbeans/modules/debugger/resources/editor/Breakpoint"; 52 public static final String LINE_BREAKPOINT_PC = 53 "org/netbeans/modules/debugger/resources/editor/Breakpoint+PC"; 54 public static final String DISABLED_LINE_BREAKPOINT = 55 "org/netbeans/modules/debugger/resources/editor/DisabledBreakpoint"; 56 57 private Vector listeners = new Vector (); 58 59 60 62 71 public String getDisplayName (Object node) throws UnknownTypeException { 72 if (node instanceof AntBreakpoint) { 73 AntBreakpoint breakpoint = (AntBreakpoint) node; 74 FileObject fileObject = (FileObject) breakpoint.getLine (). 75 getLookup ().lookup (FileObject.class); 76 return fileObject.getNameExt () + ":" + 77 (breakpoint.getLine ().getLineNumber () + 1); 78 } 79 throw new UnknownTypeException (node); 80 } 81 82 91 public String getIconBase (Object node) throws UnknownTypeException { 92 if (node instanceof AntBreakpoint) { 93 AntBreakpoint breakpoint = (AntBreakpoint) node; 94 if (!((AntBreakpoint) node).isEnabled ()) 95 return DISABLED_LINE_BREAKPOINT; 96 AntDebugger debugger = getDebugger (); 97 if ( debugger != null && 98 Utils.contains ( 99 debugger.getCurrentLine (), 100 breakpoint.getLine () 101 ) 102 ) 103 return LINE_BREAKPOINT_PC; 104 return LINE_BREAKPOINT; 105 } 106 throw new UnknownTypeException (node); 107 } 108 109 118 public String getShortDescription (Object node) 119 throws UnknownTypeException { 120 if (node instanceof AntBreakpoint) { 121 AntBreakpoint breakpoint = (AntBreakpoint) node; 122 return breakpoint.getLine ().getDisplayName (); 123 } 124 throw new UnknownTypeException (node); 125 } 126 127 132 public void addModelListener (ModelListener l) { 133 listeners.add (l); 134 } 135 136 141 public void removeModelListener (ModelListener l) { 142 listeners.remove (l); 143 } 144 145 146 148 164 public Object getValueAt (Object node, String columnID) throws 165 UnknownTypeException { 166 if (node instanceof AntBreakpoint) { 167 if (columnID.equals (BREAKPOINT_ENABLED_COLUMN_ID)) 168 return Boolean.valueOf (((AntBreakpoint) node).isEnabled ()); 169 } 170 throw new UnknownTypeException (node); 171 } 172 173 186 public boolean isReadOnly (Object node, String columnID) throws 187 UnknownTypeException { 188 if (node instanceof AntBreakpoint) { 189 if (columnID.equals (BREAKPOINT_ENABLED_COLUMN_ID)) 190 return false; 191 } 192 throw new UnknownTypeException (node); 193 } 194 195 207 public void setValueAt (Object node, String columnID, Object value) 208 throws UnknownTypeException { 209 if (node instanceof AntBreakpoint) { 210 if (columnID.equals (BREAKPOINT_ENABLED_COLUMN_ID)) 211 if (((Boolean ) value).equals (Boolean.TRUE)) 212 ((AntBreakpoint) node).enable (); 213 else 214 ((AntBreakpoint) node).disable (); 215 } else 216 throw new UnknownTypeException (node); 217 } 218 219 220 222 public void fireChanges () { 223 Vector v = (Vector ) listeners.clone (); 224 int i, k = v.size (); 225 for (i = 0; i < k; i++) 226 ((ModelListener) v.get (i)).modelChanged ( 227 new ModelEvent.TreeChanged (this) 228 ); 229 } 230 231 private static AntDebugger getDebugger () { 232 DebuggerEngine engine = DebuggerManager.getDebuggerManager (). 233 getCurrentEngine (); 234 if (engine == null) return null; 235 return (AntDebugger) engine.lookupFirst (null, AntDebugger.class); 236 } 237 } 238 | Popular Tags |