2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.debugger.jpda.ui.models;
44
import java.awt.event.ActionEvent;
45
import java.util.Vector;
46
import javax.swing.Action;
48
import org.netbeans.api.debugger.DebuggerEngine;
49
import org.netbeans.api.debugger.DebuggerManager;
50
import org.netbeans.spi.debugger.ContextProvider;
51
import org.netbeans.api.debugger.jpda.JPDADebugger;
52
import org.netbeans.api.debugger.jpda.JPDAThread;
53
import org.netbeans.api.debugger.jpda.JPDAThreadGroup;
54
import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge;
55
import org.netbeans.modules.debugger.jpda.ui.SourcePath;
56
import org.netbeans.spi.viewmodel.NodeActionsProvider;
57
import org.netbeans.spi.viewmodel.ModelListener;
58
import org.netbeans.spi.viewmodel.UnknownTypeException;
59
import org.netbeans.spi.viewmodel.Models;
60
import org.netbeans.spi.viewmodel.TreeModel;
61
import org.openide.util.NbBundle;
67
public class ThreadsActionsProvider implements NodeActionsProvider {
69
private Action MAKE_CURRENT_ACTION = Models.createAction (
70
NbBundle.getBundle(ThreadsActionsProvider.class).getString("CTL_ThreadAction_MakeCurrent_Label"),
71
new Models.ActionPerformer () {
72
public boolean isEnabled (Object node) {
73
if (node instanceof MonitorModel.ThreadWithBordel) node = ((MonitorModel.ThreadWithBordel) node).originalThread;
74
return debugger.getCurrentThread () != node;
77
public void perform (Object[] nodes) {
78
if (nodes[0] instanceof MonitorModel.ThreadWithBordel) nodes[0] = ((MonitorModel.ThreadWithBordel) nodes[0]).originalThread;
79
((JPDAThread) nodes [0]).makeCurrent ();
82
Models.MULTISELECTION_TYPE_EXACTLY_ONE
85
private static Action GO_TO_SOURCE_ACTION = Models.createAction (
86
NbBundle.getBundle(ThreadsActionsProvider.class).getString("CTL_ThreadAction_GoToSource_Label"),
87
new Models.ActionPerformer () {
88
public boolean isEnabled (Object node) {
89
if (node instanceof MonitorModel.ThreadWithBordel) node = ((MonitorModel.ThreadWithBordel) node).originalThread;
90
return isGoToSourceSupported ((JPDAThread) node);
93
public void perform (Object[] nodes) {
94
if (nodes[0] instanceof MonitorModel.ThreadWithBordel) nodes[0] = ((MonitorModel.ThreadWithBordel) nodes[0]).originalThread;
95
String language = DebuggerManager.getDebuggerManager ().
96
getCurrentSession ().getCurrentLanguage ();
97
SourcePath sp = (SourcePath) DebuggerManager.
98
getDebuggerManager ().getCurrentEngine ().lookupFirst
99
(null, SourcePath.class);
100
sp.showSource ((JPDAThread) nodes [0], language);
103
Models.MULTISELECTION_TYPE_EXACTLY_ONE
106
private Action SUSPEND_ACTION = Models.createAction (
107
NbBundle.getBundle(ThreadsActionsProvider.class).getString("CTL_ThreadAction_Suspend_Label"),
108
new Models.ActionPerformer () {
109
public boolean isEnabled (Object node) {
110
if (node instanceof MonitorModel.ThreadWithBordel) node = ((MonitorModel.ThreadWithBordel) node).originalThread;
111
if (node instanceof JPDAThread)
112
return !((JPDAThread) node).isSuspended ();
117
public void perform (Object[] nodes) {
118
int i, k = nodes.length;
119
for (i = 0; i < k; i++) {
120
Object node = (nodes[i] instanceof MonitorModel.ThreadWithBordel) ?
121
((MonitorModel.ThreadWithBordel) nodes[i]).originalThread : nodes[i];
122
if (node instanceof JPDAThread)
123
((JPDAThread) node).suspend ();
125
((JPDAThreadGroup) node).suspend ();
129
Models.MULTISELECTION_TYPE_ALL
132
private Action RESUME_ACTION = Models.createAction (
133
NbBundle.getBundle(ThreadsActionsProvider.class).getString("CTL_ThreadAction_Resume_Label"),
134
new Models.ActionPerformer () {
135
public boolean isEnabled (Object node) {
136
if (node instanceof MonitorModel.ThreadWithBordel) node = ((MonitorModel.ThreadWithBordel) node).originalThread;
137
if (node instanceof JPDAThread)
138
return ((JPDAThread) node).isSuspended ();
143
public void perform (Object[] nodes) {
144
int i, k = nodes.length;
145
for (i = 0; i < k; i++) {
146
Object node = (nodes[i] instanceof MonitorModel.ThreadWithBordel) ?
147
((MonitorModel.ThreadWithBordel) nodes[i]).originalThread : nodes[i];
148
if (node instanceof JPDAThread)
149
((JPDAThread) node).resume ();
151
((JPDAThreadGroup) node).resume ();
155
Models.MULTISELECTION_TYPE_ALL
158
private Action INTERRUPT_ACTION = Models.createAction (
159
NbBundle.getBundle(ThreadsActionsProvider.class).getString("CTL_ThreadAction_Interrupt_Label"),
160
new Models.ActionPerformer () {
161
public boolean isEnabled (Object node) {
162
if (node instanceof MonitorModel.ThreadWithBordel) node = ((MonitorModel.ThreadWithBordel) node).originalThread;
163
if (node instanceof JPDAThread)
164
return !((JPDAThread) node).isSuspended ();
169
public void perform (Object[] nodes) {
170
int i, k = nodes.length;
171
for (i = 0; i < k; i++) {
172
Object node = (nodes[i] instanceof MonitorModel.ThreadWithBordel) ?
173
((MonitorModel.ThreadWithBordel) nodes[i]).originalThread : nodes[i];
174
if (node instanceof JPDAThread) {
175
((JPDAThread) node).interrupt();
180
Models.MULTISELECTION_TYPE_ALL
183
private JPDADebugger debugger;
186
public ThreadsActionsProvider (ContextProvider lookupProvider) {
187
debugger = (JPDADebugger) lookupProvider.
188
lookupFirst (null, JPDADebugger.class);
191
public Action[] getActions (Object node) throws UnknownTypeException {
192
if (node == TreeModel.ROOT)
193
return new Action [0];
194
if (node instanceof JPDAThreadGroup) {
195
return new Action [] {
200
if (node instanceof JPDAThread) {
201
JPDAThread t = (JPDAThread) node;
202
boolean suspended = t.isSuspended ();
208
return new Action [] {
215
throw new UnknownTypeException (node);
218
public void performDefaultAction (Object node) throws UnknownTypeException {
219
if (node == TreeModel.ROOT)
221
if (node instanceof JPDAThread)
222
((JPDAThread) node).makeCurrent ();
224
if (node instanceof JPDAThreadGroup)
227
throw new UnknownTypeException (node);
232
* @param l the listener to add
234
public void addModelListener (ModelListener l) {
239
* @param l the listener to remove
241
public void removeModelListener (ModelListener l) {
244
private static boolean isGoToSourceSupported (JPDAThread t) {
245
String language = DebuggerManager.getDebuggerManager ().
246
getCurrentSession ().getCurrentLanguage ();
247
if (!t.isSuspended ())
249
String className = t.getClassName ();
250
SourcePath sp = (SourcePath) DebuggerManager.
251
getDebuggerManager ().getCurrentEngine ().lookupFirst
252
(null, SourcePath.class);
253
return sp.sourceAvailable (t, language, true);