KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > externaltools > internal > launchConfigurations > ExternalToolsMainTab


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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.ui.externaltools.internal.launchConfigurations;
12
13
14 import java.io.File JavaDoc;
15 import org.eclipse.core.resources.IResource;
16 import org.eclipse.core.resources.ResourcesPlugin;
17 import org.eclipse.core.runtime.CoreException;
18 import org.eclipse.core.runtime.IPath;
19 import org.eclipse.core.variables.IStringVariableManager;
20 import org.eclipse.core.variables.VariablesPlugin;
21 import org.eclipse.debug.core.ILaunchConfiguration;
22 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
23 import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
24 import org.eclipse.debug.ui.StringVariableSelectionDialog;
25 import org.eclipse.jface.dialogs.Dialog;
26 import org.eclipse.jface.dialogs.IDialogConstants;
27 import org.eclipse.swt.SWT;
28 import org.eclipse.swt.accessibility.AccessibleAdapter;
29 import org.eclipse.swt.accessibility.AccessibleEvent;
30 import org.eclipse.swt.events.ModifyEvent;
31 import org.eclipse.swt.events.ModifyListener;
32 import org.eclipse.swt.events.SelectionAdapter;
33 import org.eclipse.swt.events.SelectionEvent;
34 import org.eclipse.swt.graphics.Image;
35 import org.eclipse.swt.layout.GridData;
36 import org.eclipse.swt.layout.GridLayout;
37 import org.eclipse.swt.widgets.Button;
38 import org.eclipse.swt.widgets.Composite;
39 import org.eclipse.swt.widgets.Control;
40 import org.eclipse.swt.widgets.DirectoryDialog;
41 import org.eclipse.swt.widgets.FileDialog;
42 import org.eclipse.swt.widgets.Group;
43 import org.eclipse.swt.widgets.Label;
44 import org.eclipse.swt.widgets.Text;
45 import org.eclipse.ui.dialogs.ContainerSelectionDialog;
46 import org.eclipse.ui.dialogs.ResourceSelectionDialog;
47 import org.eclipse.ui.externaltools.internal.model.ExternalToolsImages;
48 import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
49 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
50
51 /**
52  * The external tools main tab allows the user to configure primary attributes
53  * of external tool launch configurations such as the location, working directory,
54  * and arguments.
55  */

