KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > commands > actions > TerminateAllAction


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.commands.actions;
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.core.commands.ITerminateHandler;
18 import org.eclipse.debug.internal.ui.DebugPluginImages;
19 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
20 import org.eclipse.debug.internal.ui.actions.ActionMessages;
21 import org.eclipse.jface.resource.ImageDescriptor;
22 import org.eclipse.jface.viewers.ISelection;
23 import org.eclipse.jface.viewers.StructuredSelection;
24 import org.eclipse.ui.IWorkbenchPart;
25
26 /**
27  * Terminates all launches.
28  *
29  * @since 3.3
30  */

31 public class TerminateAllAction extends DebugCommandAction implements ILaunchesListener2 {
32         
33     protected ISelection getContext() {
34         return new StructuredSelection(getLaunchManager().getLaunches());
35     }
36     
37     public void contextActivated(ISelection context, IWorkbenchPart part) {
38         // DO NOTHING
39
}
40
41     public void contextChanged(ISelection context, IWorkbenchPart part) {
42         // DO NOTHING
43
}
44     
45     public void dispose() {
46         getLaunchManager().removeLaunchListener(this);
47         super.dispose();
48     }
49
50     public void init(IWorkbenchPart part) {
51         super.init(part);
52         ILaunchManager launchManager = getLaunchManager();
53         launchManager.addLaunchListener(this);
54         // heuristic... rather than updating all the time, just assume there's
55
// something that's not terminated.
56
setEnabled(launchManager.getLaunches().length > 0);
57     }
58
59     private ILaunchManager getLaunchManager() {
60         return DebugPlugin.getDefault().getLaunchManager();
61     }
62
63     public String JavaDoc getHelpContextId() {
64         return "org.eclipse.debug.ui.terminate_all_action_context"; //$NON-NLS-1$
65
}
66
67     public String JavaDoc getId() {
68         return "org.eclipse.debug.ui.debugview.popupMenu.terminateAll"; //$NON-NLS-1$
69
}
70
71     public String JavaDoc getText() {
72         return ActionMessages.TerminateAllAction_2;
73     }
74
75     public String JavaDoc getToolTipText() {
76         return ActionMessages.TerminateAllAction_3;
77     }
78
79     public ImageDescriptor getDisabledImageDescriptor() {
80         return DebugPluginImages
81                 .getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TERMINATE_ALL);
82     }
83
84     public ImageDescriptor getHoverImageDescriptor() {
85         return DebugPluginImages
86                 .getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE_ALL);
87     }
88
89     public ImageDescriptor getImageDescriptor() {
90         return DebugPluginImages
91                 .getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE_ALL);
92     }
93
94     protected Class JavaDoc getCommandType() {
95         return ITerminateHandler.class;
96     }
97
98     /* (non-Javadoc)
99      * @see org.eclipse.debug.core.ILaunchesListener2#launchesTerminated(org.eclipse.debug.core.ILaunch[])
100      */

101     public void launchesTerminated(ILaunch[] launches) {
102     }
103
104     /* (non-Javadoc)
105      * @see org.eclipse.debug.core.ILaunchesListener#launchesAdded(org.eclipse.debug.core.ILaunch[])
106      */

107     public void launchesAdded(ILaunch[] launches) {
108         setEnabled(true);
109     }
110
111     /* (non-Javadoc)
112      * @see org.eclipse.debug.core.ILaunchesListener#launchesChanged(org.eclipse.debug.core.ILaunch[])
113      */

114     public void launchesChanged(ILaunch[] launches) {
115     }
116
117     /* (non-Javadoc)
118      * @see org.eclipse.debug.core.ILaunchesListener#launchesRemoved(org.eclipse.debug.core.ILaunch[])
119      */

120     public void launchesRemoved(ILaunch[] launches) {
121         setEnabled(getLaunchManager().getLaunches().length > 0);
122     }
123 }
124
Popular Tags