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.jface.action.IAction; 20 import org.eclipse.jface.viewers.ISelection; 21 import org.eclipse.jface.viewers.IStructuredSelection; 22 import org.eclipse.jface.viewers.StructuredSelection; 23 24 27 public class TerminateAllAction extends AbstractListenerActionDelegate { 28 29 32 protected void doAction(Object element) throws DebugException { 33 if (element instanceof ILaunch) { 34 ILaunch launch = (ILaunch) element; 35 if (!launch.isTerminated() && DebugPlugin.getDefault().getLaunchManager().isRegistered(launch)) { 36 launch.terminate(); 37 } 38 } 39 } 40 41 44 protected boolean isRunInBackground() { 45 return true; 46 } 47 48 53 protected void update(IAction action, ISelection selection) { 54 ILaunchManager lManager= DebugPlugin.getDefault().getLaunchManager(); 55 ILaunch[] launches= lManager.getLaunches(); 56 for (int i= 0; i< launches.length; i++) { 57 ILaunch launch= launches[i]; 58 if (!launch.isTerminated()) { 59 action.setEnabled(true); 60 return; 61 } 62 } 63 action.setEnabled(false); 64 } 65 66 69 public void selectionChanged(IAction action, ISelection selection) { 70 setAction(action); 71 } 72 73 76 protected void doHandleDebugEvent(DebugEvent event) { 77 switch (event.getKind()) { 78 case DebugEvent.TERMINATE : 79 update(getAction(), null); 80 break; 81 case DebugEvent.CREATE : 82 update(getAction(), null); 83 break; 84 } 85 } 86 87 90 protected IStructuredSelection getSelection() { 91 return new StructuredSelection(DebugPlugin.getDefault().getLaunchManager().getLaunches()); 92 } 93 94 95 } 96 | Popular Tags |