56 public abstract class ExternalToolsMainTab extends AbstractLaunchConfigurationTab {
57     public final static String JavaDoc FIRST_EDIT = "editedByExternalToolsMainTab"; //$NON-NLS-1$
58

59     protected Text locationField;
60     protected Text workDirectoryField;
61     protected Button fileLocationButton;
62     protected Button workspaceLocationButton;
63     protected Button variablesLocationButton;
64     protected Button fileWorkingDirectoryButton;
65     protected Button workspaceWorkingDirectoryButton;
66     protected Button variablesWorkingDirectoryButton;
67
68     protected Text argumentField;
69     protected Button argumentVariablesButton;
70
71     protected SelectionAdapter selectionAdapter;
72     
73     protected boolean fInitializing= false;
74     private boolean userEdited= false;
75
76     protected WidgetListener fListener= new WidgetListener();
77     
78     /**
79      * A listener to update for text modification and widget selection.
80      */

81     protected class WidgetListener extends SelectionAdapter implements ModifyListener {
82         public void modifyText(ModifyEvent e) {
83             if (!fInitializing) {
84                 setDirty(true);
85                 userEdited= true;
86                 updateLaunchConfigurationDialog();
87             }
88         }
89         public void widgetSelected(SelectionEvent e) {
90             setDirty(true);
91             Object JavaDoc source= e.getSource();
92             if (source == workspaceLocationButton) {
93                 handleWorkspaceLocationButtonSelected();
94             } else if (source == fileLocationButton) {
95                 handleFileLocationButtonSelected();
96             } else if (source == workspaceWorkingDirectoryButton) {
97                 handleWorkspaceWorkingDirectoryButtonSelected();
98             } else if (source == fileWorkingDirectoryButton) {
99                 handleFileWorkingDirectoryButtonSelected();
100             } else if (source == argumentVariablesButton) {
101                 handleVariablesButtonSelected(argumentField);
102             } else if (source == variablesLocationButton) {
103                 handleVariablesButtonSelected(locationField);
104             } else if (source == variablesWorkingDirectoryButton) {
105                 handleVariablesButtonSelected(workDirectoryField);
106             }
107         }
108
109     }
110     
111     /* (non-Javadoc)
112      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#createControl(org.eclipse.swt.widgets.Composite)
113      */

114     public void createControl(Composite parent) {
115         Composite mainComposite = new Composite(parent, SWT.NONE);
116         setControl(mainComposite);
117         mainComposite.setFont(parent.getFont());
118         GridLayout layout = new GridLayout();
119         layout.numColumns = 1;
120         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
121         mainComposite.setLayout(layout);
122         mainComposite.setLayoutData(gridData);
123
124         createLocationComponent(mainComposite);
125         createWorkDirectoryComponent(mainComposite);
126         createArgumentComponent(mainComposite);
127         createVerticalSpacer(mainComposite, 1);
128         
129         Dialog.applyDialogFont(parent);
130     }
131     
132     /**
133      * Creates the controls needed to edit the location
134      * attribute of an external tool
135      *
136      * @param parent the composite to create the controls in
137      */

138     protected void createLocationComponent(Composite parent) {
139         Group group = new Group(parent, SWT.NONE);
140         String JavaDoc locationLabel = getLocationLabel();
141         group.setText(locationLabel);
142         GridLayout layout = new GridLayout();
143         layout.numColumns = 1;
144         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
145         group.setLayout(layout);
146         group.setLayoutData(gridData);
147         
148         locationField = new Text(group, SWT.BORDER);
149         gridData = new GridData(GridData.FILL_HORIZONTAL);
150         gridData.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
151         locationField.setLayoutData(gridData);
152         locationField.addModifyListener(fListener);
153         addControlAccessibleListener(locationField, group.getText());
154         
155         Composite buttonComposite = new Composite(group, SWT.NONE);
156         layout = new GridLayout();
157         layout.marginHeight = 0;
158         layout.marginWidth = 0;
159         layout.numColumns = 3;
160         gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
161         buttonComposite.setLayout(layout);
162         buttonComposite.setLayoutData(gridData);
163         buttonComposite.setFont(parent.getFont());
164         
165         workspaceLocationButton= createPushButton(buttonComposite, ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab__Browse_Workspace____3, null);
166         workspaceLocationButton.addSelectionListener(fListener);
167         addControlAccessibleListener(workspaceLocationButton, group.getText() + " " + workspaceLocationButton.getText()); //$NON-NLS-1$
168

169         fileLocationButton= createPushButton(buttonComposite, ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_Brows_e_File_System____4, null);
170         fileLocationButton.addSelectionListener(fListener);
171         addControlAccessibleListener(fileLocationButton, group.getText() + " " + fileLocationButton.getText()); //$NON-NLS-1$
172

173         variablesLocationButton = createPushButton(buttonComposite, ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_31, null);
174         variablesLocationButton.addSelectionListener(fListener);
175         addControlAccessibleListener(variablesLocationButton, group.getText() + " " + variablesLocationButton.getText()); //$NON-NLS-1$
176
}
177     
178     /**
179      * Returns the label used for the location widgets. Subclasses may wish to override.
180      */

181     protected String JavaDoc getLocationLabel() {
182         return ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab__Location___2;
183     }
184
185     /**
186      * Creates the controls needed to edit the working directory
187      * attribute of an external tool
188      *
189      * @param parent the composite to create the controls in
190      */

191     protected void createWorkDirectoryComponent(Composite parent) {
192         Group group = new Group(parent, SWT.NONE);
193         String JavaDoc groupName = getWorkingDirectoryLabel();
194         group.setText(groupName);
195         GridLayout layout = new GridLayout();
196         layout.numColumns = 1;
197         GridData gridData = new GridData(GridData.FILL_HORIZONTAL);
198         group.setLayout(layout);
199         group.setLayoutData(gridData);
200         
201         workDirectoryField = new Text(group, SWT.BORDER);
202         GridData data = new GridData(GridData.FILL_HORIZONTAL);
203         data.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
204         workDirectoryField.setLayoutData(data);
205         workDirectoryField.addModifyListener(fListener);
206         addControlAccessibleListener(workDirectoryField,group.getText());
207         
208         Composite buttonComposite = new Composite(group, SWT.NONE);
209         layout = new GridLayout();
210         layout.marginWidth = 0;
211         layout.marginHeight = 0;
212         layout.numColumns = 3;
213         gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
214         buttonComposite.setLayout(layout);
215         buttonComposite.setLayoutData(gridData);
216         buttonComposite.setFont(parent.getFont());
217         
218         workspaceWorkingDirectoryButton= createPushButton(buttonComposite, ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_Browse_Wor_kspace____6, null);
219         workspaceWorkingDirectoryButton.addSelectionListener(fListener);
220         addControlAccessibleListener(workspaceWorkingDirectoryButton, group.getText() + " " + workspaceWorkingDirectoryButton.getText()); //$NON-NLS-1$
221

222         fileWorkingDirectoryButton= createPushButton(buttonComposite, ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_Browse_F_ile_System____7, null);
223         fileWorkingDirectoryButton.addSelectionListener(fListener);
224         addControlAccessibleListener(fileWorkingDirectoryButton, group.getText() + " " + fileLocationButton.getText()); //$NON-NLS-1$
225

226         variablesWorkingDirectoryButton = createPushButton(buttonComposite, ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_32, null);
227         variablesWorkingDirectoryButton.addSelectionListener(fListener);
228         addControlAccessibleListener(variablesWorkingDirectoryButton, group.getText() + " " + variablesWorkingDirectoryButton.getText()); //$NON-NLS-1$
229
}
230     
231     /**
232      * Return the String to use as the label for the working directory field.
233      * Subclasses may wish to override.
234      */

235     protected String JavaDoc getWorkingDirectoryLabel() {
236         return ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_Working__Directory__5;
237     }
238     
239     /**
240      * Creates the controls needed to edit the argument and
241      * prompt for argument attributes of an external tool
242      *
243      * @param parent the composite to create the controls in
244      */

245     protected void createArgumentComponent(Composite parent) {
246         Group group = new Group(parent, SWT.NONE);
247         String JavaDoc groupName = ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab__Arguments___1;
248         group.setText(groupName);
249         GridLayout layout = new GridLayout();
250         layout.numColumns = 1;
251         GridData gridData = new GridData(GridData.FILL_BOTH);
252         group.setLayout(layout);
253         group.setLayoutData(gridData);
254         group.setFont(parent.getFont());
255         
256         argumentField = new Text(group, SWT.MULTI | SWT.WRAP | SWT.BORDER | SWT.V_SCROLL);
257         gridData = new GridData(GridData.FILL_BOTH);
258         gridData.widthHint = IDialogConstants.ENTRY_FIELD_WIDTH;
259         gridData.heightHint = 30;
260         argumentField.setLayoutData(gridData);
261         argumentField.addModifyListener(fListener);
262         addControlAccessibleListener(argumentField, group.getText());
263         
264         Composite composite = new Composite(group, SWT.NONE);
265         layout = new GridLayout();
266         layout.numColumns= 1;
267         layout.marginHeight= 0;
268         layout.marginWidth= 0;
269         gridData = new GridData(GridData.HORIZONTAL_ALIGN_END);
270         composite.setLayout(layout);
271         composite.setLayoutData(gridData);
272         composite.setFont(parent.getFont());
273         
274         argumentVariablesButton= createPushButton(composite, ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_Varia_bles____2, null);
275         argumentVariablesButton.addSelectionListener(fListener);
276         addControlAccessibleListener(argumentVariablesButton, argumentVariablesButton.getText()); // need to strip the mnemonic from buttons
277

278         Label instruction = new Label(group, SWT.NONE);
279         instruction.setText(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_3);
280         gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
281         gridData.horizontalSpan = 2;
282         instruction.setLayoutData(gridData);
283     }
284     
285     /* (non-Javadoc)
286      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#setDefaults(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
287      */

288     public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
289         configuration.setAttribute(FIRST_EDIT, true);
290     }
291
292     /* (non-Javadoc)
293      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#initializeFrom(org.eclipse.debug.core.ILaunchConfiguration)
294      */

