KickJava   Java API By Example, From Geeks To Geeks.

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


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.AbsentInformationException;
23 import java.util.Collections JavaDoc;
24 import java.util.Set JavaDoc;
25 import org.netbeans.api.debugger.ActionsManager;
26
27 import org.netbeans.spi.debugger.ContextProvider;
28 import org.netbeans.api.debugger.jpda.JPDADebugger;
29 import org.netbeans.api.debugger.jpda.JPDAThread;
30 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
31
32
33 /**
34 * Representation of a debugging session.
35 *
36 * @author Jan Jancura
37 */

38 public class PopToHereActionProvider extends JPDADebuggerActionProvider {
39     
40     private ContextProvider lookupProvider;
41
42     
43     public PopToHereActionProvider (ContextProvider lookupProvider) {
44         super (
45             (JPDADebuggerImpl) lookupProvider.lookupFirst
46                 (null, JPDADebugger.class)
47         );
48         this.lookupProvider = lookupProvider;
49         setProviderToDisableOnLazyAction(this);
50     }
51     
52     public Set JavaDoc getActions () {
53         return Collections.singleton (ActionsManager.ACTION_POP_TOPMOST_CALL);
54     }
55
56     public void doAction (Object JavaDoc action) {
57         runAction();
58     }
59     
60     public void postAction(Object JavaDoc action, final Runnable JavaDoc actionPerformedNotifier) {
61         doLazyAction(new Runnable JavaDoc() {
62             public void run() {
63                 try {
64                     runAction();
65                 } finally {
66                     actionPerformedNotifier.run();
67                 }
68             }
69         });
70     }
71     
72     public void runAction() {
73         try {
74             JPDAThread t = getDebuggerImpl ().getCurrentThread ();
75             t.getCallStack (0, 1) [0].popFrame ();
76         } catch (AbsentInformationException ex) {
77         }
78     }
79     
80     protected void checkEnabled (int debuggerState) {
81         if (!getDebuggerImpl().canPopFrames()) {
82             setEnabled (
83                 ActionsManager.ACTION_POP_TOPMOST_CALL,
84                 false
85             );
86             return;
87         }
88         synchronized (getDebuggerImpl().LOCK) {
89             if (debuggerState == getDebuggerImpl ().STATE_STOPPED) {
90                 JPDAThread t = getDebuggerImpl ().getCurrentThread ();
91                 if (t == null) {
92                     setEnabled (
93                         ActionsManager.ACTION_POP_TOPMOST_CALL,
94                         false
95                     );
96                     return;
97                 }
98                 synchronized (t) {
99                     if (!t.isSuspended()) {
100                         setEnabled (
101                             ActionsManager.ACTION_POP_TOPMOST_CALL,
102                             false
103                         );
104                     } else {
105                         setEnabled (
106                             ActionsManager.ACTION_POP_TOPMOST_CALL,
107                             t.getStackDepth () > 1
108                         );
109                     }
110                 }
111                 return;
112             }
113             setEnabled (
114                 ActionsManager.ACTION_POP_TOPMOST_CALL,
115                 false
116             );
117         }
118     }
119 }
120
Popular Tags