1 19 package org.netbeans.modules.debugger.jpda.ui.actions; 20 21 import com.sun.jdi.VMDisconnectedException; 22 import com.sun.jdi.request.EventRequestManager; 23 import java.beans.PropertyChangeEvent ; 24 import java.beans.PropertyChangeListener ; 25 26 import java.util.Collections ; 27 import java.util.Set ; 28 import org.netbeans.api.debugger.ActionsManager; 29 import org.netbeans.api.debugger.ActionsManagerListener; 30 31 32 import org.netbeans.api.debugger.DebuggerManager; 33 import org.netbeans.spi.debugger.ContextProvider; 34 import org.netbeans.api.debugger.Session; 35 import org.netbeans.api.debugger.jpda.JPDADebugger; 36 import org.netbeans.api.debugger.jpda.LineBreakpoint; 37 import org.netbeans.modules.debugger.jpda.ui.EditorContextBridge; 38 import org.netbeans.spi.debugger.ActionsProviderSupport; 39 40 41 45 public class RunToCursorActionProvider extends ActionsProviderSupport 46 implements PropertyChangeListener , 47 ActionsManagerListener { 48 49 private JPDADebugger debugger; 50 private Session session; 51 private LineBreakpoint breakpoint; 52 private ActionsManager lastActionsManager; 53 54 55 public RunToCursorActionProvider (ContextProvider lookupProvider) { 56 debugger = (JPDADebugger) lookupProvider.lookupFirst 57 (null, JPDADebugger.class); 58 session = (Session) lookupProvider.lookupFirst 59 (null, Session.class); 60 debugger.addPropertyChangeListener (debugger.PROP_STATE, this); 61 EditorContextBridge.addPropertyChangeListener (this); 62 } 63 64 private void destroy () { 65 debugger.removePropertyChangeListener (debugger.PROP_STATE, this); 66 EditorContextBridge.removePropertyChangeListener (this); 67 } 68 69 static ActionsManager getCurrentActionsManager () { 70 return DebuggerManager.getDebuggerManager (). 71 getCurrentEngine () == null ? 72 DebuggerManager.getDebuggerManager ().getActionsManager () : 73 DebuggerManager.getDebuggerManager ().getCurrentEngine (). 74 getActionsManager (); 75 } 76 77 private ActionsManager getActionsManager () { 78 ActionsManager current = getCurrentActionsManager(); 79 if (current != lastActionsManager) { 80 if (lastActionsManager != null) { 81 lastActionsManager.removeActionsManagerListener( 82 ActionsManagerListener.PROP_ACTION_STATE_CHANGED, this); 83 } 84 current.addActionsManagerListener( 85 ActionsManagerListener.PROP_ACTION_STATE_CHANGED, this); 86 lastActionsManager = current; 87 } 88 return current; 89 } 90 91 public void propertyChange (PropertyChangeEvent evt) { 92 setEnabled ( 93 ActionsManager.ACTION_RUN_TO_CURSOR, 94 getActionsManager().isEnabled(ActionsManager.ACTION_CONTINUE) && 95 (debugger.getState () == debugger.STATE_STOPPED) && 96 (EditorContextBridge.getCurrentLineNumber () >= 0) && 97 (EditorContextBridge.getCurrentURL ().endsWith (".java")) 98 ); 99 if ( (debugger.getState () != debugger.STATE_RUNNING) && 100 (breakpoint != null) 101 ) { 102 DebuggerManager.getDebuggerManager ().removeBreakpoint (breakpoint); 103 breakpoint = null; 104 } 105 if (debugger.getState () == debugger.STATE_DISCONNECTED) 106 destroy (); 107 } 108 109 public Set getActions () { 110 return Collections.singleton (ActionsManager.ACTION_RUN_TO_CURSOR); 111 } 112 113 public void doAction (Object action) { 114 if (breakpoint != null) { 115 DebuggerManager.getDebuggerManager ().removeBreakpoint (breakpoint); 116 breakpoint = null; 117 } 118 breakpoint = LineBreakpoint.create ( 119 EditorContextBridge.getCurrentURL (), 120 EditorContextBridge.getCurrentLineNumber () 121 ); 122 breakpoint.setHidden (true); 123 DebuggerManager.getDebuggerManager ().addBreakpoint (breakpoint); 124 session.getEngineForLanguage ("Java").getActionsManager ().doAction ( 125 ActionsManager.ACTION_CONTINUE 126 ); 127 } 128 129 public void actionPerformed(Object action) { 130 } 132 133 134 public void actionStateChanged(Object action, boolean enabled) { 135 if (ActionsManager.ACTION_CONTINUE == action) { 136 setEnabled ( 137 ActionsManager.ACTION_RUN_TO_CURSOR, 138 enabled && 139 (debugger.getState () == debugger.STATE_STOPPED) && 140 (EditorContextBridge.getCurrentLineNumber () >= 0) && 141 (EditorContextBridge.getCurrentURL ().endsWith (".java")) 142 ); 143 } 144 } 145 } 146 | Popular Tags |