295     public void initializeFrom(ILaunchConfiguration configuration) {
296         fInitializing= true;
297         updateLocation(configuration);
298         updateWorkingDirectory(configuration);
299         updateArgument(configuration);
300         fInitializing= false;
301         setDirty(false);
302     }
303     
304     /**
305      * Updates the working directory widgets to match the state of the given launch
306      * configuration.
307      */

308     protected void updateWorkingDirectory(ILaunchConfiguration configuration) {
309         String JavaDoc workingDir= ""; //$NON-NLS-1$
310
try {
311             workingDir= configuration.getAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, ""); //$NON-NLS-1$
312
} catch (CoreException ce) {
313             ExternalToolsPlugin.getDefault().log(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_Error_reading_configuration_10, ce);
314         }
315         workDirectoryField.setText(workingDir);
316     }
317     
318     /**
319      * Updates the location widgets to match the state of the given launch
320      * configuration.
321      */

322     protected void updateLocation(ILaunchConfiguration configuration) {
323         String JavaDoc location= ""; //$NON-NLS-1$
324
try {
325             location= configuration.getAttribute(IExternalToolConstants.ATTR_LOCATION, ""); //$NON-NLS-1$
326
} catch (CoreException ce) {
327             ExternalToolsPlugin.getDefault().log(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_Error_reading_configuration_10, ce);
328         }
329         locationField.setText(location);
330     }
331
332     /**
333      * Updates the argument widgets to match the state of the given launch
334      * configuration.
335      */

