KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.context;
12
13  
14 import org.eclipse.debug.core.DebugPlugin;
15 import org.eclipse.debug.core.ILaunch;
16 import org.eclipse.debug.core.ILaunchManager;
17 import org.eclipse.debug.internal.ui.DebugPluginImages;
18 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
19 import org.eclipse.debug.internal.ui.actions.ActionMessages;
20 import org.eclipse.debug.internal.ui.actions.provisional.IAsynchronousTerminateAdapter;
21 import org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor;
22 import org.eclipse.jface.action.IAction;
23 import org.eclipse.jface.resource.ImageDescriptor;
24 import org.eclipse.jface.viewers.ISelection;
25 import org.eclipse.jface.viewers.IStructuredSelection;
26 import org.eclipse.jface.viewers.StructuredSelection;
27
28 /**
29  * Terminates all launches.
30  */

31 public class TerminateAllAction extends AbstractDebugContextAction {
32     
33
34     /*
35      * (non-Javadoc)
36      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#doAction(java.lang.Object)
37      */

38     protected void doAction(Object JavaDoc element) {
39         if (element instanceof ILaunch) {
40             ILaunch launch = (ILaunch) element;
41             if (!launch.isTerminated() && DebugPlugin.getDefault().getLaunchManager().isRegistered(launch)) {
42                 IAsynchronousTerminateAdapter killer = (IAsynchronousTerminateAdapter) launch.getAdapter(IAsynchronousTerminateAdapter.class);
43                 if (killer != null)
44                     killer.terminate(element, new ActionRequestMonitor());
45             }
46         }
47     }
48     
49     /*
50      * (non-Javadoc)
51      * @see org.eclipse.debug.internal.ui.actions.context.AbstractDebugContextAction#isEnabledFor(java.lang.Object, org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor)
52      */

53     protected void isEnabledFor(Object JavaDoc element, IBooleanRequestMonitor monitor) {
54         
55         //not really async here because we don't need to ask the target if the launch has terminated...
56
// will this ever be called??? update is overridden in this class...
57

58         if (element instanceof ILaunch) {
59             ILaunch launch = (ILaunch) element;
60             if (!launch.isTerminated() && DebugPlugin.getDefault().getLaunchManager().isRegistered(launch)) {
61                 monitor.setResult(true);
62             } else {
63                 monitor.setResult(false);
64             }
65         }
66         monitor.done();
67     }
68
69
70     /**
71      * Update the action enablement based on the launches present in
72      * the launch manager. selection is unused and can be <code>null</code>.
73      * @see org.eclipse.debug.internal.ui.actions.AbstractDebugActionDelegate#update(org.eclipse.jface.action.IAction, org.eclipse.jface.viewers.ISelection)
74      */

75     protected void update(IAction action, ISelection selection) {
76         ILaunchManager lManager= DebugPlugin.getDefault().getLaunchManager();
77         ILaunch[] launches= lManager.getLaunches();
78         for (int i= 0; i< launches.length; i++) {
79             ILaunch launch= launches[i];
80             if (!launch.isTerminated()) {
81                 action.setEnabled(true);
82                 return;
83             }
84         }
85         action.setEnabled(false);
86     }
87
88     protected IStructuredSelection getContext() {
89         return new StructuredSelection(DebugPlugin.getDefault().getLaunchManager().getLaunches());
90     }
91
92     public String JavaDoc getHelpContextId() {
93         return "terminate_all_action_context"; //$NON-NLS-1$
94
}
95
96     public String JavaDoc getId() {
97         return "org.eclipse.debug.ui.debugview.popupMenu.terminateAll"; //$NON-NLS-1$
98
}
99
100     public String JavaDoc getText() {
101         return ActionMessages.TerminateAllAction_2;
102     }
103
104     public String JavaDoc getToolTipText() {
105         return ActionMessages.TerminateAllAction_3;
106     }
107
108     public ImageDescriptor getDisabledImageDescriptor() {
109         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TERMINATE_ALL);
110     }
111
112     public ImageDescriptor getHoverImageDescriptor() {
113         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE_ALL);
114     }
115
116     public ImageDescriptor getImageDescriptor() {
117         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE_ALL);
118     }
119 }
120
Popular Tags