KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > actions > RemoveAllTerminatedAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.actions;
12
13
14 import java.util.ArrayList JavaDoc;
15 import java.util.List JavaDoc;
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 /**
24  * Removes all terminated/detached launches from the
25  * active debug view.
26  */

27 public class RemoveAllTerminatedAction extends AbstractRemoveAllActionDelegate implements ILaunchesListener2 {
28
29     /* (non-Javadoc)
30      * @see org.eclipse.debug.internal.ui.actions.selection.AbstractRemoveAllActionDelegate#isEnabled()
31      */

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 JavaDoc removed = new ArrayList JavaDoc();
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     /* (non-Javadoc)
59      * @see org.eclipse.debug.internal.ui.actions.selection.AbstractRemoveAllActionDelegate#initialize()
60      */

61     protected void initialize() {
62         DebugPlugin.getDefault().getLaunchManager().addLaunchListener(this);
63     }
64         
65     /* (non-Javadoc)
66      * @see org.eclipse.debug.internal.ui.actions.selection.AbstractRemoveAllActionDelegate#dispose()
67      */

68     public void dispose() {
69         super.dispose();
70         DebugPlugin.getDefault().getLaunchManager().removeLaunchListener(this);
71     }
72
73     /* (non-Javadoc)
74      * @see org.eclipse.debug.core.ILaunchesListener#launchesAdded(org.eclipse.debug.core.ILaunch[])
75      */

76     public void launchesAdded(ILaunch[] launches) {
77     }
78
79     /* (non-Javadoc)
80      * @see org.eclipse.debug.core.ILaunchesListener#launchesChanged(org.eclipse.debug.core.ILaunch[])
81      */

82     public void launchesChanged(ILaunch[] launches) {
83     }
84
85     /* (non-Javadoc)
86      * @see org.eclipse.debug.core.ILaunchesListener#launchesRemoved(org.eclipse.debug.core.ILaunch[])
87      */

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     /* (non-Javadoc)
98      * @see org.eclipse.debug.core.ILaunchesListener2#launchesTerminated(org.eclipse.debug.core.ILaunch[])
99      */

100     public void launchesTerminated(ILaunch[] launches) {
101         update();
102     }
103
104     /* (non-Javadoc)
105      * @see org.eclipse.ui.IActionDelegate#run(org.eclipse.jface.action.IAction)
106      */

107     public void run(IAction action) {
108         ILaunch[] launches = DebugPlugin.getDefault().getLaunchManager().getLaunches();
109         removeTerminatedLaunches(launches);
110     }
111 }
112
113
Popular Tags