KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > LaunchConfigurationPropertiesDialog


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.launchConfigurations;
12
13
14 import java.util.Set JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IStatus;
18 import org.eclipse.debug.core.DebugPlugin;
19 import org.eclipse.debug.core.ILaunchConfiguration;
20 import org.eclipse.debug.core.ILaunchConfigurationListener;
21 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
22 import org.eclipse.debug.core.ILaunchManager;
23 import org.eclipse.debug.internal.ui.DebugUIPlugin;
24 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
25 import org.eclipse.debug.ui.IDebugUIConstants;
26 import org.eclipse.debug.ui.ILaunchConfigurationDialog;
27 import org.eclipse.debug.ui.ILaunchConfigurationTab;
28 import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
29 import org.eclipse.jface.dialogs.IDialogConstants;
30 import org.eclipse.swt.SWT;
31 import org.eclipse.swt.layout.GridData;
32 import org.eclipse.swt.layout.GridLayout;
33 import org.eclipse.swt.widgets.Composite;
34 import org.eclipse.swt.widgets.Shell;
35
36 import com.ibm.icu.text.MessageFormat;
37  
38
39 /**
40  * A dialog used to edit a single launch configuration.
41  */

42 public class LaunchConfigurationPropertiesDialog extends LaunchConfigurationsDialog implements ILaunchConfigurationListener {
43     
44     /**
45      * The launch configuration to display
46      */

47     private ILaunchConfiguration fLaunchConfiguration;
48     
49     /**
50      * Whether to set default values when opened
51      * @since 3.3
52      */

53     private boolean fSetDefaultOnOpen = false;
54
55     /**
56      * Constructs a new launch configuration dialog on the given
57      * parent shell.
58      *
59      * @param shell the parent shell
60      * @param selection the selection used to initialize this dialog, typically the
61      * current workbench selection
62      * @param group launch group
63      */

64     public LaunchConfigurationPropertiesDialog(Shell shell, ILaunchConfiguration launchConfiguration, LaunchGroupExtension group) {
65         super(shell, group);
66         fLaunchConfiguration = launchConfiguration;
67         DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(this);
68     }
69     
70     /**
71      * Constructs a new launch configuration dialog on the given
72      * parent shell.
73      *
74      * @param shell the parent shell
75      * @param selection the selection used to initialize this dialog, typically the
76      * current workbench selection
77      * @param reservednames a set of names of virtual launch configurations that need to be considered
78      * when configuration names are generated
79      * @param group launch group
80      */

81     public LaunchConfigurationPropertiesDialog(Shell shell, ILaunchConfiguration launchConfiguration, LaunchGroupExtension group, Set JavaDoc reservednames) {
82         super(shell, group);
83         fLaunchConfiguration = launchConfiguration;
84         DebugPlugin.getDefault().getLaunchManager().addLaunchConfigurationListener(this);
85         fReservedNames = reservednames;
86     }
87     
88     /**
89      * Returns the launch configuration being displayed.
90      *
91      * @return ILaunchConfiguration
92      */

93     protected ILaunchConfiguration getLaunchConfiguration() {
94         return fLaunchConfiguration;
95     }
96
97     /* (non-Javadoc)
98      * @see org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog#initializeBounds()
99      */

100     protected void initializeBounds() {
101         super.initializeBounds();
102         resize();
103     }
104
105     /* (non-Javadoc)
106      * @see org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog#initializeContent()
107      */

108     protected void initializeContent() {
109         ILaunchConfiguration launchConfiguration = getLaunchConfiguration();
110         if (fSetDefaultOnOpen && launchConfiguration instanceof ILaunchConfigurationWorkingCopy) {
111             ILaunchConfigurationWorkingCopy wc = (ILaunchConfigurationWorkingCopy) launchConfiguration;
112             try {
113                 ILaunchConfigurationTabGroup tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(wc, getMode());
114                 // this only works because this action is only present when the dialog is open
115
ILaunchConfigurationDialog dialog = LaunchConfigurationsDialog.getCurrentlyVisibleLaunchConfigurationDialog();
116                 tabGroup.createTabs(dialog, dialog.getMode());
117                 ILaunchConfigurationTab[] tabs = tabGroup.getTabs();
118                 for (int i = 0; i < tabs.length; i++) {
119                     tabs[i].setLaunchConfigurationDialog(dialog);
120                 }
121                 tabGroup.setDefaults(wc);
122                 tabGroup.dispose();
123             } catch (CoreException e) {
124                 DebugUIPlugin.log(e.getStatus());
125             }
126         }
127         getTabViewer().setInput(launchConfiguration);
128         IStatus status = getInitialStatus();
129         if (status != null) {
130             handleStatus(status);
131         }
132     }
133     
134     /* (non-Javadoc)
135      * @see org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog#close()
136      */

137     public boolean close() {
138         if (!isSafeToClose()) {
139             return false;
140         }
141         getBannerImage().dispose();
142         getTabViewer().dispose();
143         DebugPlugin.getDefault().getLaunchManager().removeLaunchConfigurationListener(this);
144         return super.close();
145     }
146         
147     /* (non-Javadoc)
148      * @see org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog#addContent(org.eclipse.swt.widgets.Composite)
149      */

150     protected void addContent(Composite dialogComp) {
151         GridData gd;
152         Composite topComp = new Composite(dialogComp, SWT.NONE);
153         gd = new GridData(GridData.FILL_BOTH);
154         topComp.setLayoutData(gd);
155         GridLayout topLayout = new GridLayout();
156         topLayout.numColumns = 1;
157         topLayout.marginHeight = 5;
158         topLayout.marginWidth = 5;
159         topComp.setLayout(topLayout);
160         topComp.setFont(dialogComp.getFont());
161     
162         // Set the things that TitleAreaDialog takes care of
163
setTitle(getTitleAreaTitle());
164         setMessage(""); //$NON-NLS-1$
165
setModeLabelState();
166     
167         // Build the launch configuration edit area and put it into the composite.
168
Composite editAreaComp = createLaunchConfigurationEditArea(topComp);
169         gd = new GridData(GridData.FILL_BOTH);
170         editAreaComp.setLayoutData(gd);
171         editAreaComp.setFont(dialogComp.getFont());
172         
173         dialogComp.layout(true);
174         applyDialogFont(dialogComp);
175     }
176     
177     /**
178      * returns the title area title of the dialog
179      * @return the title area title
180      */

181     protected String JavaDoc getTitleAreaTitle() {
182         return LaunchConfigurationsMessages.LaunchConfigurationPropertiesDialog_Edit_launch_configuration_properties_1;
183     }
184             
185     /* (non-Javadoc)
186      * @see org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
187      */

188     protected void createButtonsForButtonBar(Composite parent) {
189         // create OK and Cancel buttons by default
190
createButton(parent, IDialogConstants.OK_ID, IDialogConstants.OK_LABEL, true);
191         createButton(parent, IDialogConstants.CANCEL_ID, IDialogConstants.CANCEL_LABEL, false);
192     }
193                     
194     /* (non-Javadoc)
195      * @see org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog#getShellTitle()
196      */

197     protected String JavaDoc getShellTitle() {
198         return MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationPropertiesDialog_Properties_for__0__2, new String JavaDoc[]{getLaunchConfiguration().getName()});
199     }
200     
201     /* (non-Javadoc)
202      * @see org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog#getHelpContextId()
203      */

