KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > projects > StepIntoActionProvider


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.projects;
21
22 import java.beans.PropertyChangeEvent JavaDoc;
23 import java.beans.PropertyChangeListener JavaDoc;
24 import java.util.Collections JavaDoc;
25 import java.util.Set JavaDoc;
26 import javax.swing.SwingUtilities JavaDoc;
27 import org.netbeans.api.debugger.ActionsManager;
28
29 import org.netbeans.api.debugger.Breakpoint;
30
31 import org.netbeans.api.debugger.DebuggerManager;
32 import org.netbeans.api.debugger.DebuggerManagerListener;
33 import org.netbeans.api.debugger.Session;
34 import org.netbeans.api.debugger.Watch;
35 import org.netbeans.api.debugger.jpda.MethodBreakpoint;
36 import org.netbeans.api.project.Project;
37 import org.netbeans.spi.debugger.ActionsProviderSupport;
38 import org.netbeans.spi.project.ActionProvider;
39 import org.openide.ErrorManager;
40
41
42 /**
43 *
44 * @author Jan Jancura
45 */

46 public class StepIntoActionProvider extends ActionsProviderSupport {
47
48 // private MethodBreakpoint breakpoint;
49

50     {
51         Listener JavaDoc listener = new Listener JavaDoc ();
52         MainProjectManager.getDefault ().addPropertyChangeListener (listener);
53 // DebuggerManager.getDebuggerManager ().addDebuggerListener (listener);
54

55         setEnabled (
56             ActionsManager.ACTION_STEP_INTO,
57             shouldBeEnabled ()
58         );
59     }
60     
61     public Set JavaDoc getActions () {
62         return Collections.singleton (ActionsManager.ACTION_STEP_INTO);
63     }
64     
65     public void doAction (final Object JavaDoc action) {
66         // start debugging of project
67
if (!SwingUtilities.isEventDispatchThread()) {
68             try {
69                 SwingUtilities.invokeAndWait(new Runnable JavaDoc() {
70                     public void run() {
71                         invokeAction();
72                     }
73                 });
74             } catch (InterruptedException JavaDoc iex) {
75                 // Procceed
76
} catch (java.lang.reflect.InvocationTargetException JavaDoc itex) {
77                 ErrorManager.getDefault().notify(itex);
78             }
79         } else {
80             invokeAction();
81         }
82     }
83     
84     public void postAction(Object JavaDoc action, Runnable JavaDoc actionPerformedNotifier) {
85         // start debugging of project
86
invokeAction();
87         actionPerformedNotifier.run();
88     }
89     
90     private void invokeAction() {
91         ((ActionProvider) MainProjectManager.getDefault ().
92             getMainProject ().getLookup ().lookup (
93                 ActionProvider.class
94             )).invokeAction (
95                 ActionProvider.COMMAND_DEBUG_STEP_INTO,
96                 MainProjectManager.getDefault ().getMainProject ().getLookup ()
97             );
98     }
99     
100     private boolean shouldBeEnabled () {
101         
102         // check if current project supports this action
103
Project p = MainProjectManager.getDefault ().getMainProject ();
104         if (p == null) return false;
105         ActionProvider actionProvider = (ActionProvider) p.getLookup ().
106             lookup (ActionProvider.class);
107         if (actionProvider == null) return false;
108         String JavaDoc[] sa = actionProvider.getSupportedActions ();
109         int i, k = sa.length;
110         for (i = 0; i < k; i++)
111             if (ActionProvider.COMMAND_DEBUG_STEP_INTO.equals (sa [i]))
112                 break;
113         if (i == k) return false;
114         
115         // check if this action should be enabled
116
return actionProvider.isActionEnabled (
117             ActionProvider.COMMAND_DEBUG_STEP_INTO,
118             MainProjectManager.getDefault ().getMainProject ().getLookup ()
119         );
120     }
121     
122     
123     private class Listener implements PropertyChangeListener JavaDoc/*,
124     DebuggerManagerListener */
{
125         public void propertyChange (PropertyChangeEvent JavaDoc e) {
126             setEnabled (
127                 ActionsManager.ACTION_STEP_INTO,
128                 shouldBeEnabled ()
129             );
130         }
131 // public void sessionRemoved (Session session) {
132
// if (breakpoint != null) {
133
// DebuggerManager.getDebuggerManager ().removeBreakpoint (breakpoint);
134
// breakpoint = null;
135
// }
136
// }
137
//
138
// public void breakpointAdded (Breakpoint breakpoint) {}
139
// public void breakpointRemoved (Breakpoint breakpoint) {}
140
// public Breakpoint[] initBreakpoints () {
141
// return new Breakpoint [0];
142
// }
143
// public void initWatches () {}
144
// public void sessionAdded (Session session) {}
145
// public void watchAdded (Watch watch) {}
146
// public void watchRemoved (Watch watch) {}
147
}
148 }
149
Popular Tags