1 11 package org.eclipse.debug.internal.ui.actions; 12 13 14 import java.util.ArrayList ; 15 import java.util.List ; 16 17 import org.eclipse.debug.core.DebugPlugin; 18 import org.eclipse.debug.core.ILaunch; 19 import org.eclipse.debug.core.ILaunchManager; 20 import org.eclipse.debug.core.ILaunchesListener2; 21 import org.eclipse.jface.action.IAction; 22 23 27 public class RemoveAllTerminatedAction extends AbstractRemoveAllActionDelegate implements ILaunchesListener2 { 28 29 32 protected boolean isEnabled() { 33 ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); 34 if (launches != null) { 35 for (int i= 0; i < launches.length; i++) { 36 if (launches[i].isTerminated()) { 37 return true; 38 } 39 } 40 } 41 return false; 42 } 43 44 public static void removeTerminatedLaunches(ILaunch[] elements) { 45 List removed = new ArrayList (); 46 for (int i = 0; i < elements.length; i++) { 47 ILaunch launch = elements[i]; 48 if (launch.isTerminated()) { 49 removed.add(launch); 50 } 51 } 52 if (!removed.isEmpty()) { 53 ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager(); 54 manager.removeLaunches((ILaunch[])removed.toArray(new ILaunch[removed.size()])); 55 } 56 } 57 58 61 protected void initialize() { 62 DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this); 63 } 64 65 68 public void dispose() { 69 super.dispose(); 70 DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this); 71 } 72 73 76 public void launchesAdded(ILaunch[] launches) { 77 } 78 79 82 public void launchesChanged(ILaunch[] launches) { 83 } 84 85 88 public void launchesRemoved(ILaunch[] launches) { 89 IAction action = getAction(); 90 if (action != null) { 91 if (action.isEnabled()) { 92 update(); 93 } 94 } 95 } 96 97 100 public void launchesTerminated(ILaunch[] launches) { 101 update(); 102 } 103 104 107 public void run(IAction action) { 108 ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches(); 109 removeTerminatedLaunches(launches); 110 } 111 } 112 113 | Popular Tags |