336     protected void updateArgument(ILaunchConfiguration configuration) {
337         String JavaDoc arguments= ""; //$NON-NLS-1$
338
try {
339             arguments= configuration.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, ""); //$NON-NLS-1$
340
} catch (CoreException ce) {
341             ExternalToolsPlugin.getDefault().log(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_Error_reading_configuration_7, ce);
342         }
343         argumentField.setText(arguments);
344     }
345
346     /* (non-Javadoc)
347      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#performApply(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
348      */

349     public void performApply(ILaunchConfigurationWorkingCopy configuration) {
350         String JavaDoc location= locationField.getText().trim();
351         if (location.length() == 0) {
352             configuration.setAttribute(IExternalToolConstants.ATTR_LOCATION, (String JavaDoc)null);
353         } else {
354             configuration.setAttribute(IExternalToolConstants.ATTR_LOCATION, location);
355         }
356         
357         String JavaDoc workingDirectory= workDirectoryField.getText().trim();
358         if (workingDirectory.length() == 0) {
359             configuration.setAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, (String JavaDoc)null);
360         } else {
361             configuration.setAttribute(IExternalToolConstants.ATTR_WORKING_DIRECTORY, workingDirectory);
362         }
363
364         String JavaDoc arguments= argumentField.getText().trim();
365         if (arguments.length() == 0) {
366             configuration.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, (String JavaDoc)null);
367         } else {
368             configuration.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, arguments);
369         }
370         
371         if(userEdited) {
372             configuration.setAttribute(FIRST_EDIT, (String JavaDoc)null);
373         }
374     }
375
376     /* (non-Javadoc)
377      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getName()
378      */

379     public String JavaDoc getName() {
380         return ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab__Main_17;
381     }
382     
383     /* (non-Javadoc)
384      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#isValid(org.eclipse.debug.core.ILaunchConfiguration)
385      */

386     public boolean isValid(ILaunchConfiguration launchConfig) {
387         setErrorMessage(null);
388         setMessage(null);
389         boolean newConfig = false;
390         try {
391             newConfig = launchConfig.getAttribute(FIRST_EDIT, false);
392         } catch (CoreException e) {
393             //assume false is correct
394
}
395         return validateLocation(newConfig) && validateWorkDirectory();
396     }
397     
398     /**
399      * Validates the content of the location field.
400      */

