1) Fixed breakpoint with skip count (or hit count).
[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
104          * 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
123                                 .getString("ExternalToolsMainTab.&Location___2")); //$NON-NLS-1$
124                 label.setFont(font);
125
126                 final IPreferenceStore store = ExternalToolsPlugin.getDefault()
127                                 .getPreferenceStore();
128                 locationField = new Combo(composite, SWT.DROP_DOWN | SWT.BORDER);
129                 GridData data = new GridData(GridData.FILL_HORIZONTAL);
130                 data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
131                 locationField.setLayoutData(data);
132                 locationField.setFont(font);
133                 locationField.add(store.getString(ExternalToolsPlugin.PHP_RUN_PREF), 0);
134                 locationField.add(store.getString(ExternalToolsPlugin.APACHE_RUN_PREF),
135                                 1);
136                 locationField.add(store.getString(ExternalToolsPlugin.MYSQL_RUN_PREF),
137                                 2);
138                 locationField.add(
139                                 store.getString(ExternalToolsPlugin.XAMPP_START_PREF), 3);
140                 locationField.add(store.getString(ExternalToolsPlugin.XAMPP_STOP_PREF),
141                                 4);
142                 Composite buttonComposite = new Composite(parent, SWT.NONE);
143                 layout = new GridLayout();
144                 layout.marginWidth = 0;
145                 layout.marginHeight = 0;
146                 layout.numColumns = 1;
147                 gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
148                 buttonComposite.setLayout(layout);
149                 buttonComposite.setLayoutData(gridData);
150                 buttonComposite.setFont(font);
151
152                 createVerticalSpacer(buttonComposite, 1);
153
154                 workspaceLocationButton = createPushButton(
155                                 buttonComposite,
156                                 ExternalToolsLaunchConfigurationMessages
157                                                 .getString("ExternalToolsMainTab.&Browse_Workspace..._3"), null); //$NON-NLS-1$
158                 workspaceLocationButton.addSelectionListener(new SelectionAdapter() {
159                         public void widgetSelected(SelectionEvent evt) {
160                                 handleWorkspaceLocationButtonSelected();
161                         }
162                 });
163                 fileLocationButton = createPushButton(
164                                 buttonComposite,
165                                 ExternalToolsLaunchConfigurationMessages
166                                                 .getString("ExternalToolsMainTab.Brows&e_File_System..._4"), null); //$NON-NLS-1$
167                 fileLocationButton.addSelectionListener(new SelectionAdapter() {
168                         public void widgetSelected(SelectionEvent evt) {
169                                 handleLocationButtonSelected();
170                         }
171                 });
172         }
173
174         /**
175          * Creates the controls needed to edit the working directory attribute of an
176          * external tool
177          * 
178          * @param parent
179          *            the composite to create the controls in
180          */
181         protected void createWorkDirectoryComponent(Composite parent) {
182                 Font font = parent.getFont();
183
184                 Composite composite = new Composite(parent, SWT.NONE);
185                 GridLayout layout = new GridLayout();
186                 layout.marginWidth = 0;
187                 layout.marginHeight = 0;
188                 layout.numColumns = 1;
189                 GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
190                 composite.setLayout(layout);
191                 composite.setLayoutData(gridData);
192
193                 Label label = new Label(composite, SWT.NONE);
194                 label.setText(ExternalToolsLaunchConfigurationMessages
195                                 .getString("ExternalToolsMainTab.Working_&Directory__5")); //$NON-NLS-1$
196                 label.setFont(font);
197
198                 workDirectoryField = new Text(composite, SWT.BORDER);
199                 GridData data = new GridData(GridData.FILL_HORIZONTAL);
200                 data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
201                 workDirectoryField.setLayoutData(data);
202                 workDirectoryField.setFont(font);
203
204                 Composite buttonComposite = new Composite(parent, SWT.NONE);
205                 layout = new GridLayout();
206                 layout.marginWidth = 0;
207                 layout.marginHeight = 0;
208                 layout.numColumns = 1;
209                 gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
210                 buttonComposite.setLayout(layout);
211                 buttonComposite.setLayoutData(gridData);
212                 buttonComposite.setFont(font);
213
214                 createVerticalSpacer(buttonComposite, 1);
215                 workspaceWorkingDirectoryButton = createPushButton(
216                                 buttonComposite,
217                                 ExternalToolsLaunchConfigurationMessages
218                                                 .getString("ExternalToolsMainTab.Browse_Wor&kspace..._6"), null); //$NON-NLS-1$
219                 workspaceWorkingDirectoryButton
220                                 .addSelectionListener(new SelectionAdapter() {
221                                         public void widgetSelected(SelectionEvent evt) {
222                                                 handleWorkspaceWorkingDirectoryButtonSelected();
223                                         }
224                                 });
225                 fileWorkingDirectoryButton = createPushButton(
226                                 buttonComposite,
227                                 ExternalToolsLaunchConfigurationMessages
228                                                 .getString("ExternalToolsMainTab.Browse_F&ile_System..._7"), null); //$NON-NLS-1$
229                 fileWorkingDirectoryButton.addSelectionListener(new SelectionAdapter() {
230                         public void widgetSelected(SelectionEvent evt) {
231                                 handleFileWorkingDirectoryButtonSelected();
232                         }
233                 });
234         }
235
236         /**
237          * Creates the controls needed to edit the argument and prompt for argument
238          * attributes of an external tool
239          * 
240          * @param parent
241          *            the composite to create the controls in
242          */
243         protected void createArgumentComponent(Composite parent) {
244                 Font font = parent.getFont();
245
246                 Label label = new Label(parent, SWT.NONE);
247                 label.setText(ExternalToolsLaunchConfigurationMessages
248                                 .getString("ExternalToolsOptionTab.&Arguments___1")); //$NON-NLS-1$
249                 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
250                 data.horizontalSpan = 2;
251                 label.setLayoutData(data);
252                 label.setFont(font);
253
254                 argumentField = new Text(parent, SWT.BORDER);
255                 data = new GridData(GridData.FILL_HORIZONTAL);
256                 data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
257                 argumentField.setLayoutData(data);
258                 argumentField.setFont(font);
259                 argumentField.addModifyListener(new ModifyListener() {
260                         public void modifyText(ModifyEvent e) {
261                                 updateLaunchConfigurationDialog();
262                         }
263                 });
264
265                 variableButton = createPushButton(
266                                 parent,
267                                 ExternalToolsLaunchConfigurationMessages
268                                                 .getString("ExternalToolsOptionTab.Varia&bles..._2"), null); //$NON-NLS-1$
269                 variableButton.addSelectionListener(new SelectionAdapter() {
270                         public void widgetSelected(SelectionEvent e) {
271                                 VariableSelectionDialog dialog = new VariableSelectionDialog(
272                                                 getShell());
273                                 if (dialog.open() == SelectionDialog.OK) {
274                                         argumentField
275                                                         .insert(dialog.getForm().getSelectedVariable());
276                                 }
277                         }
278                 });
279
280                 Label instruction = new Label(parent, SWT.NONE);
281                 instruction
282                                 .setText(ExternalToolsLaunchConfigurationMessages
283                                                 .getString("ExternalToolsOptionTab.Note__Enclose_an_argument_containing_spaces_using_double-quotes_(__)._Not_applicable_for_variables._3")); //$NON-NLS-1$
284                 data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
285                 data.horizontalSpan = 2;
286                 instruction.setLayoutData(data);
287                 instruction.setFont(font);
288         }
289
290         /**
291          * Creates the controls needed to edit the run in background attribute of an
292          * external tool
293          * 
294          * @param parent
295          *            the composite to create the controls in
296          */
297         protected void createRunBackgroundComponent(Composite parent) {
298                 runBackgroundButton = new Button(parent, SWT.CHECK);
299                 runBackgroundButton.setText(ExternalToolsLaunchConfigurationMessages
300                                 .getString("ExternalToolsOptionTab.Run_tool_in_bac&kground_4")); //$NON-NLS-1$
301                 GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
302                 runBackgroundButton.setLayoutData(data);
303                 runBackgroundButton.setFont(parent.getFont());
304                 runBackgroundButton.addSelectionListener(getSelectionAdapter());
305         }
306
307         /**
308          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
309          */
310         public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
311                 configuration.setAttribute(
312                                 IExternalToolConstants.ATTR_RUN_IN_BACKGROUND, false);
313         }
314
315         /**
316          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
317          */
318         public void initializeFrom(ILaunchConfiguration configuration) {
319                 updateLocation(configuration);
320                 updateWorkingDirectory(configuration);
321                 updateArgument(configuration);
322                 updateRunBackground(configuration);
323         }
324
325         protected void updateWorkingDirectory(ILaunchConfiguration configuration) {
326                 String workingDir = ""; //$NON-NLS-1$
327                 try {
328                         workingDir = configuration.getAttribute(
329                                         IExternalToolConstants.ATTR_WORKING_DIRECTORY, ""); //$NON-NLS-1$
330                 } catch (CoreException ce) {
331                         ExternalToolsPlugin
332                                         .getDefault()
333                                         .log(
334                                                         ExternalToolsLaunchConfigurationMessages
335                                                                         .getString("ExternalToolsMainTab.Error_reading_configuration_10"), ce); //$NON-NLS-1$
336                 }
337                 workDirectoryField.setText(workingDir);
338                 workDirectoryField.addModifyListener(modifyListener);
339
340         }
341
342         protected void updateLocation(ILaunchConfiguration configuration) {
343                 String location = ""; //$NON-NLS-1$
344                 try {
345                         location = configuration.getAttribute(
346                                         IExternalToolConstants.ATTR_LOCATION, ""); //$NON-NLS-1$
347                 } catch (CoreException ce) {
348                         ExternalToolsPlugin
349                                         .getDefault()
350                                         .log(
351                                                         ExternalToolsLaunchConfigurationMessages
352                                                                         .getString("ExternalToolsMainTab.Error_reading_configuration_10"), ce); //$NON-NLS-1$
353                 }
354                 locationField.setText(location);
355                 locationField.addModifyListener(modifyListener);
356         }
357
358         protected void updateArgument(ILaunchConfiguration configuration) {
359                 String arguments = ""; //$NON-NLS-1$
360                 try {
361                         arguments = configuration.getAttribute(
362                                         IExternalToolConstants.ATTR_TOOL_ARGUMENTS, ""); //$NON-NLS-1$
363                 } catch (CoreException ce) {
364                         ExternalToolsPlugin
365                                         .getDefault()
366                                         .log(
367                                                         ExternalToolsLaunchConfigurationMessages
368                                                                         .getString("ExternalToolsOptionTab.Error_reading_configuration_7"), ce); //$NON-NLS-1$
369                 }
370                 argumentField.setText(arguments);
371         }
372
373         protected void updateRunBackground(ILaunchConfiguration configuration) {
374                 boolean runInBackgroud = true;
375                 try {
376                         runInBackgroud = configuration.getAttribute(
377                                         IExternalToolConstants.ATTR_RUN_IN_BACKGROUND, false);
378                 } catch (CoreException ce) {
379                         ExternalToolsPlugin
380                                         .getDefault()
381                                         .log(
382                                                         ExternalToolsLaunchConfigurationMessages
383                                                                         .getString("ExternalToolsOptionTab.Error_reading_configuration_7"), ce); //$NON-NLS-1$
384                 }
385                 runBackgroundButton.setSelection(runInBackgroud);
386         }
387
388         /**
389          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
390          */
391         public void performApply(ILaunchConfigurationWorkingCopy configuration) {
392                 String location = locationField.getText().trim();
393                 if (location.length() == 0) {
394                         configuration.setAttribute(IExternalToolConstants.ATTR_LOCATION,
395                                         (String) null);
396                 } else {
397                         configuration.setAttribute(IExternalToolConstants.ATTR_LOCATION,
398                                         location);
399                 }
400
401                 String workingDirectory = workDirectoryField.getText().trim();
402                 if (workingDirectory.length() == 0) {
403                         configuration.setAttribute(
404                                         IExternalToolConstants.ATTR_WORKING_DIRECTORY,
405                                         (String) null);
406                 } else {
407                         configuration.setAttribute(
408                                         IExternalToolConstants.ATTR_WORKING_DIRECTORY,
409                                         workingDirectory);
410                 }
411
412                 setAttribute(IExternalToolConstants.ATTR_RUN_IN_BACKGROUND,
413                                 configuration, runBackgroundButton.getSelection(), false);
414
415                 String arguments = argumentField.getText().trim();
416                 if (arguments.length() == 0) {
417                         configuration.setAttribute(
418                                         IExternalToolConstants.ATTR_TOOL_ARGUMENTS, (String) null);
419                 } else {
420                         configuration.setAttribute(
421                                         IExternalToolConstants.ATTR_TOOL_ARGUMENTS, arguments);
422                 }
423         }
424
425         /**
426          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
427          */
428         public String getName() {
429                 return ExternalToolsLaunchConfigurationMessages
430                                 .getString("ExternalToolsMainTab.&Main_17"); //$NON-NLS-1$
431         }
432
433         /**
434          * @see ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
435          */
436         public boolean isValid(ILaunchConfiguration launchConfig) {
437                 setErrorMessage(null);
438                 setMessage(null);
439                 return validateLocation() && validateWorkDirectory();
440         }
441
442         /**
443          * Validates the content of the location field.
444          */
445         protected boolean validateLocation() {
446                 String value = locationField.getText().trim();
447                 if (value.length() < 1) {
448                         setErrorMessage(ExternalToolsLaunchConfigurationMessages
449                                         .getString("ExternalToolsMainTab.External_tool_location_cannot_be_empty_18")); //$NON-NLS-1$
450                         setMessage(null);
451                         return false;
452                 }
453
454                 // Translate field contents to the actual file location so we
455                 // can check to ensure the file actually exists.
456                 MultiStatus multiStatus = new MultiStatus(
457                                 IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
458                 value = ToolUtil.expandFileLocation(value,
459                                 ExpandVariableContext.EMPTY_CONTEXT, multiStatus);
460                 if (!multiStatus.isOK()) {
461                         IStatus[] children = multiStatus.getChildren();
462                         if (children.length > 0) {
463                                 setErrorMessage(children[0].getMessage());
464                                 setMessage(null);
465                         }
466                         return false;
467                 }
468
469                 File file = new File(value);
470                 if (!file.exists()) { // The file does not exist.
471                         setErrorMessage(ExternalToolsLaunchConfigurationMessages
472                                         .getString("ExternalToolsMainTab.External_tool_location_does_not_exist_19")); //$NON-NLS-1$
473                         return false;
474                 }
475                 if (!file.isFile()) {
476                         setErrorMessage(ExternalToolsLaunchConfigurationMessages
477                                         .getString("ExternalToolsMainTab.External_tool_location_specified_is_not_a_file_20")); //$NON-NLS-1$
478                         return false;
479                 }
480                 return true;
481         }
482
483         /**
484          * Validates the content of the working directory field.
485          */
486         protected boolean validateWorkDirectory() {
487
488                 String value = workDirectoryField.getText().trim();
489                 if (value.length() > 0) {
490                         // Translate field contents to the actual directory location so we
491                         // can check to ensure the directory actually exists.
492                         MultiStatus multiStatus = new MultiStatus(
493                                         IExternalToolConstants.PLUGIN_ID, 0, "", null); //$NON-NLS-1$
494                         value = ToolUtil.expandDirectoryLocation(value,
495                                         ExpandVariableContext.EMPTY_CONTEXT, multiStatus);
496                         if (!multiStatus.isOK()) {
497                                 IStatus[] children = multiStatus.getChildren();
498                                 if (children.length > 0) {
499                                         setErrorMessage(children[0].getMessage());
500                                 }
501                                 return false;
502                         }
503
504                         File file = new File(value);
505                         if (!file.exists()) { // The directory does not exist.
506                                 setErrorMessage(ExternalToolsLaunchConfigurationMessages
507                                                 .getString("ExternalToolsMainTab.External_tool_working_directory_does_not_exist_or_is_invalid_21")); //$NON-NLS-1$
508                                 return false;
509                         }
510                 }
511                 return true;
512         }
513
514         protected void handleLocationButtonSelected() {
515                 FileDialog fileDialog = new FileDialog(getShell(), SWT.NONE);
516                 fileDialog.setFileName(locationField.getText());
517                 String text = fileDialog.open();
518                 if (text != null) {
519                         locationField.setText(text);
520                 }
521         }
522
523         /**
524          * Prompts the user for a workspace location within the workspace and sets
525          * the location as a String containing the workspace_loc variable or
526          * <code>null</code> if no location was obtained from the user.
527          */
528         protected void handleWorkspaceLocationButtonSelected() {
529                 ResourceSelectionDialog dialog;
530                 dialog = new ResourceSelectionDialog(getShell(), ResourcesPlugin
531                                 .getWorkspace().getRoot(),
532                                 ExternalToolsLaunchConfigurationMessages
533                                                 .getString("ExternalToolsMainTab.Select_a_resource_22")); //$NON-NLS-1$
534                 dialog.open();
535                 Object[] results = dialog.getResult();
536                 if (results == null || results.length < 1) {
537                         return;
538                 }
539                 IResource resource = (IResource) results[0];
540                 StringBuffer buf = new StringBuffer();
541                 ToolUtil.buildVariableTag(IExternalToolConstants.VAR_WORKSPACE_LOC,
542                                 resource.getFullPath().toString(), buf);
543                 String text = buf.toString();
544                 if (text != null) {
545                         locationField.setText(text);
546                 }
547         }
548
549         /**
550          * Prompts the user for a working directory location within the workspace
551          * and sets the working directory as a String containing the workspace_loc
552          * variable or <code>null</code> if no location was obtained from the
553          * user.
554          */
555         protected void handleWorkspaceWorkingDirectoryButtonSelected() {
556                 ContainerSelectionDialog containerDialog;
557                 containerDialog = new ContainerSelectionDialog(
558                                 getShell(),
559                                 ResourcesPlugin.getWorkspace().getRoot(),
560                                 false,
561                                 ExternalToolsLaunchConfigurationMessages
562                                                 .getString("ExternalToolsMainTab.&Select_a_directory__23")); //$NON-NLS-1$
563                 containerDialog.open();
564                 Object[] resource = containerDialog.getResult();
565                 String text = null;
566                 if (resource != null && resource.length > 0) {
567                         text = ToolUtil.buildVariableTag(
568                                         IExternalToolConstants.VAR_RESOURCE_LOC,
569                                         ((IPath) resource[0]).toString());
570                 }
571                 if (text != null) {
572                         workDirectoryField.setText(text);
573                 }
574         }
575
576         protected void handleFileWorkingDirectoryButtonSelected() {
577                 DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SAVE);
578                 dialog.setMessage(ExternalToolsLaunchConfigurationMessages
579                                 .getString("ExternalToolsMainTab.&Select_a_directory__23")); //$NON-NLS-1$
580                 dialog.setFilterPath(workDirectoryField.getText());
581                 String text = dialog.open();
582                 if (text != null) {
583                         workDirectoryField.setText(text);
584                 }
585         }
586
587         /**
588          * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
589          */
590         public Image getImage() {
591                 return ExternalToolsImages
592                                 .getImage(IExternalToolConstants.IMG_TAB_MAIN);
593         }
594
595         /**
596          * Method getSelectionAdapter.
597          * 
598          * @return SelectionListener
599          */
600         protected SelectionListener getSelectionAdapter() {
601                 if (selectionAdapter == null) {
602                         selectionAdapter = new SelectionAdapter() {
603                                 public void widgetSelected(SelectionEvent e) {
604                                         updateLaunchConfigurationDialog();
605                                 }
606                         };
607                 }
608                 return selectionAdapter;
609         }
610
611         private class VariableSelectionDialog extends SelectionDialog {
612                 private ExternalToolVariableForm form;
613
614                 private VariableSelectionDialog(Shell parent) {
615                         super(parent);
616                         setTitle(ExternalToolsLaunchConfigurationMessages
617                                         .getString("ExternalToolsOptionTab.Select_variable_10")); //$NON-NLS-1$
618                 }
619
620                 protected Control createDialogArea(Composite parent) {
621                         // Create the dialog area
622                         Composite composite = (Composite) super.createDialogArea(parent);
623                         ExternalToolVariable[] variables = ExternalToolsPlugin.getDefault()
624                                         .getArgumentVariableRegistry().getArgumentVariables();
625                         form = new ExternalToolVariableForm(
626                                         ExternalToolsLaunchConfigurationMessages
627                                                         .getString("ExternalToolsOptionTab.&Choose_a_variable__11"), variables); //$NON-NLS-1$
628                         form.createContents(composite, new IGroupDialogPage() {
629                                 public GridData setButtonGridData(Button button) {
630                                         GridData data = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
631                                         data.heightHint = convertVerticalDLUsToPixels(IDialogConstants.BUTTON_HEIGHT);
632                                         int widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
633                                         data.widthHint = Math.max(widthHint, button.computeSize(
634                                                         SWT.DEFAULT, SWT.DEFAULT, true).x);
635                                         button.setLayoutData(data);
636                                         return data;
637                                 }
638
639                                 public void setMessage(String newMessage, int newType) {
640                                         VariableSelectionDialog.this.setMessage(newMessage);
641                                 }
642
643                                 public void updateValidState() {
644                                 }
645
646                                 public int convertHeightHint(int chars) {
647                                         return convertHeightInCharsToPixels(chars);
648                                 }
649
650                                 public String getMessage() {
651                                         if (!form.isValid()) {
652                                                 return ExternalToolsLaunchConfigurationMessages
653                                                                 .getString("ExternalToolsOptionTab.Invalid_selection_12"); //$NON-NLS-1$
654                                         }
655                                         return null;
656                                 }
657
658                                 public int getMessageType() {
659                                         if (!form.isValid()) {
660                                                 return IMessageProvider.ERROR;
661                                         }
662                                         return 0;
663                                 }
664                         });
665                         return composite;
666                 }
667
668                 private ExternalToolVariableForm getForm() {
669                         return form;
670                 }
671         }
672
673 }