KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > debugger > breakpoints > BreakpointModel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.ant.debugger.breakpoints;
21
22 import java.util.Vector JavaDoc;
23 import javax.swing.Action JavaDoc;
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 /**
45  *
46  * @author Jan Jancura
47  */

48 public class BreakpointModel implements NodeModel, TableModel, Constants {
49     
50     public static final String JavaDoc LINE_BREAKPOINT =
51         "org/netbeans/modules/debugger/resources/editor/Breakpoint";
52     public static final String JavaDoc LINE_BREAKPOINT_PC =
53         "org/netbeans/modules/debugger/resources/editor/Breakpoint+PC";
54     public static final String JavaDoc DISABLED_LINE_BREAKPOINT =
55         "org/netbeans/modules/debugger/resources/editor/DisabledBreakpoint";
56     
57     private Vector JavaDoc listeners = new Vector JavaDoc ();
58     
59     
60     // NodeModel implementation ................................................
61

62     /**
63      * Returns display name for given node.
64      *
65      * @throws ComputingException if the display name resolving process
66      * is time consuming, and the value will be updated later
67      * @throws UnknownTypeException if this NodeModel implementation is not
68      * able to resolve display name for given node type
69      * @return display name for given node
70      */

71     public String JavaDoc getDisplayName (Object JavaDoc 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     /**
83      * Returns icon for given node.
84      *
85      * @throws ComputingException if the icon resolving process
86      * is time consuming, and the value will be updated later
87      * @throws UnknownTypeException if this NodeModel implementation is not
88      * able to resolve icon for given node type
89      * @return icon for given node
90      */

91     public String JavaDoc getIconBase (Object JavaDoc 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     /**
110      * Returns tooltip for given node.
111      *
112      * @throws ComputingException if the tooltip resolving process
113      * is time consuming, and the value will be updated later
114      * @throws UnknownTypeException if this NodeModel implementation is not
115      * able to resolve tooltip for given node type
116      * @return tooltip for given node
117      */

118     public String JavaDoc getShortDescription (Object JavaDoc 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     /**
128      * Registers given listener.
129      *
130      * @param l the listener to add
131      */

132     public void addModelListener (ModelListener l) {
133         listeners.add (l);
134     }
135
136     /**
137      * Unregisters given listener.
138      *
139      * @param l the listener to remove
140      */

141     public void removeModelListener (ModelListener l) {
142         listeners.remove (l);
143     }
144         
145      
146     // TableModel implementation ......................................
147

148     /**
149      * Returns value to be displayed in column <code>columnID</code>
150      * and row identified by <code>node</code>. Column ID is defined in by
151      * {@link ColumnModel#getID}, and rows are defined by values returned from
152      * {@link org.netbeans.spi.viewmodel.TreeModel#getChildren}.
153      *
154      * @param node a object returned from
155      * {@link org.netbeans.spi.viewmodel.TreeModel#getChildren} for this row
156      * @param columnID a id of column defined by {@link ColumnModel#getID}
157      * @throws ComputingException if the value is not known yet and will
158      * be computed later
159      * @throws UnknownTypeException if there is no TableModel defined for given
160      * parameter type
161      *
162      * @return value of variable representing given position in tree table.
163      */

164     public Object JavaDoc getValueAt (Object JavaDoc node, String JavaDoc 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     /**
174      * Returns true if value displayed in column <code>columnID</code>
175      * and row <code>node</code> is read only. Column ID is defined in by
176      * {@link ColumnModel#getID}, and rows are defined by values returned from
177      * {@link TreeModel#getChildren}.
178      *
179      * @param node a object returned from {@link TreeModel#getChildren} for this row
180      * @param columnID a id of column defined by {@link ColumnModel#getID}
181      * @throws UnknownTypeException if there is no TableModel defined for given
182      * parameter type
183      *
184      * @return true if variable on given position is read only
185      */

186     public boolean isReadOnly (Object JavaDoc node, String JavaDoc 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     /**
196      * Changes a value displayed in column <code>columnID</code>
197      * and row <code>node</code>. Column ID is defined in by
198      * {@link ColumnModel#getID}, and rows are defined by values returned from
199      * {@link TreeModel#getChildren}.
200      *
201      * @param node a object returned from {@link TreeModel#getChildren} for this row
202      * @param columnID a id of column defined by {@link ColumnModel#getID}
203      * @param value a new value of variable on given position
204      * @throws UnknownTypeException if there is no TableModel defined for given
205      * parameter type
206      */

207     public void setValueAt (Object JavaDoc node, String JavaDoc columnID, Object JavaDoc value)
208     throws UnknownTypeException {
209         if (node instanceof AntBreakpoint) {
210             if (columnID.equals (BREAKPOINT_ENABLED_COLUMN_ID))
211                 if (((Boolean JavaDoc) 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     // TableModel implementation ......................................
221

222     public void fireChanges () {
223         Vector JavaDoc v = (Vector JavaDoc) 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