401     protected boolean validateLocation(boolean newConfig) {
402         String JavaDoc location = locationField.getText().trim();
403         if (location.length() < 1) {
404             if (newConfig) {
405                 setErrorMessage(null);
406                 setMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_30);
407             } else {
408                 setErrorMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_External_tool_location_cannot_be_empty_18);
409                 setMessage(null);
410             }
411             return false;
412         }
413         
414         String JavaDoc expandedLocation= null;
415         try {
416             expandedLocation= resolveValue(location);
417             if (expandedLocation == null) { //a variable that needs to be resolved at runtime
418
return true;
419             }
420         } catch (CoreException e) {
421             setErrorMessage(e.getStatus().getMessage());
422             return false;
423         }
424         
425         File JavaDoc file = new File JavaDoc(expandedLocation);
426         if (!file.exists()) { // The file does not exist.
427
if (!newConfig) {
428                 setErrorMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_External_tool_location_does_not_exist_19);
429             }
430             return false;
431         }
432         if (!file.isFile()) {
433             if (!newConfig) {
434                 setErrorMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_External_tool_location_specified_is_not_a_file_20);
435             }
436             return false;
437         }
438         return true;
439     }
440     
441     /**
442      * Validates the variables of the given string to determine if all variables are valid
443      *
444      * @param expression expression with variables
445      * @exception CoreException if a variable is specified that does not exist
446      */

447     private void validateVaribles(String JavaDoc expression) throws CoreException {
448         IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
449         manager.validateStringVariables(expression);
450     }
451     
452     private String JavaDoc resolveValue(String JavaDoc expression) throws CoreException {
453         String JavaDoc expanded= null;
454         try {
455             expanded= getValue(expression);
456         } catch (CoreException e) { //possibly just a variable that needs to be resolved at runtime
457
validateVaribles(expression);
458             return null;
459         }
460         return expanded;
461     }
462     
463     /**
464      * Validates the value of the given string to determine if any/all variables are valid
465      *
466      * @param expression expression with variables
467      * @return whether the expression contained any variable values
468      * @exception CoreException if variable resolution fails
469      */

470     private String JavaDoc getValue(String JavaDoc expression) throws CoreException {
471         IStringVariableManager manager = VariablesPlugin.getDefault().getStringVariableManager();
472         return manager.performStringSubstitution(expression);
473     }
474
475     /**
476      * Validates the content of the working directory field.
477      */

478     protected boolean validateWorkDirectory() {
479         String JavaDoc dir = workDirectoryField.getText().trim();
480         if (dir.length() <= 0) {
481             return true;
482         }
483
484         String JavaDoc expandedDir= null;
485         try {
486             expandedDir= resolveValue(dir);
487             if (expandedDir == null) { //a variable that needs to be resolved at runtime
488
return true;
489             }
490         } catch (CoreException e) {
491             setErrorMessage(e.getStatus().getMessage());
492             return false;
493         }
494             
495         File JavaDoc file = new File JavaDoc(expandedDir);
496         if (!file.exists()) { // The directory does not exist.
497
setErrorMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_External_tool_working_directory_does_not_exist_or_is_invalid_21);
498             return false;
499         }
500         if (!file.isDirectory()) {
501             setErrorMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_Not_a_directory);
502             return false;
503         }
504         return true;
505     }
506     
507     /**
508      * Prompts the user to choose a location from the filesystem and
509      * sets the location as the full path of the selected file.
510      */

511     protected void handleFileLocationButtonSelected() {
512         FileDialog fileDialog = new FileDialog(getShell(), SWT.NONE);
513         fileDialog.setFileName(locationField.getText());
514         String JavaDoc text= fileDialog.open();
515         if (text != null) {
516             locationField.setText(text);
517         }
518     }
519     
520     /**
521      * Prompts the user for a workspace location within the workspace and sets
522      * the location as a String containing the workspace_loc variable or
523      * <code>null</code> if no location was obtained from the user.
524      */

525     protected void handleWorkspaceLocationButtonSelected() {
526         ResourceSelectionDialog dialog;
527         dialog = new ResourceSelectionDialog(getShell(), ResourcesPlugin.getWorkspace().getRoot(), ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_Select_a_resource_22);
528         dialog.open();
529         Object JavaDoc[] results = dialog.getResult();
530         if (results == null || results.length < 1) {
531             return;
532         }
533         IResource resource = (IResource)results[0];
534         locationField.setText(newVariableExpression("workspace_loc", resource.getFullPath().toString())); //$NON-NLS-1$
535
}
536     
537     /**
538      * Prompts the user for a working directory location within the workspace
539      * and sets the working directory as a String containing the workspace_loc
540      * variable or <code>null</code> if no location was obtained from the user.
541      */

