KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > actions > MakeCalleeCurrentActionProvider


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

38 public class MakeCalleeCurrentActionProvider extends JPDADebuggerAction {
39
40     private ContextProvider lookupProvider;
41     
42     
43     public MakeCalleeCurrentActionProvider (ContextProvider lookupProvider) {
44         super (
45             (JPDADebugger) lookupProvider.lookupFirst
46                 (null, JPDADebugger.class)
47         );
48         this.lookupProvider = lookupProvider;
49         getDebuggerImpl ().addPropertyChangeListener
50             (JPDADebugger.PROP_CURRENT_CALL_STACK_FRAME, this);
51     }
52     
53     public Set JavaDoc getActions () {
54         return Collections.singleton (ActionsManager.ACTION_MAKE_CALLEE_CURRENT);
55     }
56
57     public void doAction (Object JavaDoc action) {
58         JPDAThread t = getDebuggerImpl ().getCurrentThread ();
59         if (t == null) return;
60         int i = MakeCallerCurrentActionProvider.getCurrentCallStackFrameIndex
61             (getDebuggerImpl ());
62         if (i == 0) return;
63         MakeCallerCurrentActionProvider.setCurrentCallStackFrameIndex
64             (getDebuggerImpl (), --i, lookupProvider);
65     }
66     
67     protected void checkEnabled (int debuggerState) {
68         if (debuggerState == getDebuggerImpl ().STATE_STOPPED) {
69             JPDAThread t = getDebuggerImpl ().getCurrentThread ();
70             if (t != null) {
71                 int i = MakeCallerCurrentActionProvider.getCurrentCallStackFrameIndex
72                     (getDebuggerImpl ());
73                 setEnabled (
74                     ActionsManager.ACTION_MAKE_CALLEE_CURRENT,
75                     i > 0
76                 );
77                 return;
78             }
79         }
80         setEnabled (
81             ActionsManager.ACTION_MAKE_CALLEE_CURRENT,
82             false
83         );
84     }
85 }
86
Popular Tags