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