1 11 package org.eclipse.debug.internal.ui.actions; 12 13 14 import org.eclipse.debug.core.DebugEvent; 15 import org.eclipse.debug.core.DebugException; 16 import org.eclipse.debug.core.DebugPlugin; 17 import org.eclipse.debug.core.ILaunch; 18 import org.eclipse.debug.core.ILaunchManager; 19 import org.eclipse.debug.core.model.IDebugTarget; 20 import org.eclipse.debug.core.model.IProcess; 21 import org.eclipse.debug.core.model.ITerminate; 22 import org.eclipse.jface.action.IAction; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.jface.viewers.IStructuredSelection; 25 26 public class TerminateActionDelegate extends AbstractListenerActionDelegate { 27 28 31 protected void doAction(Object element) throws DebugException { 32 if (element instanceof ITerminate) { 33 if (element instanceof IProcess) { 34 killTargets((IProcess) element); 35 } 36 ((ITerminate)element).terminate(); 37 } 38 } 39 40 private void killTargets(IProcess process) throws DebugException { 41 ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); 42 ILaunch[] launches = launchManager.getLaunches(); 43 44 for (int i = 0; i < launches.length; i++) { 45 ILaunch launch = launches[i]; 46 IProcess[] processes = launch.getProcesses(); 47 for (int j = 0; j < processes.length; j++) { 48 IProcess process2 = processes[j]; 49 if (process2.equals(process)) { 50 IDebugTarget[] debugTargets = launch.getDebugTargets(); 51 for (int k = 0; k < debugTargets.length; k++) { 52 IDebugTarget target = debugTargets[k]; 53 if (target.canTerminate()) { 54 target.terminate(); 55 } 56 } 57 return; } 59 } 60 } 61 } 62 63 66 protected boolean isRunInBackground() { 67 return true; 68 } 69 70 73 protected boolean isEnabledFor(Object element) { 74 return element instanceof ITerminate && ((ITerminate)element).canTerminate(); 75 } 76 77 80 protected String getStatusMessage() { 81 return ActionMessages.TerminateActionDelegate_Exceptions_occurred_attempting_to_terminate__2; } 83 84 87 protected String getErrorDialogMessage() { 88 return ActionMessages.TerminateActionDelegate_Terminate_failed__1; } 90 91 94 protected void doHandleDebugEvent(DebugEvent event) { 95 if (event.getKind() == DebugEvent.TERMINATE || event.getKind() == DebugEvent.CREATE) { 96 update(getAction(), getSelection()); 97 } 98 } 99 100 103 protected void update(IAction action, ISelection s) { 104 if (s instanceof IStructuredSelection) { 106 super.update(action, s); 107 } 108 } 109 110 111 } 112 | Popular Tags |