KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > ant > debugger > WatchesModel


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;
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.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 /**
42  *
43  * @author Jan Jancura
44  */

45 public class WatchesModel implements TreeModel, NodeModel, TableModel {
46
47     public static final String JavaDoc WATCH =
48     "org/netbeans/modules/debugger/resources/watchesView/Watch";
49
50     private AntDebugger debugger;
51     private Vector JavaDoc listeners = new Vector JavaDoc ();
52     
53     
54     public WatchesModel (ContextProvider contextProvider) {
55         debugger = (AntDebugger) contextProvider.lookupFirst
56             (null, AntDebugger.class);
57     }
58     
59     
60     // TreeModel implementation ................................................
61

62     /**
63      * Returns the root node of the tree or null, if the tree is empty.
64      *
65      * @return the root node of the tree or null
66      */

67     public Object JavaDoc getRoot () {
68         return ROOT;
69     }
70     
71     /**
72      * Returns children for given parent on given indexes.
73      *
74      * @param parent a parent of returned nodes
75      * @param from a start index
76      * @param to a end index
77      *
78      * @throws NoInformationException if the set of children can not be
79      * resolved
80      * @throws ComputingException if the children resolving process
81      * is time consuming, and will be performed off-line
82      * @throws UnknownTypeException if this TreeModel implementation is not
83      * able to resolve children for given node type
84      *
85      * @return children for given parent on given indexes
86      */

87     public Object JavaDoc[] getChildren (Object JavaDoc 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     /**
96      * Returns true if node is leaf.
97      *
98      * @throws UnknownTypeException if this TreeModel implementation is not
99      * able to resolve dchildren for given node type
100      * @return true if node is leaf
101      */

102     public boolean isLeaf (Object JavaDoc 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     /**
111      * Returns number of children for given node.
112      *
113      * @param node the parent node
114      * @throws NoInformationException if the set of children can not be
115      * resolved
116      * @throws ComputingException if the children resolving process
117      * is time consuming, and will be performed off-line
118      * @throws UnknownTypeException if this TreeModel implementation is not
119      * able to resolve children for given node type
120      *
121      * @return true if node is leaf
122      * @since 1.1
123      */

124     public int getChildrenCount (Object JavaDoc node) throws UnknownTypeException {
125         if (node == ROOT)
126             return DebuggerManager.getDebuggerManager ().getWatches ().length;
127         throw new UnknownTypeException (node);
128     }
129     
130     
131     // NodeModel implementation ................................................
132

133     /**
134      * Returns display name for given node.
135      *
136      * @throws ComputingException if the display name resolving process
137      * is time consuming, and the value will be updated later
138      * @throws UnknownTypeException if this NodeModel implementation is not
139      * able to resolve display name for given node type
140      * @return display name for given node
141      */

142     public String JavaDoc getDisplayName (Object JavaDoc node) throws UnknownTypeException {
143         if (node instanceof Watch)
144             return ((Watch) node).getExpression ();
145         throw new UnknownTypeException (node);
146     }
147     
148     /**
149      * Returns icon for given node.
150      *
151      * @throws ComputingException if the icon resolving process
152      * is time consuming, and the value will be updated later
153      * @throws UnknownTypeException if this NodeModel implementation is not
154      * able to resolve icon for given node type
155      * @return icon for given node
156      */

157     public String JavaDoc getIconBase (Object JavaDoc node) throws UnknownTypeException {
158         if (node instanceof Watch)
159             return WATCH;
160         throw new UnknownTypeException (node);
161     }
162     
163     /**
164      * Returns tooltip for given node.
165      *
166      * @throws ComputingException if the tooltip resolving process
167      * is time consuming, and the value will be updated later
168      * @throws UnknownTypeException if this NodeModel implementation is not
169      * able to resolve tooltip for given node type
170      * @return tooltip for given node
171      */

172     public String JavaDoc getShortDescription (Object JavaDoc node)
173     throws UnknownTypeException {
174         if (node instanceof Watch) {
175             String JavaDoc expression = ((Watch) node).getExpression ();
176             return debugger.getVariableValue (expression);
177         }
178         throw new UnknownTypeException (node);
179     }
180         
181      
182     // TableModel implementation ...............................................
183

184     /**
185      * Returns value to be displayed in column <code>columnID</code>
186      * and row identified by <code>node</code>. Column ID is defined in by
187      * {@link ColumnModel#getID}, and rows are defined by values returned from
188      * {@link org.netbeans.spi.viewmodel.TreeModel#getChildren}.
189      *
190      * @param node a object returned from
191      * {@link org.netbeans.spi.viewmodel.TreeModel#getChildren} for this row
192      * @param columnID a id of column defined by {@link ColumnModel#getID}
193      * @throws ComputingException if the value is not known yet and will
194      * be computed later
195      * @throws UnknownTypeException if there is no TableModel defined for given
196      * parameter type
197      *
198      * @return value of variable representing given position in tree table.
199      */

200     public Object JavaDoc getValueAt (Object JavaDoc node, String JavaDoc 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 JavaDoc 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     /**
218      * Returns true if value displayed in column <code>columnID</code>
219      * and row <code>node</code> is read only. Column ID is defined in by
220      * {@link ColumnModel#getID}, and rows are defined by values returned from
221      * {@link TreeModel#getChildren}.
222      *
223      * @param node a object returned from {@link TreeModel#getChildren} for this row
224      * @param columnID a id of column defined by {@link ColumnModel#getID}
225      * @throws UnknownTypeException if there is no TableModel defined for given
226      * parameter type
227      *
228      * @return true if variable on given position is read only
229      */

230     public boolean isReadOnly (Object JavaDoc node, String JavaDoc 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     /**
243      * Changes a value displayed in column <code>columnID</code>
244      * and row <code>node</code>. Column ID is defined in by
245      * {@link ColumnModel#getID}, and rows are defined by values returned from
246      * {@link TreeModel#getChildren}.
247      *
248      * @param node a object returned from {@link TreeModel#getChildren} for this row
249      * @param columnID a id of column defined by {@link ColumnModel#getID}
250      * @param value a new value of variable on given position
251      * @throws UnknownTypeException if there is no TableModel defined for given
252      * parameter type
253      */

254     public void setValueAt (Object JavaDoc node, String JavaDoc columnID, Object JavaDoc value)
255     throws UnknownTypeException {
256         throw new UnknownTypeException (node);
257     }
258         
259      
260     /**
261      * Registers given listener.
262      *
263      * @param l the listener to add
264      */

265     public void addModelListener (ModelListener l) {
266         listeners.add (l);
267     }
268
269     /**
270      * Unregisters given listener.
271      *
272      * @param l the listener to remove
273      */

274     public void removeModelListener (ModelListener l) {
275         listeners.remove (l);
276     }
277
278     
279     // other mothods ...........................................................
280

281     void fireChanges () {
282         Vector JavaDoc v = (Vector JavaDoc) 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