KickJava   Java API By Example, From Geeks To Geeks.

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


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.actions;
12
13
14 import com.ibm.icu.text.MessageFormat;
15 import org.eclipse.core.runtime.CoreException;
16 import org.eclipse.core.runtime.IAdaptable;
17 import org.eclipse.debug.core.DebugPlugin;
18 import org.eclipse.debug.core.ILaunch;
19 import org.eclipse.debug.core.ILaunchConfiguration;
20 import org.eclipse.debug.core.model.IDebugElement;
21 import org.eclipse.debug.core.model.IProcess;
22 import org.eclipse.debug.internal.ui.DebugPluginImages;
23 import org.eclipse.debug.internal.ui.DebugUIPlugin;
24 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
25 import org.eclipse.debug.ui.DebugUITools;
26 import org.eclipse.debug.ui.ILaunchGroup;
27 import org.eclipse.jface.resource.ImageDescriptor;
28 import org.eclipse.jface.viewers.IStructuredSelection;
29 import org.eclipse.ui.PlatformUI;
30 import org.eclipse.ui.actions.SelectionListenerAction;
31
32 /**
33  * Opens the launch configuration dialog on a single launch configuration, based
34  * on the the launch associated with the selected element.
35  */

36 public class EditLaunchConfigurationAction extends SelectionListenerAction {
37     
38     private ILaunchConfiguration fConfiguration = null;
39     private String JavaDoc fMode = null;
40     private boolean fTerminated = false;
41
42     /**
43      * Constructs a new action.
44      */

45     public EditLaunchConfigurationAction() {
46         super(""); //$NON-NLS-1$
47
setEnabled(false);
48         PlatformUI.getWorkbench().getHelpSystem().setHelp(this, IDebugHelpContextIds.EDIT_LAUNCH_CONFIGURATION_ACTION);
49     }
50
51     /**
52      * @see org.eclipse.ui.actions.SelectionListenerAction#updateSelection(org.eclipse.jface.viewers.IStructuredSelection)
53      */

54     protected boolean updateSelection(IStructuredSelection selection) {
55         setLaunchConfiguration(null);
56         setMode(null);
57         if (selection.size() == 1) {
58             Object JavaDoc object = selection.getFirstElement();
59             ILaunch launch = null;
60             if (object instanceof IAdaptable) {
61                 launch = (ILaunch)((IAdaptable)object).getAdapter(ILaunch.class);
62             }
63             if (launch == null) {
64                 if (object instanceof ILaunch) {
65                     launch = (ILaunch)object;
66                 } else if (object instanceof IDebugElement) {
67                     launch = ((IDebugElement)object).getLaunch();
68                 } else if (object instanceof IProcess) {
69                     launch = ((IProcess)object).getLaunch();
70                 }
71             }
72             if (launch != null) {
73                 ILaunchConfiguration configuration = launch.getLaunchConfiguration();
74                 if (configuration != null) {
75                     try {
76                         // The DebugUIPlugin creates stand-in launches with copied configurations
77
// while a launch is waiting for a build. These copied configurations
78
// have an attribute that points to the config that the user is really
79
// launching.
80
String JavaDoc underlyingHandle = configuration.getAttribute(DebugUIPlugin.ATTR_LAUNCHING_CONFIG_HANDLE, ""); //$NON-NLS-1$
81
if (underlyingHandle.length() > 0) {
82                             ILaunchConfiguration underlyingConfig = DebugPlugin.getDefault().getLaunchManager().getLaunchConfiguration(underlyingHandle);
83                             if (underlyingConfig != null) {
84                                 configuration = underlyingConfig;
85                             }
86                         }
87                     } catch (CoreException e1) {
88                     }
89                     setLaunchConfiguration(configuration);
90                     setMode(launch.getLaunchMode());
91                     setIsTerminated(launch.isTerminated());
92                     setText(MessageFormat.format(ActionMessages.EditLaunchConfigurationAction_1, new String JavaDoc[]{configuration.getName()}));
93                     ImageDescriptor descriptor = null;
94                     try {
95                         descriptor = DebugPluginImages.getImageDescriptor(configuration.getType().getIdentifier());
96                     } catch (CoreException e) {
97                         DebugUIPlugin.log(e);
98                     }
99                     setImageDescriptor(descriptor);
100                 }
101             }
102         }
103         
104         // Disable the action if the launch config is private
105
ILaunchConfiguration config = getLaunchConfiguration();
106         if (config == null) {
107             return false;
108         }
109         return !DebugUITools.isPrivate(config);
110     }
111
112     protected void setLaunchConfiguration(ILaunchConfiguration configuration) {
113         fConfiguration = configuration;
114     }
115     
116     protected ILaunchConfiguration getLaunchConfiguration() {
117         return fConfiguration;
118     }
119     
120     protected void setMode(String JavaDoc mode) {
121         fMode = mode;
122     }
123     
124     protected String JavaDoc getMode() {
125         return fMode;
126     }
127     
128     protected boolean isTerminated() {
129         return fTerminated;
130     }
131     
132     protected void setIsTerminated(boolean terminated) {
133         fTerminated = terminated;
134     }
135     
136     /**
137      * @see org.eclipse.jface.action.IAction#run()
138      */

139     public void run() {
140         ILaunchGroup group = DebugUITools.getLaunchGroup(getLaunchConfiguration(), getMode());
141         if (group != null) {
142             if(isTerminated()) {
143                 DebugUITools.openLaunchConfigurationDialog(
144                     DebugUIPlugin.getShell(), getLaunchConfiguration(),
145                     group.getIdentifier(), null);
146             }
147             else {
148                 DebugUIPlugin.openLaunchConfigurationEditDialog(
149                         DebugUIPlugin.getShell(), getLaunchConfiguration(),
150                         group.getIdentifier(), null, false);
151             }
152         }
153     }
154
155 }
156
Popular Tags