1 11 package org.eclipse.debug.internal.ui.views.console; 12 13 import org.eclipse.debug.core.DebugPlugin; 14 import org.eclipse.debug.core.ILaunch; 15 import org.eclipse.debug.core.ILaunchManager; 16 import org.eclipse.debug.core.ILaunchesListener2; 17 import org.eclipse.debug.internal.ui.DebugPluginImages; 18 import org.eclipse.debug.internal.ui.IDebugHelpContextIds; 19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants; 20 import org.eclipse.debug.ui.IDebugUIConstants; 21 import org.eclipse.jface.action.Action; 22 import org.eclipse.jface.action.IAction; 23 import org.eclipse.jface.viewers.ISelection; 24 import org.eclipse.ui.IViewActionDelegate; 25 import org.eclipse.ui.IViewPart; 26 import org.eclipse.ui.PlatformUI; 27 import org.eclipse.ui.console.ConsolePlugin; 28 import org.eclipse.ui.console.IConsole; 29 import org.eclipse.ui.console.IConsoleListener; 30 import org.eclipse.ui.console.IConsoleView; 31 32 35 public class ConsoleRemoveLaunchAction extends Action implements IViewActionDelegate, IConsoleListener, ILaunchesListener2 { 36 37 private ILaunch fLaunch; 38 39 private IConsoleView fConsoleView; 41 42 public ConsoleRemoveLaunchAction() { 43 super(ConsoleMessages.ConsoleRemoveTerminatedAction_0); 44 setToolTipText(ConsoleMessages.ConsoleRemoveTerminatedAction_1); 45 PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.CONSOLE_REMOVE_LAUNCH); 46 setImageDescriptor(DebugPluginImages.getImageDescriptor(IDebugUIConstants.IMG_LCL_REMOVE)); 47 setDisabledImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_REMOVE)); 48 setHoverImageDescriptor(DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_REMOVE)); 49 DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); 50 ConsolePlugin.getDefault().getConsoleManager().addConsoleListener(this); 51 } 52 53 public ConsoleRemoveLaunchAction(ILaunch launch) { 54 this(); 55 fLaunch = launch; 56 update(); 57 } 58 59 public void dispose() { 60 DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this); 61 ConsolePlugin.getDefault().getConsoleManager().removeConsoleListener(this); 62 } 63 64 public synchronized void update() { 65 ILaunch launch = getLaunch(); 66 if (launch != null) { 67 setEnabled(launch.isTerminated()); 68 } else { 69 setEnabled(false); 70 } 71 } 72 73 public synchronized void run() { 74 ILaunch launch = getLaunch(); 75 if (launch != null) { 76 ILaunchManager launchManager = DebugPlugin.getDefault().getLaunchManager(); 77 launchManager.removeLaunch(launch); 78 } 79 } 80 81 public void init(IViewPart view) { 82 if (view instanceof IConsoleView) { 83 fConsoleView = (IConsoleView) view; 84 } 85 update(); 86 } 87 88 public void run(IAction action) { 89 run(); 90 } 91 92 public void selectionChanged(IAction action, ISelection selection) { 93 } 94 95 public void consolesAdded(IConsole[] consoles) { 96 } 97 98 public void consolesRemoved(IConsole[] consoles) { 99 update(); 100 } 101 102 105 public void launchesTerminated(ILaunch[] launches) { 106 update(); 107 } 108 109 112 public void launchesRemoved(ILaunch[] launches) { 113 } 114 115 118 public void launchesAdded(ILaunch[] launches) { 119 } 120 121 124 public void launchesChanged(ILaunch[] launches) { 125 } 126 127 protected ILaunch getLaunch() { 128 if (fConsoleView == null) { 129 return fLaunch; 130 } 131 IConsole console = fConsoleView.getConsole(); 133 if (console instanceof ProcessConsole) { 134 ProcessConsole pconsole = (ProcessConsole) console; 135 return pconsole.getProcess().getLaunch(); 136 } 137 return null; 138 } 139 } 140 | Popular Tags |