KickJava   Java API By Example, From Geeks To Geeks.

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


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 package org.netbeans.modules.debugger.jpda.actions;
20
21 import java.beans.PropertyChangeEvent JavaDoc;
22 import java.beans.PropertyChangeListener JavaDoc;
23 import java.util.Collections JavaDoc;
24 import java.util.Set JavaDoc;
25 import org.netbeans.api.debugger.ActionsManager;
26 import org.netbeans.api.debugger.ActionsManagerListener;
27 import org.netbeans.api.debugger.DebuggerManager;
28 import org.netbeans.api.debugger.jpda.JPDAStep;
29 import org.netbeans.spi.debugger.ContextProvider;
30 import org.netbeans.api.debugger.Session;
31 import org.netbeans.api.debugger.jpda.JPDADebugger;
32 import org.netbeans.api.debugger.jpda.LineBreakpoint;
33 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl;
34 import org.netbeans.spi.debugger.ActionsProviderSupport;
35
36
37 /**
38  *
39  * @author Martin Entlicher
40  */

41 public class StepOperationActionProvider extends ActionsProviderSupport
42                                        implements PropertyChangeListener JavaDoc,
43                                                   ActionsManagerListener {
44
45     private JPDADebugger debugger;
46     private Session session;
47     private ActionsManager lastActionsManager;
48     
49     
50     public StepOperationActionProvider (ContextProvider lookupProvider) {
51         debugger = (JPDADebugger) lookupProvider.lookupFirst
52                 (null, JPDADebugger.class);
53         session = (Session) lookupProvider.lookupFirst
54                 (null, Session.class);
55         debugger.addPropertyChangeListener (debugger.PROP_STATE, this);
56     }
57     
58     private void destroy () {
59         debugger.removePropertyChangeListener (debugger.PROP_STATE, this);
60     }
61     
62     static ActionsManager getCurrentActionsManager () {
63         return DebuggerManager.getDebuggerManager ().
64             getCurrentEngine () == null ?
65             DebuggerManager.getDebuggerManager ().getActionsManager () :
66             DebuggerManager.getDebuggerManager ().getCurrentEngine ().
67                 getActionsManager ();
68     }
69     
70     private ActionsManager getActionsManager () {
71         ActionsManager current = getCurrentActionsManager();
72         if (current != lastActionsManager) {
73             if (lastActionsManager != null) {
74                 lastActionsManager.removeActionsManagerListener(
75                         ActionsManagerListener.PROP_ACTION_STATE_CHANGED, this);
76             }
77             current.addActionsManagerListener(
78                     ActionsManagerListener.PROP_ACTION_STATE_CHANGED, this);
79             lastActionsManager = current;
80         }
81         return current;
82     }
83
84     public void propertyChange (PropertyChangeEvent JavaDoc evt) {
85         setEnabled (
86             ActionsManager.ACTION_STEP_OPERATION,
87             getActionsManager().isEnabled(ActionsManager.ACTION_CONTINUE) &&
88             (debugger.getState () == debugger.STATE_STOPPED)
89         );
90         if (debugger.getState () == debugger.STATE_DISCONNECTED)
91             destroy ();
92     }
93     
94     public Set JavaDoc getActions () {
95         return Collections.singleton (ActionsManager.ACTION_STEP_OPERATION);
96     }
97     
98     public void doAction (Object JavaDoc action) {
99         JPDAStep step = debugger.createJPDAStep(JPDAStep.STEP_OPERATION, JPDAStep.STEP_OVER);
100         step.addStep(debugger.getCurrentThread());
101         if (debugger.getSuspend() == JPDADebugger.SUSPEND_EVENT_THREAD) {
102             //debugger.getCurrentThread().resume();
103
((JPDADebuggerImpl) debugger).resumeCurrentThread();
104         } else {
105             ((JPDADebuggerImpl) debugger).resume();
106         }
107     }
108
109     public void actionPerformed(Object JavaDoc action) {
110         // Is never called
111
}
112
113     /** Sync up with continue action state. */
114     public void actionStateChanged(Object JavaDoc action, boolean enabled) {
115         if (ActionsManager.ACTION_CONTINUE == action) {
116             setEnabled (
117                 ActionsManager.ACTION_STEP_OPERATION,
118                 enabled &&
119                 (debugger.getState () == debugger.STATE_STOPPED)
120             );
121         }
122     }
123 }
124
Popular Tags