KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 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 import org.eclipse.core.runtime.IAdaptable;
14 import org.eclipse.debug.core.DebugPlugin;
15 import org.eclipse.debug.core.ILaunch;
16 import org.eclipse.debug.core.model.IDebugElement;
17 import org.eclipse.debug.core.model.IProcess;
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.debug.internal.ui.actions.provisional.IAsynchronousTerminateAdapter;
22 import org.eclipse.debug.internal.ui.actions.provisional.IBooleanRequestMonitor;
23 import org.eclipse.jface.resource.ImageDescriptor;
24
25 public class TerminateAndRemoveAction extends AbstractDebugContextAction {
26
27     
28     class TerminateAndRemoveMonitor extends ActionRequestMonitor {
29         private Object JavaDoc fElement;
30         TerminateAndRemoveMonitor(Object JavaDoc element) {
31             fElement = element;
32         }
33         public void done() {
34             if(getStatus() == null) {
35                 ILaunch launch= null;
36                 
37                 if (fElement instanceof ILaunch) {
38                     launch= (ILaunch) fElement;
39                 } else if (fElement instanceof IDebugElement) {
40                     launch= ((IDebugElement) fElement).getLaunch();
41                 } else if (fElement instanceof IProcess) {
42                     launch= ((IProcess) fElement).getLaunch();
43                 }
44                 if (launch != null)
45                     DebugPlugin.getDefault().getLaunchManager().removeLaunch(launch);
46             }
47             super.done();
48         }
49         
50     }
51     protected void doAction(Object JavaDoc element) {
52         if (element instanceof IAdaptable) {
53             IAsynchronousTerminateAdapter adapter = (IAsynchronousTerminateAdapter) ((IAdaptable)element).getAdapter(IAsynchronousTerminateAdapter.class);
54             if (adapter != null)
55                 adapter.terminate(element, new TerminateAndRemoveMonitor(element));
56         }
57     }
58
59     
60     protected void isEnabledFor(Object JavaDoc element, IBooleanRequestMonitor monitor) {
61         if (element instanceof IAdaptable) {
62             IAsynchronousTerminateAdapter adapter = (IAsynchronousTerminateAdapter) ((IAdaptable)element).getAdapter(IAsynchronousTerminateAdapter.class);
63             if (adapter != null) {
64                 adapter.canTerminate(element, monitor);
65             } else {
66                 notSupported(monitor);
67             }
68         }
69     
70     }
71
72     protected String JavaDoc getStatusMessage() {
73         return ActionMessages.TerminateAndRemoveActionDelegate_Exceptions_occurred_attempting_to_terminate_and_remove_2;
74     }
75
76     protected String JavaDoc getErrorDialogMessage() {
77         return ActionMessages.TerminateAndRemoveActionDelegate_Terminate_and_remove_failed_1;
78     }
79
80     public String JavaDoc getText() {
81         return ActionMessages.TerminateAndRemoveAction_0;
82     }
83
84     public String JavaDoc getHelpContextId() {
85         return "terminate_and_remove_action_context"; //$NON-NLS-1$
86
}
87
88     public String JavaDoc getId() {
89         return "org.eclipse.debug.ui.debugview.popupMenu.terminateAndRemove"; //$NON-NLS-1$
90
}
91
92     public String JavaDoc getToolTipText() {
93         return ActionMessages.TerminateAndRemoveAction_3;
94     }
95
96     public ImageDescriptor getDisabledImageDescriptor() {
97         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TERMINATE_AND_REMOVE);
98     }
99
100     public ImageDescriptor getHoverImageDescriptor() {
101         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE_AND_REMOVE);
102     }
103
104     public ImageDescriptor getImageDescriptor() {
105         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE_AND_REMOVE);
106     }
107
108 }
109
Popular Tags