1 19 20 package org.netbeans.modules.debugger.jpda.actions; 21 22 import com.sun.jdi.ThreadReference; 23 import com.sun.jdi.VMDisconnectedException; 24 import com.sun.jdi.VirtualMachine; 25 import com.sun.jdi.request.EventRequestManager; 26 import com.sun.jdi.request.InvalidRequestStateException; 27 import com.sun.jdi.request.StepRequest; 28 import java.beans.PropertyChangeEvent ; 29 import java.beans.PropertyChangeListener ; 30 import java.util.HashSet ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Set ; 34 import org.netbeans.modules.debugger.jpda.JPDADebuggerImpl; 35 import org.netbeans.modules.debugger.jpda.JPDAStepImpl.SingleThreadedStepWatch; 36 import org.netbeans.spi.debugger.ActionsProviderSupport; 37 import org.openide.util.RequestProcessor; 38 import org.openide.util.WeakSet; 39 40 41 47 abstract class JPDADebuggerActionProvider extends ActionsProviderSupport 48 implements PropertyChangeListener { 49 50 private JPDADebuggerImpl debugger; 51 52 53 private static RequestProcessor actionsRequestProcessor; 54 55 private static Set <JPDADebuggerActionProvider> providersToDisableOnLazyActions = new WeakSet<JPDADebuggerActionProvider>(); 56 57 private volatile boolean disabled; 58 59 JPDADebuggerActionProvider (JPDADebuggerImpl debugger) { 60 this.debugger = debugger; 61 debugger.addPropertyChangeListener (debugger.PROP_STATE, this); 62 } 63 64 public void propertyChange (PropertyChangeEvent evt) { 65 if (debugger.getState() == JPDADebuggerImpl.STATE_DISCONNECTED) { 66 synchronized (JPDADebuggerActionProvider.class) { 67 if (actionsRequestProcessor != null) { 68 actionsRequestProcessor.stop(); 69 actionsRequestProcessor = null; 70 } 71 } 72 } 73 checkEnabled (debugger.getState ()); 74 } 75 76 protected abstract void checkEnabled (int debuggerState); 77 78 public boolean isEnabled (Object action) { 79 if (!disabled) { 80 checkEnabled (debugger.getState ()); 81 } 82 return super.isEnabled (action); 83 } 84 85 JPDADebuggerImpl getDebuggerImpl () { 86 return debugger; 87 } 88 89 protected void removeStepRequests (ThreadReference tr) { 90 try { 92 VirtualMachine vm = getDebuggerImpl ().getVirtualMachine (); 93 if (vm == null) return; 94 EventRequestManager erm = vm.eventRequestManager (); 95 List <StepRequest> l = erm.stepRequests (); 96 Iterator <StepRequest> it = l.iterator (); 97 while (it.hasNext ()) { 98 StepRequest stepRequest = it.next (); 99 if (stepRequest.thread ().equals (tr)) { 100 erm.deleteEventRequest (stepRequest); 102 SingleThreadedStepWatch.stepRequestDeleted(stepRequest); 103 break; 104 } 105 } 107 } catch (VMDisconnectedException e) { 108 } catch (IllegalThreadStateException e) { 109 e.printStackTrace(); 110 } catch (InvalidRequestStateException e) { 111 e.printStackTrace(); 112 } 113 } 114 115 118 protected final void setProviderToDisableOnLazyAction(JPDADebuggerActionProvider provider) { 119 synchronized (JPDADebuggerActionProvider.class) { 120 providersToDisableOnLazyActions.add(provider); 121 } 122 } 123 124 128 protected final void doLazyAction(final Runnable run) { 129 final Set <JPDADebuggerActionProvider> disabledActions; 130 synchronized (JPDADebuggerActionProvider.class) { 131 if (actionsRequestProcessor == null) { 132 actionsRequestProcessor = new RequestProcessor("JPDA Processor", 1); } 134 disabledActions = new HashSet <JPDADebuggerActionProvider>(providersToDisableOnLazyActions); 135 } 136 for (Iterator <JPDADebuggerActionProvider> it = disabledActions.iterator(); it.hasNext(); ) { 137 JPDADebuggerActionProvider ap = it.next(); 138 Set actions = ap.getActions(); 139 ap.disabled = true; 140 for (Iterator ait = actions.iterator(); ait.hasNext(); ) { 141 Object action = ait.next(); 142 ap.setEnabled (action, false); 143 } 145 } 146 actionsRequestProcessor.post(new Runnable () { 147 public void run() { 148 try { 149 run.run(); 150 for (Iterator <JPDADebuggerActionProvider> it = disabledActions.iterator(); it.hasNext(); ) { 151 JPDADebuggerActionProvider ap = it.next(); 152 Set actions = ap.getActions(); 153 ap.disabled = false; 154 ap.checkEnabled (debugger.getState ()); 155 } 156 } catch (com.sun.jdi.VMDisconnectedException e) { 157 } 159 } 160 }); 161 } 162 } 163 | Popular Tags |