KickJava   Java API By Example, From Geeks To Geeks.

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


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 javax.swing.Action JavaDoc;
23 import org.netbeans.modules.scripting.php.dbginterface.DbgDebuggerImpl;
24 import org.netbeans.modules.scripting.php.dbginterface.ModelSupport;
25 import org.netbeans.spi.debugger.ContextProvider;
26 import org.netbeans.spi.viewmodel.ModelEvent;
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.util.NbBundle;
34
35 /**
36  *
37  * @author Jan Jancura
38  */

39 public class ThreadsModel extends ModelSupport
40         implements TreeModel, NodeModel, NodeActionsProvider, TableModel {
41
42     private static final boolean DEBUG = false;
43
44     public static final String JavaDoc CURRENT =
45         "org/netbeans/modules/debugger/resources/threadsView/CurrentThread"; // NOI18N
46
public static final String JavaDoc RUNNING =
47         "org/netbeans/modules/debugger/resources/threadsView/RunningThread"; // NOI18N
48
public static final String JavaDoc SUSPENDED =
49         "org/netbeans/modules/debugger/resources/threadsView/SuspendedThread"; // NOI18N
50

51     public ThreadsModel(ContextProvider contextProvider) {
52         this.contextProvider = contextProvider;
53     }
54
55     private ContextProvider contextProvider;
56
57     private ContextProvider getContextProvider() {
58         return contextProvider;
59     }
60
61     private DbgDebuggerImpl getDebugger() {
62         return (DbgDebuggerImpl)contextProvider.lookupFirst(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(DEBUG) Debug.verboseWithin(this,"getChildren",parent); // NOI18N
74
if (parent == ROOT) {
75             return getDebugger().getScriptContexts();
76         }
77         
78         throw new UnknownTypeException(parent);
79     }
80
81     public boolean isLeaf(Object JavaDoc node) throws UnknownTypeException {
82 // if(DEBUG) Debug.verboseWithin(this,"isLeaf",node); // NOI18N
83
if (node == ROOT) {
84             return false;
85         }
86         else if (node instanceof DbgDebuggerImpl.Context) {
87             return true;
88         }
89
90         throw new UnknownTypeException(node);
91     }
92
93     public int getChildrenCount(Object JavaDoc node) throws UnknownTypeException {
94 // if(DEBUG) Debug.verboseWithin(this,"getChildrenCount",node); // NOI18N
95
if (node == ROOT) {
96             return getDebugger().getScriptContexts().length;
97         }
98         throw new UnknownTypeException(node);
99     }
100
101     // ------------------------------------------------------------------------
102
// NodeModel implementation
103
// ------------------------------------------------------------------------
104
public String JavaDoc getDisplayName(Object JavaDoc node) throws UnknownTypeException {
105 // if(DEBUG) Debug.verboseWithin(this,"getDisplayName",node); // NOI18N
106
if (node instanceof DbgDebuggerImpl.Context) {
107             DbgDebuggerImpl.Context context = (DbgDebuggerImpl.Context) node;
108             String JavaDoc contextName = context.toString();
109             String JavaDoc debuggerName = context.getServer().toString();
110             
111             return NbBundle.getMessage(ThreadsModel.class, "LBL_ThreadName", contextName, debuggerName); // NOI18N
112
}
113         else if (node == ROOT) {
114             return ROOT.toString();
115         }
116         
117         throw new UnknownTypeException(node);
118     }
119
120     public String JavaDoc getIconBase(Object JavaDoc node) throws UnknownTypeException {
121 // if(DEBUG) Debug.verboseWithin(this,"getIconBase",node); // NOI18N
122
if (node instanceof DbgDebuggerImpl.Context) {
123             if (((DbgDebuggerImpl.Context)node).isSuspended()) {
124                 return SUSPENDED;
125             }
126             else if (((DbgDebuggerImpl.Context)node).isCurrent()) {
127                 return CURRENT;
128             }
129             else {
130                 return RUNNING;
131             }
132         }
133         else if (node == ROOT) {
134             return null;
135         }
136         
137         throw new UnknownTypeException(node);
138     }
139
140     public String JavaDoc getShortDescription(Object JavaDoc node) throws UnknownTypeException {
141 // if(DEBUG) Debug.verboseWithin(this,"getShortDescription",node); // NOI18N
142
if (node == ROOT) {
143             return null;
144         }
145         else if (node instanceof DbgDebuggerImpl.Context) {
146             return null;
147         }
148         throw new UnknownTypeException(node);
149     }
150
151     // ------------------------------------------------------------------------
152
// NodeActionsProvider implementation
153
// ------------------------------------------------------------------------
154
public void performDefaultAction(Object JavaDoc node) throws UnknownTypeException {
155 // if(DEBUG) Debug.verboseWithin(this,"performDefaultAction",node); // NOI18N
156
if (node instanceof DbgDebuggerImpl.Context) {
157             DbgDebuggerImpl.Context context = (DbgDebuggerImpl.Context) node;
158             
159             if (!context.isCurrent()) {
160                 getDebugger().setCurrentScriptContext(context);
161                 refresh(false);
162             }
163         }
164         
165         throw new UnknownTypeException(node);
166     }
167
168     public Action JavaDoc[] getActions(Object JavaDoc node) throws UnknownTypeException {
169         return new Action JavaDoc [] {};
170     }
171
172     // ------------------------------------------------------------------------
173
// TableModel implementation
174
// ------------------------------------------------------------------------
175
public Object JavaDoc getValueAt(Object JavaDoc node, String JavaDoc columnID) throws UnknownTypeException {
176 // if(DEBUG) Debug.verboseWithin(this,"getValueAt", node); // NOI18N
177
if (node == ROOT) {
178             return null;
179         }
180
181         if (node instanceof DbgDebuggerImpl.Context) {
182             DbgDebuggerImpl.Context context = (DbgDebuggerImpl.Context)node;
183             
184             if (columnID == Constants.THREAD_SUSPENDED_COLUMN_ID) {
185                 return context.isSuspended();
186             }
187             else if (columnID == Constants.THREAD_STATE_COLUMN_ID) {
188                 String JavaDoc result = NbBundle.getMessage(ThreadsModel.class,
189                         (context.isCurrent() ? "LBL_ActiveThreadState" : "LBL_InactiveThreadState"), // NOI18N
190
NbBundle.getMessage(ThreadsModel.class,
191                         (context.isSuspended() ? "LBL_Suspended" : "LBL_Running"))); // NOI18N
192
return result;
193             }
194         }
195
196         throw new UnknownTypeException(node);
197     }
198
199     public boolean isReadOnly(Object JavaDoc node, String JavaDoc columnID) throws UnknownTypeException {
200 // if(DEBUG) Debug.verboseWithin(this,"isReadOnly", node); // NOI18N
201
if (node == ROOT) {
202             return true;
203         }
204         else if (node instanceof DbgDebuggerImpl.Context) {
205             return true;
206         }
207
208         // if(DEBUG) Debug.verboseWithin(this, "isReadOnly", "THROWING -> UTE + " + node); // NOI18N
209
throw new UnknownTypeException(node);
210     }
211
212     public void setValueAt(Object JavaDoc node, String JavaDoc columnID, Object JavaDoc value) throws UnknownTypeException {
213 // if(DEBUG) Debug.verboseWithin(this,"setValueAt", node); // NOI18N
214
throw new UnknownTypeException(node);
215     }
216
217
218     // ------------------------------------------------------------------------
219
// Event support
220
// ------------------------------------------------------------------------
221

222     public void updateThreadState(DbgDebuggerImpl.Context context) {
223         // if(DEBUG) Debug.verboseWithin(this, "updateThreadState"); // NOI18N
224

225         fireChangeEvent(new ModelEvent.NodeChanged(this, context));
226     }
227
228     public void updateThreadState(DbgDebuggerImpl.Context[] context) {
229         // if(DEBUG) Debug.verboseWithin(this, "updateThreadState[]"); // NOI18N
230

231         ModelEvent[] events = new ModelEvent[context.length];
232         
233         for(int i = 0; i < context.length; i++) {
234             events[i] = new ModelEvent.NodeChanged(this, context[i]);
235         }
236         fireChangeEvents(events);
237     }
238 }
239
Popular Tags