204     protected String JavaDoc getHelpContextId() {
205         return IDebugHelpContextIds.LAUNCH_CONFIGURATION_PROPERTIES_DIALOG;
206     }
207         
208     /* (non-Javadoc)
209      * @see org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog#updateButtons()
210      */

211     public void updateButtons() {
212         getTabViewer().refresh();
213         getButton(IDialogConstants.OK_ID).setEnabled(getTabViewer().canSave());
214         
215     }
216     
217     /* (non-Javadoc)
218      * @see org.eclipse.jface.dialogs.Dialog#okPressed()
219      */

220     protected void okPressed() {
221         getTabViewer().handleApplyPressed();
222         super.okPressed();
223     }
224
225     /* (non-Javadoc)
226      * @see org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog#open()
227      */

228     public int open() {
229         setOpenMode(-1);
230         return super.open();
231     }
232
233     /* (non-Javadoc)
234      * @see org.eclipse.debug.internal.ui.launchConfigurations.LaunchConfigurationsDialog#getDialogSettingsSectionName()
235      */

236     protected String JavaDoc getDialogSettingsSectionName() {
237         return IDebugUIConstants.PLUGIN_ID + ".LAUNCH_CONFIGURATION_PROPERTIES_DIALOG_SECTION"; //$NON-NLS-1$
238
}
239
240     /* (non-Javadoc)
241      * @see org.eclipse.debug.core.ILaunchConfigurationListener#launchConfigurationAdded(org.eclipse.debug.core.ILaunchConfiguration)
242      */

243     public void launchConfigurationAdded(ILaunchConfiguration configuration) {
244         ILaunchManager manager = DebugPlugin.getDefault().getLaunchManager();
245         if (getLaunchConfiguration().equals(manager.getMovedFrom(configuration))) {
246             // this config was re-named, update the dialog with the new config
247
fLaunchConfiguration = configuration;
248             getTabViewer().setInput(getLaunchConfiguration());
249         }
250     }
251
252     /* (non-Javadoc)
253      * @see org.eclipse.debug.core.ILaunchConfigurationListener#launchConfigurationChanged(org.eclipse.debug.core.ILaunchConfiguration)
254      */

255     public void launchConfigurationChanged(ILaunchConfiguration configuration) {}
256
257     /* (non-Javadoc)
258      * @see org.eclipse.debug.core.ILaunchConfigurationListener#launchConfigurationRemoved(org.eclipse.debug.core.ILaunchConfiguration)
259      */

260     public void launchConfigurationRemoved(ILaunchConfiguration configuration) {}
261     
262     /**
263      * Sets whether the tab group should set default values in the launch configuration
264      * when the dialog is opened. If this method is not called, default values are not
265      * set.
266      *
267      * @param setDefaults whether to set default values
268      */

269     public void setDefaultsOnOpen(boolean setDefaults) {
270         fSetDefaultOnOpen = setDefaults;
271     }
272
273 }
274
Popular Tags