deleted dependency from net.sourceforge.phpeclipse module
[phpeclipse.git] / net.sourceforge.phpeclipse.externaltools / src / net / sourceforge / phpdt / externaltools / launchConfigurations / ExternalToolsMainTab.java
1 package net.sourceforge.phpdt.externaltools.launchConfigurations;
2
3 /***********************************************************************************************************************************
4  * Copyright (c) 2000, 2002 IBM Corp. All rights reserved. This file is made available under the terms of the Common Public License
5  * v1.0 which accompanies this distribution, and is available at http://www.eclipse.org/legal/cpl-v10.html
6  **********************************************************************************************************************************/
7
8 import java.io.File;
9
10 import net.sourceforge.phpdt.externaltools.group.IGroupDialogPage;
11 import net.sourceforge.phpdt.externaltools.internal.dialog.ExternalToolVariableForm;
12 import net.sourceforge.phpdt.externaltools.internal.model.ExternalToolsImages;
13 import net.sourceforge.phpdt.externaltools.internal.registry.ExternalToolVariable;
14 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
15 import net.sourceforge.phpdt.externaltools.model.ToolUtil;
16 import net.sourceforge.phpdt.externaltools.variable.ExpandVariableContext;
17 import net.sourceforge.phpeclipse.externaltools.ExternalToolsPlugin;
18
19 import org.eclipse.core.resources.IResource;
20 import org.eclipse.core.resources.ResourcesPlugin;
21 import org.eclipse.core.runtime.CoreException;
22 import org.eclipse.core.runtime.IPath;
23 import org.eclipse.core.runtime.IStatus;
24 import org.eclipse.core.runtime.MultiStatus;
25 import org.eclipse.debug.core.ILaunchConfiguration;
26 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
27 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
28 import org.eclipse.debug.ui.ILaunchConfigurationTab;
29 import org.eclipse.jface.dialogs.IDialogConstants;
30 import org.eclipse.jface.dialogs.IMessageProvider;
31 import org.eclipse.jface.preference.IPreferenceStore;
32 import org.eclipse.swt.SWT;
33 import org.eclipse.swt.events.ModifyEvent;
34 import org.eclipse.swt.events.ModifyListener;
35 import org.eclipse.swt.events.SelectionAdapter;
36 import org.eclipse.swt.events.SelectionEvent;
37 import org.eclipse.swt.events.SelectionListener;
38 import org.eclipse.swt.graphics.Font;
39 import org.eclipse.swt.graphics.Image;
40 import org.eclipse.swt.layout.GridData;
41 import org.eclipse.swt.layout.GridLayout;
42 import org.eclipse.swt.widgets.Button;
43 import org.eclipse.swt.widgets.Combo;
44 import org.eclipse.swt.widgets.Composite;
45 import org.eclipse.swt.widgets.Control;
46 import org.eclipse.swt.widgets.DirectoryDialog;
47 import org.eclipse.swt.widgets.FileDialog;
48 import org.eclipse.swt.widgets.Label;
49 import org.eclipse.swt.widgets.Shell;
50 import org.eclipse.swt.widgets.Text;
51 import org.eclipse.ui.dialogs.ContainerSelectionDialog;
52 import org.eclipse.ui.dialogs.ResourceSelectionDialog;
53 import org.eclipse.ui.dialogs.SelectionDialog;
54
55 public class ExternalToolsMainTab extends AbstractLaunchConfigurationTab {
56
57   protected Combo locationField;
58
59   protected Text workDirectoryField;
60
61   protected Button fileLocationButton;
62
63   protected Button workspaceLocationButton;
64
65   protected Button fileWorkingDirectoryButton;
66
67   protected Button workspaceWorkingDirectoryButton;
68
69   protected Button runBackgroundButton;
70
71   protected Text argumentField;
72
73   protected Button variableButton;
74
75   protected SelectionAdapter selectionAdapter;
76
77   protected ModifyListener modifyListener = new ModifyListener() {
78     public void modifyText(ModifyEvent e) {
79       updateLaunchConfigurationDialog();
80     }
81   };
82
83   /**
84    * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
85    */
86   public void createControl(Composite parent) {
87     Composite mainComposite = new Composite(parent, SWT.NONE);
88     setControl(mainComposite);
89     GridLayout layout = new GridLayout();
90     layout.numColumns = 2;
91     GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
92     mainComposite.setLayout(layout);
93     mainComposite.setLayoutData(gridData);
94     mainComposite.setFont(parent.getFont());
95     createLocationComponent(mainComposite);
96     createWorkDirectoryComponent(mainComposite);
97     createArgumentComponent(mainComposite);
98     createVerticalSpacer(mainComposite, 2);
99     createRunBackgroundComponent(mainComposite);
100   }
101
102   /**
103    * Creates the controls needed to edit the location attribute of an external tool
104    * 
105    * @param parent
106    *          the composite to create the controls in
107    */
108   protected void createLocationComponent(Composite parent) {
109     Font font = parent.getFont();
110
111     Composite composite = new Composite(parent, SWT.NONE);
112     GridLayout layout = new GridLayout();
113     layout.marginWidth = 0;
114     layout.marginHeight = 0;
115     layout.numColumns = 1;
116     GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
117     composite.setLayout(layout);
118     composite.setLayoutData(gridData);
119
120     Label label = new Label(composite, SWT.NONE);
121     label.setText(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsMainTab.&Location___2")); //$NON-NLS-1$
122     label.setFont(font);
123
124     final IPreferenceStore store = ExternalToolsPlugin.getDefault().getPreferenceStore();
125     locationField = new Combo(composite, SWT.DROP_DOWN | SWT.BORDER);
126     GridData data = new GridData(GridData.FILL_HORIZONTAL);
127     data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
128     locationField.setLayoutData(data);
129     locationField.setFont(font);
130     locationField.add(store.getString(ExternalToolsPlugin.PHP_RUN_PREF), 0);
131     locationField.add(store.getString(ExternalToolsPlugin.APACHE_RUN_PREF), 1);
132     locationField.add(store.getString(ExternalToolsPlugin.MYSQL_RUN_PREF), 2);
133     locationField.add(store.getString(ExternalToolsPlugin.XAMPP_START_PREF), 3);
134     locationField.add(store.getString(ExternalToolsPlugin.XAMPP_STOP_PREF), 4);
135     Composite buttonComposite = new Composite(parent, SWT.NONE);
136     layout = new GridLayout();
137     layout.marginWidth = 0;
138     layout.marginHeight = 0;
139     layout.numColumns = 1;
140     gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
141     buttonComposite.setLayout(layout);
142     buttonComposite.setLayoutData(gridData);
143     buttonComposite.setFont(font);
144
145     createVerticalSpacer(buttonComposite, 1);
146
147     workspaceLocationButton = createPushButton(buttonComposite, ExternalToolsLaunchConfigurationMessages
148         .getString("ExternalToolsMainTab.&Browse_Workspace..._3"), null); //$NON-NLS-1$
149     workspaceLocationButton.addSelectionListener(new SelectionAdapter() {
150       public void widgetSelected(SelectionEvent evt) {
151         handleWorkspaceLocationButtonSelected();
152       }
153     });
154     fileLocationButton = createPushButton(buttonComposite, ExternalToolsLaunchConfigurationMessages
155         .getString("ExternalToolsMainTab.Brows&e_File_System..._4"), null); //$NON-NLS-1$
156     fileLocationButton.addSelectionListener(new SelectionAdapter() {
157       public void widgetSelected(SelectionEvent evt) {
158         handleLocationButtonSelected();
159       }
160     });
161   }
162
163   /**
164    * Creates the controls needed to edit the working directory attribute of an external tool
165    * 
166    * @param parent
167    *          the composite to create the controls in
168    */
169   protected void createWorkDirectoryComponent(Composite parent) {
170     Font font = parent.getFont();
171
172     Composite composite = new Composite(parent, SWT.NONE);
173     GridLayout layout = new GridLayout();
174     layout.marginWidth = 0;
175     layout.marginHeight = 0;
176     layout.numColumns = 1;
177     GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
178     composite.setLayout(layout);
179     composite.setLayoutData(gridData);
180
181     Label label = new Label(composite, SWT.NONE);
182     label.setText(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsMainTab.Working_&Directory__5")); //$NON-NLS-1$
183     label.setFont(font);
184
185     workDirectoryField = new Text(composite, SWT.BORDER);
186     GridData data = new GridData(GridData.FILL_HORIZONTAL);
187     data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
188     workDirectoryField.setLayoutData(data);
189     workDirectoryField.setFont(font);
190
191     Composite buttonComposite = new Composite(parent, SWT.NONE);
192     layout = new GridLayout();
193     layout.marginWidth = 0;
194     layout.marginHeight = 0;
195     layout.numColumns = 1;
196     gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
197     buttonComposite.setLayout(layout);
198     buttonComposite.setLayoutData(gridData);
199     buttonComposite.setFont(font);
200
201     createVerticalSpacer(buttonComposite, 1);
202     workspaceWorkingDirectoryButton = createPushButton(buttonComposite, ExternalToolsLaunchConfigurationMessages
203         .getString("ExternalToolsMainTab.Browse_Wor&kspace..._6"), null); //$NON-NLS-1$
204     workspaceWorkingDirectoryButton.addSelectionListener(new SelectionAdapter() {
205       public void widgetSelected(SelectionEvent evt) {
206         handleWorkspaceWorkingDirectoryButtonSelected();
207       }
208     });
209     fileWorkingDirectoryButton = createPushButton(buttonComposite, ExternalToolsLaunchConfigurationMessages
210         .getString("ExternalToolsMainTab.Browse_F&ile_System..._7"), null); //$NON-NLS-1$
211     fileWorkingDirectoryButton.addSelectionListener(new SelectionAdapter() {
212       public void widgetSelected(SelectionEvent evt) {
213         handleFileWorkingDirectoryButtonSelected();
214       }
215     });
216   }
217
218   /**
219    * Creates the controls needed to edit the argument and prompt for argument attributes of an external tool
220    * 
221    * @param parent
222    *          the composite to create the controls in
223    */
224   protected void createArgumentComponent(Composite parent) {
225     Font font = parent.getFont();
226
227     Label label = new Label(parent, SWT.NONE);
228     label.setText(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsOptionTab.&Arguments___1")); //$NON-NLS-1$
229     GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
230     data.horizontalSpan = 2;
231     label.setLayoutData(data);
232     label.setFont(font);
233
234     argumentField = new Text(parent, SWT.BORDER);
235     data = new GridData(GridData.FILL_HORIZONTAL);
236     data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
237     argumentField.setLayoutData(data);
238     argumentField.setFont(font);
239     argumentField.addModifyListener(new ModifyListener() {
240       public void modifyText(ModifyEvent e) {
241         updateLaunchConfigurationDialog();
242       }
243     });
244
245     variableButton = createPushButton(parent, ExternalToolsLaunchConfigurationMessages
246         .getString("ExternalToolsOptionTab.Varia&bles..._2"), null); //$NON-NLS-1$
247     variableButton.addSelectionListener(new SelectionAdapter() {
248       public void widgetSelected(SelectionEvent e) {
249         VariableSelectionDialog dialog = new VariableSelectionDialog(getShell());
250         if (dialog.open() == SelectionDialog.OK) {
251           argumentField.insert(dialog.getForm().getSelectedVariable());
252         }
253       }
254     });
255
256     Label instruction = new Label(parent, SWT.NONE);
257     instruction
258         .setText(ExternalToolsLaunchConfigurationMessages
259             .getString("ExternalToolsOptionTab.Note__Enclose_an_argument_containing_spaces_using_double-quotes_(__)._Not_applicable_for_variables._3")); //$NON-NLS-1$
260     data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
261     data.horizontalSpan = 2;
262     instruction.setLayoutData(data);
263     instruction.setFont(font);
264   }
265
266   /**
267    * Creates the controls needed to edit the run in background attribute of an external tool
268    * 
269    * @param parent
270    *          the composite to create the controls in
271    */
272   protected void createRunBackgroundComponent(Composite parent) {
273     runBackgroundButton = new Button(parent, SWT.CHECK);
274     runBackgroundButton.setText(ExternalToolsLaunchConfigurationMessages
275         .getString("ExternalToolsOptionTab.Run_tool_in_bac&kground_4")); //$NON-NLS-1$
276     GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
277     runBackgroundButton.setLayoutData(data);
278     runBackgroundButton.setFont(parent.getFont());
279     runBackgroundButton.addSelectionListener(getSelectionAdapter());
280   }
281
282   /**
283    * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
284    */
285   public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
286     configuration.setAttribute(IExternalToolConstants.ATTR_RUN_IN_BACKGROUND, false);
287   }
288
289   /**
290    * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
291    */
292   public void initializeFrom(ILaunchConfiguration configuration) {
293     updateLocation(configuration);
294     updateWorkingDirectory(configuration);
295     updateArgument(configuration);
296     updateRunBackground(configuration);
297   }
298
299   protected void updateWorkingDirectory(ILaunchConfiguration configuration) {
300     String workingDir = ""; //$NON-NLS-1$
301     try {
302       workingDir = configuration.getAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, ""); //$NON-NLS-1$
303     } catch (CoreException ce) {
304       ExternalToolsPlugin.getDefault().log(
305           ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsMainTab.Error_reading_configuration_10"), ce); //$NON-NLS-1$
306     }
307     workDirectoryField.setText(workingDir);
308     workDirectoryField.addModifyListener(modifyListener);
309
310   }
311
312   protected void updateLocation(ILaunchConfiguration configuration) {
313     String location = ""; //$NON-NLS-1$
314     try {
315       location = configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, ""); //$NON-NLS-1$
316     } catch (CoreException ce) {
317       ExternalToolsPlugin.getDefault().log(
318           ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsMainTab.Error_reading_configuration_10"), ce); //$NON-NLS-1$
319     }
320     locationField.setText(location);
321     locationField.addModifyListener(modifyListener);
322   }
323
324   protected void updateArgument(ILaunchConfiguration configuration) {
325     String arguments = ""; //$NON-NLS-1$
326     try {
327       arguments = configuration.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, ""); //$NON-NLS-1$
328     } catch (CoreException ce) {
329       ExternalToolsPlugin.getDefault().log(
330           ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsOptionTab.Error_reading_configuration_7"), ce); //$NON-NLS-1$
331     }
332     argumentField.setText(arguments);
333   }
334
335   protected void updateRunBackground(ILaunchConfiguration configuration) {
336     boolean runInBackgroud = true;
337     try {
338       runInBackgroud = configuration.getAttribute(IExternalToolConstants.ATTR_RUN_IN_BACKGROUND, false);
339     } catch (CoreException ce) {
340       ExternalToolsPlugin.getDefault().log(
341           ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsOptionTab.Error_reading_configuration_7"), ce); //$NON-NLS-1$
342     }
343     runBackgroundButton.setSelection(runInBackgroud);
344   }
345
346   /**
347    * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
348    */
349   public void performApply(ILaunchConfigurationWorkingCopy configuration) {
350     String location = locationField.getText().trim();
351     if (location.length() == 0) {
352       configuration.setAttribute(IExternalToolConstants.ATTR_LOCATION, (String) null);
353     } else {
354       configuration.setAttribute(IExternalToolConstants.ATTR_LOCATION, location);
355     }
356
357     String workingDirectory = workDirectoryField.getText().trim();
358     if (workingDirectory.length() == 0) {
359       configuration.setAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, (String) null);
360     } else {
361       configuration.setAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, workingDirectory);
362     }
363
364     setAttribute(IExternalToolConstants.ATTR_RUN_IN_BACKGROUND, configuration, runBackgroundButton.getSelection(), false);
365
366     String arguments = argumentField.getText().trim();
367     if (arguments.length() == 0) {
368       configuration.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, (String) null);
369     } else {
370       configuration.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, arguments);
371     }
372   }
373
374   /**
375    * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
376    */
377   public String getName() {
378     return ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsMainTab.&Main_17"); //$NON-NLS-1$
379   }
380
381   /**
382    * @see ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
383    */
384   public boolean isValid(ILaunchConfiguration launchConfig) {
385     setErrorMessage(null);
386     setMessage(null);
387     return validateLocation() && validateWorkDirectory();
388   }
389
390   /**
391    * Validates the content of the location field.
392    */
393   protected boolean validateLocation() {
394     String value = locationField.getText().trim();
395     if (value.length() < 1) {
396       setErrorMessage(ExternalToolsLaunchConfigurationMessages
397           .getString("ExternalToolsMainTab.External_tool_location_cannot_be_empty_18")); //$NON-NLS-1$
398       setMessage(null);
399       return false;
400     }
401
402     // Translate field contents to the actual file location so we
403     // can check to ensure the file actually exists.
404     MultiStatus multiStatus = new MultiStatus(IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
405     value = ToolUtil.expandFileLocation(value, ExpandVariableContext.EMPTY_CONTEXT, multiStatus);
406     if (!multiStatus.isOK()) {
407       IStatus[] children = multiStatus.getChildren();
408       if (children.length > 0) {
409         setErrorMessage(children[0].getMessage());
410         setMessage(null);
411       }
412       return false;
413     }
414
415     File file = new File(value);
416     if (!file.exists()) { // The file does not exist.
417       setErrorMessage(ExternalToolsLaunchConfigurationMessages
418           .getString("ExternalToolsMainTab.External_tool_location_does_not_exist_19")); //$NON-NLS-1$
419       return false;
420     }
421     if (!file.isFile()) {
422       setErrorMessage(ExternalToolsLaunchConfigurationMessages
423           .getString("ExternalToolsMainTab.External_tool_location_specified_is_not_a_file_20")); //$NON-NLS-1$
424       return false;
425     }
426     return true;
427   }
428
429   /**
430    * Validates the content of the working directory field.
431    */
432   protected boolean validateWorkDirectory() {
433
434     String value = workDirectoryField.getText().trim();
435     if (value.length() > 0) {
436       // Translate field contents to the actual directory location so we
437       // can check to ensure the directory actually exists.
438       MultiStatus multiStatus = new MultiStatus(IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
439       value = ToolUtil.expandDirectoryLocation(value, ExpandVariableContext.EMPTY_CONTEXT, multiStatus);
440       if (!multiStatus.isOK()) {
441         IStatus[] children = multiStatus.getChildren();
442         if (children.length > 0) {
443           setErrorMessage(children[0].getMessage());
444         }
445         return false;
446       }
447
448       File file = new File(value);
449       if (!file.exists()) { // The directory does not exist.
450         setErrorMessage(ExternalToolsLaunchConfigurationMessages
451             .getString("ExternalToolsMainTab.External_tool_working_directory_does_not_exist_or_is_invalid_21")); //$NON-NLS-1$
452         return false;
453       }
454     }
455     return true;
456   }
457
458   protected void handleLocationButtonSelected() {
459     FileDialog fileDialog = new FileDialog(getShell(), SWT.NONE);
460     fileDialog.setFileName(locationField.getText());
461     String text = fileDialog.open();
462     if (text != null) {
463       locationField.setText(text);
464     }
465   }
466
467   /**
468    * Prompts the user for a workspace location within the workspace and sets the location as a String containing the workspace_loc
469    * variable or <code>null</code> if no location was obtained from the user.
470    */
471   protected void handleWorkspaceLocationButtonSelected() {
472     ResourceSelectionDialog dialog;
473     dialog = new ResourceSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(),
474         ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsMainTab.Select_a_resource_22")); //$NON-NLS-1$
475     dialog.open();
476     Object[] results = dialog.getResult();
477     if (results == null || results.length < 1) {
478       return;
479     }
480     IResource resource = (IResource) results[0];
481     StringBuffer buf = new StringBuffer();
482     ToolUtil.buildVariableTag(IExternalToolConstants.VAR_WORKSPACE_LOC, resource.getFullPath().toString(), buf);
483     String text = buf.toString();
484     if (text != null) {
485       locationField.setText(text);
486     }
487   }
488
489   /**
490    * Prompts the user for a working directory location within the workspace and sets the working directory as a String containing
491    * the workspace_loc variable or <code>null</code> if no location was obtained from the user.
492    */
493   protected void handleWorkspaceWorkingDirectoryButtonSelected() {
494     ContainerSelectionDialog containerDialog;
495     containerDialog = new ContainerSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), false,
496         ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsMainTab.&Select_a_directory__23")); //$NON-NLS-1$
497     containerDialog.open();
498     Object[] resource = containerDialog.getResult();
499     String text = null;
500     if (resource != null && resource.length > 0) {
501       text = ToolUtil.buildVariableTag(IExternalToolConstants.VAR_RESOURCE_LOC, ((IPath) resource[0]).toString());
502     }
503     if (text != null) {
504       workDirectoryField.setText(text);
505     }
506   }
507
508   protected void handleFileWorkingDirectoryButtonSelected() {
509     DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SAVE);
510     dialog.setMessage(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsMainTab.&Select_a_directory__23")); //$NON-NLS-1$
511     dialog.setFilterPath(workDirectoryField.getText());
512     String text = dialog.open();
513     if (text != null) {
514       workDirectoryField.setText(text);
515     }
516   }
517
518   /**
519    * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
520    */
521   public Image getImage() {
522     return ExternalToolsImages.getImage(IExternalToolConstants.IMG_TAB_MAIN);
523   }
524
525   /**
526    * Method getSelectionAdapter.
527    * 
528    * @return SelectionListener
529    */
530   protected SelectionListener getSelectionAdapter() {
531     if (selectionAdapter == null) {
532       selectionAdapter = new SelectionAdapter() {
533         public void widgetSelected(SelectionEvent e) {
534           updateLaunchConfigurationDialog();
535         }
536       };
537     }
538     return selectionAdapter;
539   }
540
541   private class VariableSelectionDialog extends SelectionDialog {
542     private ExternalToolVariableForm form;
543
544     private VariableSelectionDialog(Shell parent) {
545       super(parent);
546       setTitle(ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsOptionTab.Select_variable_10")); //$NON-NLS-1$
547     }
548
549     protected Control createDialogArea(Composite parent) {
550       // Create the dialog area
551       Composite composite = (Composite) super.createDialogArea(parent);
552       ExternalToolVariable[] variables = ExternalToolsPlugin.getDefault().getArgumentVariableRegistry().getArgumentVariables();
553       form = new ExternalToolVariableForm(ExternalToolsLaunchConfigurationMessages
554           .getString("ExternalToolsOptionTab.&Choose_a_variable__11"), variables); //$NON-NLS-1$
555       form.createContents(composite, new IGroupDialogPage() {
556         public GridData setButtonGridData(Button button) {
557           GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
558           data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
559           int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
560           data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x);
561           button.setLayoutData(data);
562           return data;
563         }
564
565         public void setMessage(String newMessage, int newType) {
566           VariableSelectionDialog.this.setMessage(newMessage);
567         }
568
569         public void updateValidState() {
570         }
571
572         public int convertHeightHint(int chars) {
573           return convertHeightInCharsToPixels(chars);
574         }
575
576         public String getMessage() {
577           if (!form.isValid()) {
578             return ExternalToolsLaunchConfigurationMessages.getString("ExternalToolsOptionTab.Invalid_selection_12"); //$NON-NLS-1$
579           }
580           return null;
581         }
582
583         public int getMessageType() {
584           if (!form.isValid()) {
585             return IMessageProvider.ERROR;
586           }
587           return 0;
588         }
589       });
590       return composite;
591     }
592
593     private ExternalToolVariableForm getForm() {
594       return form;
595     }
596   }
597
598 }