KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*******************************************************************************
2  * Copyright (c) 2004, 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 implementation
10  *******************************************************************************/

11 package org.eclipse.debug.internal.ui.commands.actions;
12
13 import org.eclipse.debug.core.ILaunch;
14 import org.eclipse.debug.core.ILaunchConfiguration;
15 import org.eclipse.debug.core.IRequest;
16 import org.eclipse.debug.core.commands.ITerminateHandler;
17 import org.eclipse.debug.internal.ui.DebugPluginImages;
18 import org.eclipse.debug.internal.ui.DebugUIPlugin;
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.RelaunchActionDelegate;
22 import org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationManager;
23 import org.eclipse.debug.ui.contexts.DebugContextEvent;
24 import org.eclipse.jface.resource.ImageDescriptor;
25 import org.eclipse.jface.viewers.ISelection;
26 import org.eclipse.jface.viewers.IStructuredSelection;
27
28 /**
29  * Action which terminates a launch and then re-launches it.
30  */

31 public class TerminateAndRelaunchAction extends DebugCommandAction {
32     
33     class Particiapnt implements ICommandParticipant {
34         
35         private Object JavaDoc[] fTargets;
36
37         public Particiapnt(Object JavaDoc[] targets) {
38             fTargets = targets;
39         }
40
41         /* (non-Javadoc)
42          * @see org.eclipse.debug.internal.ui.commands.actions.ICommandParticipant#requestDone(org.eclipse.debug.core.commands.IRequest)
43          */

44         public void requestDone(IRequest request) {
45             if (request.getStatus() == null || request.getStatus().isOK()) {
46                 DebugUIPlugin.getStandardDisplay().asyncExec(new Runnable JavaDoc() {
47                     public void run() {
48                         // Must be run in the UI thread since the launch can require
49
// prompting to proceed
50
for (int i = 0; i < fTargets.length; i++) {
51                             ILaunch launch = RelaunchActionDelegate.getLaunch(fTargets[i]);
52                             RelaunchActionDelegate.relaunch(launch.getLaunchConfiguration(), launch.getLaunchMode());
53                         }
54                     }
55                 });
56             }
57         }
58         
59     }
60
61     protected ICommandParticipant getCommandParticipant(Object JavaDoc[] targets) {
62         return new Particiapnt(targets);
63     }
64
65     protected Class JavaDoc getCommandType() {
66         return ITerminateHandler.class;
67     }
68
69     public void debugContextChanged(DebugContextEvent event) {
70         ISelection context = event.getContext();
71         if (context instanceof IStructuredSelection) {
72             Object JavaDoc[] elements = ((IStructuredSelection)context).toArray();
73             for (int i = 0; i < elements.length; i++) {
74                 if (!canRelaunch(elements[i])) {
75                     setEnabled(false);
76                     return;
77                 }
78             }
79         }
80         super.debugContextChanged(event);
81     }
82
83     protected boolean canRelaunch(Object JavaDoc element) {
84         ILaunch launch = RelaunchActionDelegate.getLaunch(element);
85         if (launch != null) {
86             ILaunchConfiguration configuration = launch.getLaunchConfiguration();
87             if (configuration != null) {
88                 return LaunchConfigurationManager.isVisible(configuration);
89             }
90         }
91         return false;
92     }
93
94     public String JavaDoc getActionDefinitionId() {
95         return ActionMessages.TerminateAndRelaunchAction_0;
96     }
97
98     public String JavaDoc getHelpContextId() {
99         return "org.eclipse.debug.ui.terminate_and_relaunch_action_context"; //$NON-NLS-1$
100
}
101
102     public String JavaDoc getId() {
103         return "org.eclipse.debug.ui.debugview.popupMenu.TerminateAndRelaunch"; //$NON-NLS-1$
104
}
105
106     public String JavaDoc getText() {
107         return ActionMessages.TerminateAndRelaunchAction_3;
108     }
109
110     public String JavaDoc getToolTipText() {
111         return ActionMessages.TerminateAndRelaunchAction_4;
112     }
113
114     public ImageDescriptor getDisabledImageDescriptor() {
115         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_DLCL_TERMINATE_AND_RELAUNCH);
116     }
117
118     public ImageDescriptor getHoverImageDescriptor() {
119         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE_AND_RELAUNCH);
120     }
121
122     public ImageDescriptor getImageDescriptor() {
123         return DebugPluginImages.getImageDescriptor(IInternalDebugUIConstants.IMG_ELCL_TERMINATE_AND_RELAUNCH);
124     }
125 }
126
Popular Tags