542     protected void handleWorkspaceWorkingDirectoryButtonSelected() {
543         ContainerSelectionDialog containerDialog;
544         containerDialog = new ContainerSelectionDialog(
545             getShell(),
546             ResourcesPlugin.getWorkspace().getRoot(),
547             false,
548             ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_23);
549         containerDialog.open();
550         Object JavaDoc[] resource = containerDialog.getResult();
551         String JavaDoc text= null;
552         if (resource != null && resource.length > 0) {
553             text= newVariableExpression("workspace_loc", ((IPath)resource[0]).toString()); //$NON-NLS-1$
554
}
555         if (text != null) {
556             workDirectoryField.setText(text);
557         }
558     }
559     
560     /**
561      * Returns a new variable expression with the given variable and the given argument.
562      * @see IStringVariableManager#generateVariableExpression(String, String)
563      */

564     protected String JavaDoc newVariableExpression(String JavaDoc varName, String JavaDoc arg) {
565         return VariablesPlugin.getDefault().getStringVariableManager().generateVariableExpression(varName, arg);
566     }
567     
568     /**
569      * Prompts the user to choose a working directory from the filesystem.
570      */

571     protected void handleFileWorkingDirectoryButtonSelected() {
572         DirectoryDialog dialog = new DirectoryDialog(getShell(), SWT.SAVE);
573         dialog.setMessage(ExternalToolsLaunchConfigurationMessages.ExternalToolsMainTab_23);
574         dialog.setFilterPath(workDirectoryField.getText());
575         String JavaDoc text= dialog.open();
576         if (text != null) {
577             workDirectoryField.setText(text);
578         }
579     }
580     
581     /**
582      * A variable entry button has been pressed for the given text
583      * field. Prompt the user for a variable and enter the result
584      * in the given field.
585      */

586     private void handleVariablesButtonSelected(Text textField) {
587         String JavaDoc variable = getVariable();
588         if (variable != null) {
589             textField.insert(variable);
590         }
591     }
592
593     /**
594      * Prompts the user to choose and configure a variable and returns
595      * the resulting string, suitable to be used as an attribute.
596      */

597     private String JavaDoc getVariable() {
598         StringVariableSelectionDialog dialog = new StringVariableSelectionDialog(getShell());
599         dialog.open();
600         return dialog.getVariableExpression();
601     }
602     
603     /* (non-Javadoc)
604      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#getImage()
605      */

606     public Image getImage() {
607         return ExternalToolsImages.getImage(IExternalToolConstants.IMG_TAB_MAIN);
608     }
609     
610     /* (non-Javadoc)
611      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#deactivated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
612      */

613     public void deactivated(ILaunchConfigurationWorkingCopy workingCopy) {
614     }
615     
616     /* (non-Javadoc)
617      * @see org.eclipse.debug.ui.ILaunchConfigurationTab#activated(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy)
618      */

619     public void activated(ILaunchConfigurationWorkingCopy workingCopy) {
620     }
621     
622     /*
623      * Fix for Bug 60163 Accessibility: New Builder Dialog missing object info for textInput controls
624      */

625     public void addControlAccessibleListener(Control control, String JavaDoc controlName) {
626         //strip mnemonic (&)
627
String JavaDoc[] strs = controlName.split("&"); //$NON-NLS-1$
628
StringBuffer JavaDoc stripped = new StringBuffer JavaDoc();
629         for (int i = 0; i < strs.length; i++) {
630             stripped.append(strs[i]);
631         }
632         control.getAccessible().addAccessibleListener(new ControlAccessibleListener(stripped.toString()));
633     }
634     
635     private class ControlAccessibleListener extends AccessibleAdapter {
636         private String JavaDoc controlName;
637         ControlAccessibleListener(String JavaDoc name) {
638             controlName = name;
639         }
640         public void getName(AccessibleEvent e) {
641             e.result = controlName;
642         }
643         
644     }
645 }
646
Popular Tags