1 19 package org.netbeans.modules.debugger.jpda.actions; 20 21 import java.beans.PropertyChangeEvent ; 22 import java.beans.PropertyChangeListener ; 23 import java.util.Collections ; 24 import java.util.Set ; 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 41 public class StepOperationActionProvider extends ActionsProviderSupport 42 implements PropertyChangeListener , 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 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 getActions () { 95 return Collections.singleton (ActionsManager.ACTION_STEP_OPERATION); 96 } 97 98 public void doAction (Object 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 ((JPDADebuggerImpl) debugger).resumeCurrentThread(); 104 } else { 105 ((JPDADebuggerImpl) debugger).resume(); 106 } 107 } 108 109 public void actionPerformed(Object action) { 110 } 112 113 114 public void actionStateChanged(Object 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 |