1 11 package org.eclipse.debug.ui.actions; 12 13 import org.eclipse.core.resources.IWorkspaceRunnable; 14 import org.eclipse.core.runtime.CoreException; 15 import org.eclipse.core.runtime.IProgressMonitor; 16 import org.eclipse.core.runtime.IStatus; 17 import org.eclipse.core.runtime.Status; 18 import org.eclipse.core.runtime.jobs.Job; 19 import org.eclipse.debug.core.DebugEvent; 20 import org.eclipse.debug.core.DebugException; 21 import org.eclipse.debug.core.DebugPlugin; 22 import org.eclipse.debug.core.IBreakpointManager; 23 import org.eclipse.debug.core.IBreakpointManagerListener; 24 import org.eclipse.debug.core.IDebugEventSetListener; 25 import org.eclipse.debug.core.model.IBreakpoint; 26 import org.eclipse.debug.core.model.IDebugTarget; 27 import org.eclipse.debug.core.model.ISuspendResume; 28 import org.eclipse.debug.core.model.IThread; 29 import org.eclipse.debug.internal.ui.actions.ActionMessages; 30 import org.eclipse.debug.ui.DebugUITools; 31 import org.eclipse.debug.ui.IDebugUIConstants; 32 33 44 public class RunToLineHandler implements IDebugEventSetListener, IBreakpointManagerListener, IWorkspaceRunnable { 45 46 private IDebugTarget fTarget; 47 private ISuspendResume fResumee; 48 private IBreakpoint fBreakpoint; 49 private boolean fAutoSkip = false; 50 51 58 public RunToLineHandler(IDebugTarget target, ISuspendResume suspendResume, IBreakpoint breakpoint) { 59 fResumee = suspendResume; 60 fTarget = target; 61 fBreakpoint = breakpoint; 62 } 63 64 67 public void handleDebugEvents(DebugEvent[] events) { 68 for (int i = 0; i < events.length; i++) { 69 DebugEvent event= events[i]; 70 Object source= event.getSource(); 71 if (source instanceof IThread && event.getKind() == DebugEvent.SUSPEND && 72 event.getDetail() == DebugEvent.BREAKPOINT) { 73 IThread thread = (IThread) source; 74 IDebugTarget suspendee = (IDebugTarget) thread.getAdapter(IDebugTarget.class); 75 if (fTarget.equals(suspendee)) { 76 cancel(); 78 } 79 } else if (source instanceof IDebugTarget && event.getKind() == DebugEvent.TERMINATE) { 80 if (source.equals(fTarget)) { 81 cancel(); 84 } 85 } 86 } 87 88 } 89 90 93 public void breakpointManagerEnablementChanged(boolean enabled) { 94 fAutoSkip = false; 96 } 97 98 private IBreakpointManager getBreakpointManager() { 99 return getDebugPlugin().getBreakpointManager(); 100 } 101 102 private DebugPlugin getDebugPlugin() { 103 return DebugPlugin.getDefault(); 104 } 105 106 109 public void cancel() { 110 IBreakpointManager manager = getBreakpointManager(); 111 try { 112 getDebugPlugin().removeDebugEventListener(this); 113 manager.removeBreakpointManagerListener(this); 114 fTarget.breakpointRemoved(fBreakpoint, null); 115 } finally { 116 if (fAutoSkip) { 117 manager.setEnabled(true); 118 } 119 } 120 } 121 122 125 public void run(IProgressMonitor monitor) throws CoreException { 126 getDebugPlugin().addDebugEventListener(this); 127 IBreakpointManager breakpointManager = getBreakpointManager(); 128 fAutoSkip = DebugUITools.getPreferenceStore().getBoolean(IDebugUIConstants.PREF_SKIP_BREAKPOINTS_DURING_RUN_TO_LINE) && breakpointManager.isEnabled(); 129 if (fAutoSkip) { 130 getBreakpointManager().setEnabled(false); 131 breakpointManager.addBreakpointManagerListener(this); 132 } 133 Job job = new Job(ActionMessages.RunToLineHandler_0) { 134 protected IStatus run(IProgressMonitor jobMonitor) { 135 if (!jobMonitor.isCanceled()) { 136 fTarget.breakpointAdded(fBreakpoint); 137 try { 138 fResumee.resume(); 139 } catch (DebugException e) { 140 cancel(); 141 return e.getStatus(); 142 } 143 } 144 return Status.OK_STATUS; 145 } 146 }; 147 job.schedule(); 148 } 149 150 } 151 | Popular Tags |