KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > actions > PauseActionProvider


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.debugger.jpda.actions;
21
22 import com.sun.jdi.ThreadReference;
23 import com.sun.jdi.VMDisconnectedException;
24 import com.sun.jdi.VirtualMachine;
25 import java.util.Collections JavaDoc;
26 import java.util.List JavaDoc;
27 import java.util.Map JavaDoc;
28 import java.util.Set JavaDoc;
29 import org.netbeans.api.debugger.ActionsManager;
30
31
32 import org.netbeans.spi.debugger.ContextProvider;
33 import org.netbeans.api.debugger.jpda.JPDADebugger;
34 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
35 import org.openide.util.RequestProcessor;
36
37
38 /**
39 * Representation of a debugging session.
40 *
41 * @author Jan Jancura
42 * @author Marian Petras
43 */

44 public class PauseActionProvider extends JPDADebuggerActionProvider {
45     
46     private volatile boolean doingAction;
47     
48     
49     public PauseActionProvider (ContextProvider contextProvider) {
50         super (
51             (JPDADebuggerImpl) contextProvider.lookupFirst
52                 (null, JPDADebugger.class)
53         );
54         setProviderToDisableOnLazyAction(this);
55     }
56     
57     public Set JavaDoc getActions () {
58         return Collections.singleton (ActionsManager.ACTION_PAUSE);
59     }
60
61     public void doAction (Object JavaDoc action) {
62         doingAction = true;
63         try {
64             ((JPDADebuggerImpl) getDebuggerImpl ()).suspend ();
65         } finally {
66             doingAction = false;
67         }
68     }
69     
70     public void postAction(Object JavaDoc action, final Runnable JavaDoc actionPerformedNotifier) {
71         doingAction = true;
72         doLazyAction(new Runnable JavaDoc() {
73             public void run() {
74                 try {
75                     ((JPDADebuggerImpl) getDebuggerImpl ()).suspend ();
76                 } finally {
77                     try {
78                         actionPerformedNotifier.run();
79                     } finally {
80                         doingAction = false;
81                     }
82                 }
83             }
84         });
85     }
86     
87     protected void checkEnabled (int debuggerState) {
88         setEnabled (
89             ActionsManager.ACTION_PAUSE,
90             debuggerState == JPDADebugger.STATE_RUNNING
91         );
92     }
93     
94 }
95
Popular Tags