KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > scripting > php > dbginterface > models > CallStackModel


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-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.scripting.php.dbginterface.models;
21
22 import java.util.List JavaDoc;
23 import javax.swing.Action JavaDoc;
24 import org.netbeans.modules.scripting.php.dbginterface.DbgDebuggerImpl;
25 import org.netbeans.modules.scripting.php.dbginterface.ModelSupport;
26 import org.netbeans.spi.debugger.ContextProvider;
27 import org.netbeans.spi.viewmodel.NodeActionsProvider;
28 import org.netbeans.spi.viewmodel.NodeModel;
29 import org.netbeans.spi.viewmodel.TableModel;
30 import org.netbeans.spi.viewmodel.TreeModel;
31 import org.netbeans.spi.viewmodel.UnknownTypeException;
32 import org.netbeans.spi.debugger.ui.Constants;
33 import org.openide.text.Line;
34 import org.openide.util.Mutex;
35
36 /**
37  *
38  * @author Jan Jancura
39  */

40 public class CallStackModel extends ModelSupport
41         implements TreeModel, NodeModel, NodeActionsProvider, TableModel {
42
43     private static final boolean DEBUG = false;
44
45     public static final String JavaDoc CALL_STACK =
46         "org/netbeans/modules/debugger/resources/callStackView/NonCurrentFrame";
47     public static final String JavaDoc CURRENT_CALL_STACK =
48         "org/netbeans/modules/debugger/resources/callStackView/CurrentFrame";
49
50     public CallStackModel(final ContextProvider contextProvider) {
51         this.contextProvider = contextProvider;
52     }
53
54     private final ContextProvider contextProvider;
55
56     private ContextProvider getContextProvider() {
57         return contextProvider;
58     }
59
60     private DbgDebuggerImpl getDebugger() {
61         return (DbgDebuggerImpl)contextProvider.lookupFirst(
62                 null, DbgDebuggerImpl.class);
63     }
64
65     // ------------------------------------------------------------------------
66
// TreeModel implementation
67
// ------------------------------------------------------------------------
68
public Object JavaDoc getRoot() {
69         return ROOT;
70     }
71
72     public Object JavaDoc[] getChildren(Object JavaDoc parent, int from, int to) throws UnknownTypeException {
73         if (parent == ROOT) {
74             DbgDebuggerImpl.Context context = getDebugger().getCurrentScriptContext();
75             
76             if (context != null) {
77                 List JavaDoc<DebugFrame> callstack = context.getCallStack();
78                 
79                 if (callstack != null) {
80                     return callstack.toArray(new DebugFrame[callstack.size()]);
81                 }
82             }
83
84             return new DebugFrame[0];
85         }
86         
87         throw new UnknownTypeException(parent);
88     }
89
90     public boolean isLeaf(Object JavaDoc node) throws UnknownTypeException {
91         if (node == ROOT) {
92             return false;
93         }
94         else if (node instanceof DebugFrame) {
95             return true;
96         }
97         
98         throw new UnknownTypeException(node);
99     }
100
101     public int getChildrenCount(Object JavaDoc node) throws UnknownTypeException {
102         if (node == ROOT) {
103             DbgDebuggerImpl.Context context = getDebugger().getCurrentScriptContext();
104             
105             if (context != null && context.getCallStack() != null) {
106                 return context.getCallStack().size();
107             }
108             else {
109                 return 0;
110             }
111         }
112         
113         throw new UnknownTypeException(node);
114     }
115
116     // ------------------------------------------------------------------------
117
// NodeModel implementation
118
// ------------------------------------------------------------------------
119
public String JavaDoc getDisplayName(Object JavaDoc node) throws UnknownTypeException {
120         if (node instanceof DebugFrame) {
121             DebugFrame frame = (DebugFrame)node;
122             
123             System.err.println("mw CallStackModel.getDisplayName(" + frame + ")");
124             
125             return frame.getDisplayName();
126         }
127         else if (node == ROOT) {
128             return ROOT.toString();
129         }
130         
131         throw new UnknownTypeException(node);
132     }
133
134     public String JavaDoc getIconBase(Object JavaDoc node) throws UnknownTypeException {
135         if (node instanceof DebugFrame) {
136             DbgDebuggerImpl.Context context = getDebugger().getCurrentScriptContext();
137             
138             if(context != null && context.getCallStack().get(0) == node) {
139                 return CURRENT_CALL_STACK;
140             }
141             else {
142                 return CALL_STACK;
143             }
144         }
145         else if (node == ROOT) {
146             return null;
147         }
148         
149         throw new UnknownTypeException (node);
150     }
151
152     public String JavaDoc getShortDescription(Object JavaDoc node) throws UnknownTypeException {
153         if(node == ROOT) {
154             return null;
155         }
156         else if (node instanceof DebugFrame) {
157             return null;
158         }
159         
160         throw new UnknownTypeException (node);
161     }
162
163     // ------------------------------------------------------------------------
164
// NodeActionsProvider implementation
165
// ------------------------------------------------------------------------
166
public void performDefaultAction(Object JavaDoc node) throws UnknownTypeException {
167         if (node instanceof DebugFrame) {
168             DebugFrame frame = (DebugFrame)node;
169
170             // Update frame dependent models to current frame.
171
DbgDebuggerImpl debugger = getDebugger();
172             debugger.getWatchesModel().setStackFrame(frame);
173             debugger.getVariablesModel().setStackFrame(frame);
174
175             // Focus current file/line of selected stack frame.
176
final Line line = frame.getLine();
177             
178             if (line != null) {
179                 Mutex.EVENT.readAccess(new Runnable JavaDoc () {
180                     public void run () {
181                         line.show(Line.SHOW_GOTO);
182                     }
183                 });
184             }
185         }
186         throw new UnknownTypeException (node);
187     }
188
189     public Action JavaDoc[] getActions (Object JavaDoc node) throws UnknownTypeException {
190         return new Action JavaDoc[] {};
191     }
192
193     // ------------------------------------------------------------------------
194
// TableModel implementation
195
// ------------------------------------------------------------------------
196
public Object JavaDoc getValueAt(Object JavaDoc node, String JavaDoc columnID) throws UnknownTypeException {
197         if(node == ROOT) {
198             return null;
199         }
200         else if (node instanceof DebugFrame) {
201             if (columnID == Constants.CALL_STACK_FRAME_LOCATION_COLUMN_ID) {
202                 DebugFrame frame = (DebugFrame)node;
203                 
204                 return frame.getSourceFile() + ":" + frame.getLineNumber();
205             }
206             else {
207                 return "?! unknown column";
208             }
209         }
210         
211         throw new UnknownTypeException (node);
212     }
213
214     public boolean isReadOnly(Object JavaDoc node, String JavaDoc columnID) throws UnknownTypeException {
215         if(node == ROOT) {
216             return true;
217         }
218         else if (node instanceof DebugFrame) {
219             return true;
220         }
221         
222         throw new UnknownTypeException (node);
223     }
224
225     public void setValueAt(Object JavaDoc node, String JavaDoc columnID, Object JavaDoc value) throws UnknownTypeException {
226         throw new UnknownTypeException(node);
227     }
228 }
229
Popular Tags