KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.apache.tools.ant.module.api.support.TargetLister;
24 import org.apache.tools.ant.module.spi.TaskStructure;
25 import org.netbeans.spi.debugger.ContextProvider;
26 import org.netbeans.spi.viewmodel.ModelEvent;
27 import org.netbeans.spi.viewmodel.NodeModel;
28 import org.netbeans.spi.viewmodel.TableModel;
29 import org.netbeans.spi.viewmodel.TreeModel;
30 import org.netbeans.spi.viewmodel.ModelListener;
31 import org.netbeans.spi.viewmodel.UnknownTypeException;
32
33 /**
34  *
35  * @author Jan Jancura
36  */

37 public class VariablesModel implements TreeModel, NodeModel, TableModel {
38     
39     public static final String JavaDoc LOCAL =
40         "org/netbeans/modules/debugger/resources/localsView/LocalVariable";
41     
42     private AntDebugger debugger;
43     private Vector JavaDoc listeners = new Vector JavaDoc ();
44     
45     
46     public VariablesModel (ContextProvider contextProvider) {
47         debugger = (AntDebugger) contextProvider.lookupFirst
48             (null, AntDebugger.class);
49     }
50     
51     
52     // TreeModel implementation ................................................
53

54     /**
55      * Returns the root node of the tree or null, if the tree is empty.
56      *
57      * @return the root node of the tree or null
58      */

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

79     public Object JavaDoc[] getChildren (Object JavaDoc parent, int from, int to)
80         throws UnknownTypeException {
81         if (parent == ROOT)
82             return debugger.getVariables ();
83         throw new UnknownTypeException (parent);
84     }
85     
86     /**
87      * Returns true if node is leaf.
88      *
89      * @throws UnknownTypeException if this TreeModel implementation is not
90      * able to resolve dchildren for given node type
91      * @return true if node is leaf
92      */

93     public boolean isLeaf (Object JavaDoc node) throws UnknownTypeException {
94         if (node == ROOT)
95             return false;
96         if (node instanceof String JavaDoc)
97             return true;
98         throw new UnknownTypeException (node);
99     }
100     
101     /**
102      * Returns number of children for given node.
103      *
104      * @param node the parent node
105      * @throws NoInformationException if the set of children can not be
106      * resolved
107      * @throws ComputingException if the children resolving process
108      * is time consuming, and will be performed off-line
109      * @throws UnknownTypeException if this TreeModel implementation is not
110      * able to resolve children for given node type
111      *
112      * @return true if node is leaf
113      * @since 1.1
114      */

115     public int getChildrenCount (Object JavaDoc node) throws UnknownTypeException {
116         if (node == ROOT)
117             return debugger.getVariables ().length;
118         throw new UnknownTypeException (node);
119     }
120
121     /**
122      * Registers given listener.
123      *
124      * @param l the listener to add
125      */

126     public void addModelListener (ModelListener l) {
127         listeners.add (l);
128     }
129
130     /**
131      * Unregisters given listener.
132      *
133      * @param l the listener to remove
134      */

135     public void removeModelListener (ModelListener l) {
136         listeners.remove (l);
137     }
138     
139     
140     // NodeModel implementation ................................................
141

142     /**
143      * Returns display name for given node.
144      *
145      * @throws ComputingException if the display name resolving process
146      * is time consuming, and the value will be updated later
147      * @throws UnknownTypeException if this NodeModel implementation is not
148      * able to resolve display name for given node type
149      * @return display name for given node
150      */

151     public String JavaDoc getDisplayName (Object JavaDoc node) throws UnknownTypeException {
152         if (node instanceof String JavaDoc)
153             return (String JavaDoc) node;
154         throw new UnknownTypeException (node);
155     }
156     
157     /**
158      * Returns icon for given node.
159      *
160      * @throws ComputingException if the icon resolving process
161      * is time consuming, and the value will be updated later
162      * @throws UnknownTypeException if this NodeModel implementation is not
163      * able to resolve icon for given node type
164      * @return icon for given node
165      */

166     public String JavaDoc getIconBase (Object JavaDoc node) throws UnknownTypeException {
167         if (node instanceof String JavaDoc)
168             return LOCAL;
169         throw new UnknownTypeException (node);
170     }
171     
172     /**
173      * Returns tooltip for given node.
174      *
175      * @throws ComputingException if the tooltip resolving process
176      * is time consuming, and the value will be updated later
177      * @throws UnknownTypeException if this NodeModel implementation is not
178      * able to resolve tooltip for given node type
179      * @return tooltip for given node
180      */

181     public String JavaDoc getShortDescription (Object JavaDoc node)
182     throws UnknownTypeException {
183         if (node instanceof String JavaDoc)
184             return null;
185         throw new UnknownTypeException (node);
186     }
187     
188     
189     // TableModel implementation ...............................................
190

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

207     public Object JavaDoc getValueAt (Object JavaDoc node, String JavaDoc columnID) throws
208     UnknownTypeException {
209         if ( (node instanceof String JavaDoc) &&
210              (columnID.equals ("LocalsValue"))
211         ) return debugger.getVariableValue ((String JavaDoc) node);
212         throw new UnknownTypeException (node);
213     }
214     
215     /**
216      * Returns true if value displayed in column <code>columnID</code>
217      * and row <code>node</code> is read only. Column ID is defined in by
218      * {@link ColumnModel#getID}, and rows are defined by values returned from
219      * {@link TreeModel#getChildren}.
220      *
221      * @param node a object returned from {@link TreeModel#getChildren} for this row
222      * @param columnID a id of column defined by {@link ColumnModel#getID}
223      * @throws UnknownTypeException if there is no TableModel defined for given
224      * parameter type
225      *
226      * @return true if variable on given position is read only
227      */

228     public boolean isReadOnly (Object JavaDoc node, String JavaDoc columnID) throws
229     UnknownTypeException {
230         if ( (node instanceof String JavaDoc) &&
231              (columnID.equals ("LocalsValue"))
232         ) return true;
233         throw new UnknownTypeException (node);
234     }
235     
236     /**
237      * Changes a value displayed in column <code>columnID</code>
238      * and row <code>node</code>. Column ID is defined in by
239      * {@link ColumnModel#getID}, and rows are defined by values returned from
240      * {@link TreeModel#getChildren}.
241      *
242      * @param node a object returned from {@link TreeModel#getChildren} for this row
243      * @param columnID a id of column defined by {@link ColumnModel#getID}
244      * @param value a new value of variable on given position
245      * @throws UnknownTypeException if there is no TableModel defined for given
246      * parameter type
247      */

248     public void setValueAt (Object JavaDoc node, String JavaDoc columnID, Object JavaDoc value)
249     throws UnknownTypeException {
250         throw new UnknownTypeException (node);
251     }
252
253     
254     // other mothods ...........................................................
255

256     void fireChanges () {
257         Vector JavaDoc v = (Vector JavaDoc) listeners.clone ();
258         int i, k = v.size ();
259         for (i = 0; i < k; i++)
260             ((ModelListener) v.get (i)).modelChanged (
261                 new ModelEvent.TreeChanged (this)
262             );
263     }
264 }
265
Popular Tags