1 11 package org.eclipse.debug.internal.ui.views.console; 12 13 import org.eclipse.debug.core.DebugException; 14 import org.eclipse.debug.core.DebugPlugin; 15 import org.eclipse.debug.core.ILaunch; 16 import org.eclipse.debug.core.ILaunchManager; 17 import org.eclipse.debug.core.model.IDebugTarget; 18 import org.eclipse.debug.core.model.IProcess; 19 import org.eclipse.debug.internal.ui.DebugPluginImages; 20 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 21 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 22 import org.eclipse.jface.action.Action; 23 import org.eclipse.ui.PlatformUI; 24 import org.eclipse.ui.texteditor.IUpdate; 25 26 29 public class ConsoleTerminateAction extends Action implements IUpdate { 30 31 private ProcessConsole fConsole; 32 33 36 public ConsoleTerminateAction(ProcessConsole console) { 37 super(ConsoleMessages.ConsoleTerminateAction_0); 38 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.CONSOLE_TERMINATE_ACTION); 39 fConsole = console; 40 setToolTipText(ConsoleMessages.ConsoleTerminateAction_1); 41 setImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_LCL_TERMINATE)); 42 setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TERMINATE)); 43 setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_LCL_TERMINATE)); 44 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.CONSOLE_TERMINATE_ACTION); 45 update(); 46 } 47 48 51 public void update() { 52 IProcess process = fConsole.getProcess(); 53 setEnabled(process.canTerminate()); 54 } 55 56 59 public void run() { 60 try { 61 IProcess process = fConsole.getProcess(); 62 killTargets(process); 63 process.terminate(); 64 } catch (DebugException e) { 65 } 67 } 68 69 private void killTargets(IProcess process) throws DebugException { 70 ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); 71 ILaunch[] launches = launchManager.getLaunches(); 72 73 for (int i = 0; i < launches.length; i++) { 74 ILaunch launch = launches[i]; 75 IProcess[] processes = launch.getProcesses(); 76 for (int j = 0; j < processes.length; j++) { 77 IProcess process2 = processes[j]; 78 if (process2.equals(process)) { 79 IDebugTarget[] debugTargets = launch.getDebugTargets(); 80 for (int k = 0; k < debugTargets.length; k++) { 81 IDebugTarget target = debugTargets[k]; 82 if (target.canTerminate()) { 83 target.terminate(); 84 } 85 } 86 return; } 88 } 89 } 90 } 91 92 public void dispose() { 93 fConsole = null; 94 } 95 96 } 97 | Popular Tags |