1 19 20 package org.netbeans.modules.debugger.jpda.projects; 21 22 import java.beans.PropertyChangeEvent ; 23 import java.beans.PropertyChangeListener ; 24 import java.util.Collections ; 25 import java.util.Set ; 26 import javax.swing.SwingUtilities ; 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 46 public class StepIntoActionProvider extends ActionsProviderSupport { 47 48 50 { 51 Listener listener = new Listener (); 52 MainProjectManager.getDefault ().addPropertyChangeListener (listener); 53 55 setEnabled ( 56 ActionsManager.ACTION_STEP_INTO, 57 shouldBeEnabled () 58 ); 59 } 60 61 public Set getActions () { 62 return Collections.singleton (ActionsManager.ACTION_STEP_INTO); 63 } 64 65 public void doAction (final Object action) { 66 if (!SwingUtilities.isEventDispatchThread()) { 68 try { 69 SwingUtilities.invokeAndWait(new Runnable () { 70 public void run() { 71 invokeAction(); 72 } 73 }); 74 } catch (InterruptedException iex) { 75 } catch (java.lang.reflect.InvocationTargetException itex) { 77 ErrorManager.getDefault().notify(itex); 78 } 79 } else { 80 invokeAction(); 81 } 82 } 83 84 public void postAction(Object action, Runnable actionPerformedNotifier) { 85 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 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 [] 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 return actionProvider.isActionEnabled ( 117 ActionProvider.COMMAND_DEBUG_STEP_INTO, 118 MainProjectManager.getDefault ().getMainProject ().getLookup () 119 ); 120 } 121 122 123 private class Listener implements PropertyChangeListener { 125 public void propertyChange (PropertyChangeEvent e) { 126 setEnabled ( 127 ActionsManager.ACTION_STEP_INTO, 128 shouldBeEnabled () 129 ); 130 } 131 } 148 } 149 | Popular Tags |