KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > pde > internal > ui > launcher > BasicLauncherTab


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 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.pde.internal.ui.launcher;
12
13 import java.util.ArrayList JavaDoc;
14 import java.util.StringTokenizer JavaDoc;
15
16 import org.eclipse.core.runtime.CoreException;
17 import org.eclipse.core.runtime.IPath;
18 import org.eclipse.core.runtime.IStatus;
19 import org.eclipse.core.runtime.Path;
20 import org.eclipse.debug.core.ILaunchConfiguration;
21 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
22 import org.eclipse.jdt.launching.IJavaLaunchConfigurationConstants;
23 import org.eclipse.jface.dialogs.Dialog;
24 import org.eclipse.jface.preference.IPreferenceNode;
25 import org.eclipse.jface.preference.PreferenceDialog;
26 import org.eclipse.jface.preference.PreferenceManager;
27 import org.eclipse.pde.internal.core.PDECore;
28 import org.eclipse.pde.internal.core.TargetPlatform;
29 import org.eclipse.pde.internal.ui.IHelpContextIds;
30 import org.eclipse.pde.internal.ui.PDEPlugin;
31 import org.eclipse.pde.internal.ui.PDEPluginImages;
32 import org.eclipse.pde.internal.ui.PDEUIMessages;
33 import org.eclipse.pde.internal.ui.util.SWTUtil;
34 import org.eclipse.swt.SWT;
35 import org.eclipse.swt.custom.BusyIndicator;
36 import org.eclipse.swt.events.ModifyEvent;
37 import org.eclipse.swt.events.ModifyListener;
38 import org.eclipse.swt.events.SelectionAdapter;
39 import org.eclipse.swt.events.SelectionEvent;
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.DirectoryDialog;
47 import org.eclipse.swt.widgets.Group;
48 import org.eclipse.swt.widgets.Label;
49 import org.eclipse.swt.widgets.Text;
50 import org.eclipse.ui.PlatformUI;
51
52 public class BasicLauncherTab
53     extends AbstractLauncherTab
54     implements ILauncherSettings {
55
56     private Combo fWorkspaceCombo;
57     private Button fBrowseButton;
58     private Button fClearWorkspaceCheck;
59     private Button fAskClearCheck;
60     private Combo fJreCombo;
61     private Text fVmArgsText;
62     private Text fProgArgsText;
63     private Image fImage;
64     private Button fJavawButton;
65     private Button fJavaButton;
66
67     private IStatus fJreSelectionStatus;
68     private IStatus fWorkspaceSelectionStatus;
69     
70     private boolean fBlockChanges = false;
71
72     protected Combo fApplicationCombo;
73
74     private Text fBootstrap;
75
76     private Combo fProductCombo;
77
78     private Button fProductButton;
79
80     private Button fApplicationButton;
81
82     public BasicLauncherTab() {
83         fJreSelectionStatus = createStatus(IStatus.OK, ""); //$NON-NLS-1$
84
fWorkspaceSelectionStatus = createStatus(IStatus.OK, ""); //$NON-NLS-1$
85
fImage = PDEPluginImages.DESC_MAIN_TAB.createImage();
86     }
87
88     public void dispose() {
89         super.dispose();
90         fImage.dispose();
91     }
92
93     public void createControl(Composite parent) {
94         Composite composite = new Composite(parent, SWT.NONE);
95         composite.setLayout(new GridLayout());
96         composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
97         
98         createWorkspaceDataSection(composite);
99         createProgramSection(composite);
100         createCommandLineSettingsSection(composite);
101         
102         setControl(composite);
103         Dialog.applyDialogFont(composite);
104         PlatformUI.getWorkbench().getHelpSystem().setHelp(composite, IHelpContextIds.LAUNCHER_BASIC);
105     }
106     
107     private void createProgramSection(Composite composite) {
108         Group group = new Group(composite, SWT.NONE);
109         group.setText(PDEUIMessages.BasicLauncherTab_programToRun); //$NON-NLS-1$
110
GridLayout layout = new GridLayout();
111         layout.numColumns = 2;
112         group.setLayout(layout);
113         group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
114                 
115         createApplicationSection(group);
116         createProductSection(group);
117     }
118
119     protected void createWorkspaceDataSection(Composite composite) {
120         Group group = new Group(composite, SWT.NONE);
121         group.setText(PDEUIMessages.BasicLauncherTab_workspace); //$NON-NLS-1$
122
GridLayout layout = new GridLayout();
123         layout.numColumns = 3;
124         group.setLayout(layout);
125         group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
126
127         Label label = new Label(group, SWT.NULL);
128         label.setText(PDEUIMessages.BasicLauncherTab_location); //$NON-NLS-1$
129

130         fWorkspaceCombo = new Combo(group, SWT.DROP_DOWN);
131         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
132         fWorkspaceCombo.setLayoutData(gd);
133         fWorkspaceCombo.addSelectionListener(new SelectionAdapter() {
134             public void widgetSelected(SelectionEvent e) {
135                 fWorkspaceSelectionStatus = validateWorkspaceSelection();
136                 if (!fBlockChanges)
137                     updateStatus();
138             }
139         });
140         fWorkspaceCombo.addModifyListener(new ModifyListener() {
141             public void modifyText(ModifyEvent e) {
142                 fWorkspaceSelectionStatus = validateWorkspaceSelection();
143                 if (!fBlockChanges)
144                     updateStatus();
145             }
146         });
147
148         fBrowseButton = new Button(group, SWT.PUSH);
149         fBrowseButton.setText(PDEUIMessages.BasicLauncherTab_browse); //$NON-NLS-1$
150
fBrowseButton.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
151         fBrowseButton.addSelectionListener(new SelectionAdapter() {
152             public void widgetSelected(SelectionEvent e) {
153                 IPath chosen = chooseWorkspaceLocation();
154                 if (chosen != null) {
155                     String JavaDoc destination = chosen.toOSString();
156                     if (fWorkspaceCombo.indexOf(destination) == -1)
157                         fWorkspaceCombo.add(destination, 0);
158                     fWorkspaceCombo.setText(destination);
159                     if (fClearWorkspaceCheck.getSelection())
160                         fClearWorkspaceCheck.setSelection(false);
161                     updateStatus();
162                 }
163             }
164         });
165         SWTUtil.setButtonDimensionHint(fBrowseButton);
166
167         fClearWorkspaceCheck = new Button(group, SWT.CHECK);
168         fClearWorkspaceCheck.setText(PDEUIMessages.BasicLauncherTab_clear); //$NON-NLS-1$
169
gd = new GridData();
170         gd.horizontalSpan = 3;
171         fClearWorkspaceCheck.setLayoutData(gd);
172         fClearWorkspaceCheck.addSelectionListener(new SelectionAdapter() {
173             public void widgetSelected(SelectionEvent e) {
174                 fAskClearCheck.setEnabled(fClearWorkspaceCheck.getSelection());
175                 updateLaunchConfigurationDialog();
176             }
177         });
178         
179         fAskClearCheck = new Button(group, SWT.CHECK);
180         fAskClearCheck.setText(PDEUIMessages.BasicLauncherTab_askClear); //$NON-NLS-1$
181
gd = new GridData();
182         gd.horizontalSpan = 3;
183         fAskClearCheck.setLayoutData(gd);
184         fAskClearCheck.addSelectionListener(new SelectionAdapter() {
185             public void widgetSelected(SelectionEvent e) {
186                 updateLaunchConfigurationDialog();
187             }
188         });
189     }
190     
191     protected void createCommandLineSettingsSection(Composite composite) {
192         Group group = new Group(composite, SWT.NONE);
193         group.setText(PDEUIMessages.BasicLauncherTab_commandLineSettings); //$NON-NLS-1$
194
GridLayout layout = new GridLayout();
195         layout.numColumns = 2;
196         group.setLayout(layout);
197         group.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
198         
199         createJavaExecutableSection(group);
200         createJRESection(group);
201         createVMArgsSection(group);
202         createProgArgsSection(group);
203         createBootstrapEntriesSection(group);
204     }
205     
206     protected void createProductSection(Composite parent) {
207         fProductButton = new Button(parent, SWT.RADIO);
208         fProductButton.setText(PDEUIMessages.BasicLauncherTab_runProduct); //$NON-NLS-1$
209
fProductButton.addSelectionListener(new SelectionAdapter() {
210             public void widgetSelected(SelectionEvent e) {
211                 boolean selected = fProductButton.getSelection();
212                 fApplicationCombo.setEnabled(!selected);
213                 fProductCombo.setEnabled(selected);
214                 updateLaunchConfigurationDialog();
215             }
216         });
217         
218         fProductCombo = new Combo(parent, SWT.READ_ONLY|SWT.DROP_DOWN);
219         fProductCombo.setItems(TargetPlatform.getProductNames());
220         fProductCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
221         fProductCombo.addSelectionListener(new SelectionAdapter() {
222             public void widgetSelected(SelectionEvent e) {
223                 updateLaunchConfigurationDialog();
224             }
225         });
226     }
227     
228     protected void createApplicationSection(Composite parent) {
229         fApplicationButton = new Button(parent, SWT.RADIO);
230         fApplicationButton.setText(PDEUIMessages.BasicLauncherTab_runApplication); //$NON-NLS-1$
231

232         fApplicationCombo = new Combo(parent, SWT.READ_ONLY|SWT.DROP_DOWN);
233         fApplicationCombo.setItems(getApplicationNames());
234         fApplicationCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
235         fApplicationCombo.addSelectionListener(new SelectionAdapter() {
236             public void widgetSelected(SelectionEvent e) {
237                 updateLaunchConfigurationDialog();
238             }
239         });
240     }
241     
242     protected String JavaDoc[] getApplicationNames() {
243         return TargetPlatform.getApplicationNames();
244     }
245     
246     protected String JavaDoc getApplicationAttribute() {
247         return APPLICATION;
248     }
249         
250     protected void createJRESection(Composite parent) {
251         Label label = new Label(parent, SWT.NONE);
252         label.setText(PDEUIMessages.BasicLauncherTab_jre); //$NON-NLS-1$
253

254         Composite composite = new Composite(parent, SWT.NONE);
255         GridLayout layout = new GridLayout();
256         layout.numColumns = 2;
257         layout.marginHeight = layout.marginWidth = 0;
258         composite.setLayout(layout);
259         composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
260         
261         fJreCombo = new Combo(composite, SWT.DROP_DOWN | SWT.READ_ONLY);
262         fJreCombo.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
263         fJreCombo.addSelectionListener(new SelectionAdapter() {
264             public void widgetSelected(SelectionEvent e) {
265                 fJreSelectionStatus = validateJRESelection();
266                 updateStatus();
267             }
268         });
269         
270         Button button = new Button(composite, SWT.PUSH);
271         button.setText(PDEUIMessages.BasicLauncherTab_installedJREs); //$NON-NLS-1$
272
button.addSelectionListener(new SelectionAdapter() {
273             public void widgetSelected(SelectionEvent e) {
274                 String JavaDoc currentVM = fJreCombo.getText();
275                 IPreferenceNode node = new InstalledJREsPreferenceNode();
276                 if (showPreferencePage(node)) {
277                     fJreCombo.setItems(LauncherUtils.getVMInstallNames());
278                     fJreCombo.setText(currentVM);
279                     if (fJreCombo.getSelectionIndex() == -1)
280                         fJreCombo.setText(LauncherUtils.getDefaultVMInstallName());
281                 }
282             }
283             private boolean showPreferencePage(final IPreferenceNode targetNode) {
284                 PreferenceManager manager = new PreferenceManager();
285                 manager.addToRoot(targetNode);
286                 final PreferenceDialog dialog =
287                     new PreferenceDialog(getControl().getShell(), manager);
288                 final boolean[] result = new boolean[] { false };
289                 BusyIndicator.showWhile(getControl().getDisplay(), new Runnable JavaDoc() {
290                     public void run() {
291                         dialog.create();
292                         dialog.setMessage(targetNode.getLabelText());
293                         if (dialog.open() == PreferenceDialog.OK)
294                             result[0] = true;
295                     }
296                 });
297                 return result[0];
298             }
299         });
300         button.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_END));
301         SWTUtil.setButtonDimensionHint(button);
302     }
303     
304     protected void createJavaExecutableSection(Composite parent) {
305         Label label = new Label(parent, SWT.NONE);
306         label.setText(PDEUIMessages.BasicLauncherTab_javaExec); //$NON-NLS-1$
307

308         Composite composite = new Composite(parent, SWT.NONE);
309         GridLayout layout = new GridLayout();
310         layout.numColumns = 2;
311         layout.marginHeight = layout.marginWidth = 0;
312         layout.horizontalSpacing = 20;
313         composite.setLayout(layout);
314         composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
315         
316         fJavawButton = new Button(composite, SWT.RADIO);
317         fJavawButton.setText(PDEUIMessages.BasicLauncherTab_javaExecDefault); //$NON-NLS-1$
318
fJavawButton.addSelectionListener(new SelectionAdapter() {
319             public void widgetSelected(SelectionEvent e) {
320                 updateLaunchConfigurationDialog();
321             }
322         });
323         
324         fJavaButton = new Button(composite, SWT.RADIO);
325         fJavaButton.setText("&java"); //$NON-NLS-1$
326
fJavaButton.addSelectionListener(new SelectionAdapter() {
327             public void widgetSelected(SelectionEvent e) {
328                 updateLaunchConfigurationDialog();
329             }
330         });
331     }
332     
333     protected void createVMArgsSection(Composite parent) {
334         Label label = new Label(parent, SWT.NONE);
335         label.setText(PDEUIMessages.BasicLauncherTab_vmArgs); //$NON-NLS-1$
336

337         fVmArgsText = new Text(parent, SWT.BORDER);
338         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
339         gd.widthHint = 300;
340         fVmArgsText.setLayoutData(gd);
341         fVmArgsText.addModifyListener(new ModifyListener() {
342             public void modifyText(ModifyEvent e) {
343                 if (!fBlockChanges)
344                     updateLaunchConfigurationDialog();
345             }
346         });
347     }
348     
349     protected void createProgArgsSection(Composite parent) {
350         Label label = new Label(parent, SWT.NONE);
351         label.setText(PDEUIMessages.BasicLauncherTab_programArgs); //$NON-NLS-1$
352

353         fProgArgsText = new Text(parent, SWT.BORDER);
354         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
355         gd.widthHint = 300;
356         fProgArgsText.setLayoutData(gd);
357         fProgArgsText.addModifyListener(new ModifyListener() {
358             public void modifyText(ModifyEvent e) {
359                 if (!fBlockChanges)
360                     updateLaunchConfigurationDialog();
361             }
362         });
363     }
364         
365     private void createBootstrapEntriesSection(Composite parent) {
366         Label label = new Label(parent, SWT.NONE);
367         label.setText(PDEUIMessages.BasicLauncherTab_bootstrap); //$NON-NLS-1$
368

369         fBootstrap = new Text(parent, SWT.BORDER);
370         GridData gd = new GridData(GridData.FILL_HORIZONTAL);
371         gd.widthHint = 300;
372         fBootstrap.setLayoutData(gd);
373         fBootstrap.addModifyListener(new ModifyListener() {
374             public void modifyText(ModifyEvent e) {
375                 if (!fBlockChanges)
376                     updateLaunchConfigurationDialog();
377             }
378         });
379     }
380
381     public void initializeFrom(ILaunchConfiguration config) {
382         try {
383             fBlockChanges = true;
384             initializeWorkspaceDataSection(config);
385             initializeJRESection(config);
386             initializeProgramToRunSection(config);
387             initializeVMArgsSection(config);
388             initializeProgArgsSection(config);
389             initializeBootstrapEntriesSection(config);
390             fWorkspaceSelectionStatus = validateWorkspaceSelection();
391             fJreSelectionStatus = validateJRESelection();
392             updateStatus();
393         } catch (CoreException e) {
394             PDEPlugin.logException(e);
395         } finally {
396             fBlockChanges = false;
397         }
398     }
399     
400     protected void initializeProgramToRunSection(ILaunchConfiguration config) throws CoreException {
401         initializeApplicationSection(config);
402         initializeProductSection(config);
403         
404         boolean useProduct = config.getAttribute(USE_PRODUCT, false)
405             && PDECore.getDefault().getModelManager().isOSGiRuntime()
406             && fProductCombo.getItemCount() > 0;
407         fApplicationButton.setSelection(!useProduct);
408         fApplicationCombo.setEnabled(!useProduct);
409         fProductButton.setSelection(useProduct);
410         fProductButton.setEnabled(fProductCombo.getItemCount() > 0);
411         fProductCombo.setEnabled(useProduct);
412     }
413     
414     protected void initializeProductSection(ILaunchConfiguration config) throws CoreException {
415         if (fProductCombo.getItemCount() > 0) {
416             String JavaDoc productName = config.getAttribute(PRODUCT, (String JavaDoc)null);
417             int index = productName == null ? -1 : fProductCombo.indexOf(productName);
418             if (index == -1)
419                 index = 0;
420             fProductCombo.setText(fProductCombo.getItem(index));
421         }
422     }
423
424     protected void initializeApplicationSection(ILaunchConfiguration config)
425         throws CoreException {
426         
427         String JavaDoc attribute = getApplicationAttribute();
428         
429         // first see if the application name has been set on the launch config
430
String JavaDoc application = config.getAttribute(attribute, (String JavaDoc) null);
431         if (application == null
432             || fApplicationCombo.indexOf(application) == -1) {
433             application = null;
434             
435             // check if the user has entered the -application arg in the program arg field
436
StringTokenizer JavaDoc tokenizer =
437                 new StringTokenizer JavaDoc(config.getAttribute(PROGARGS, "")); //$NON-NLS-1$
438
while (tokenizer.hasMoreTokens()) {
439                 String JavaDoc token = tokenizer.nextToken();
440                 if (token.equals("-application") && tokenizer.hasMoreTokens()) { //$NON-NLS-1$
441
application = tokenizer.nextToken();
442                     break;
443                 }
444             }
445             
446             int index = -1;
447             if (application != null)
448                 index = fApplicationCombo.indexOf(application);
449             
450             // use default application as specified in the install.ini of the target platform
451
if (index == -1)
452                 index = fApplicationCombo.indexOf(LauncherUtils.getDefaultApplicationName());
453             
454             if (index != -1) {
455                 fApplicationCombo.setText(fApplicationCombo.getItem(index));
456             } else if (fApplicationCombo.getItemCount() > 0) {
457                 fApplicationCombo.setText(fApplicationCombo.getItem(0));
458             }
459         } else {
460             fApplicationCombo.setText(application);
461         }
462     }
463
464     protected void initializeWorkspaceDataSection(ILaunchConfiguration config)
465         throws CoreException {
466         ArrayList JavaDoc items = new ArrayList JavaDoc();
467         for (int i = 0; i < 6; i++) {
468             String JavaDoc curr =
469                 config.getAttribute(LOCATION + String.valueOf(i), (String JavaDoc) null);
470             if (curr != null && !items.contains(curr)) {
471                 items.add(curr);
472             }
473         }
474
475         fWorkspaceCombo.setItems((String JavaDoc[]) items.toArray(new String JavaDoc[items.size()]));
476         if (fWorkspaceCombo.getItemCount() > 0)
477             fWorkspaceCombo.setText(items.get(0).toString());
478
479         fClearWorkspaceCheck.setSelection(config.getAttribute(DOCLEAR, false));
480         fAskClearCheck.setSelection(config.getAttribute(ASKCLEAR, true));
481         fAskClearCheck.setEnabled(fClearWorkspaceCheck.getSelection());
482     }
483     
484     protected void initializeJRESection(ILaunchConfiguration config) throws CoreException {
485         String JavaDoc javaCommand = config.getAttribute(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND, "javaw"); //$NON-NLS-1$
486
fJavawButton.setSelection(javaCommand.equals("javaw")); //$NON-NLS-1$
487
fJavaButton.setSelection(!fJavawButton.getSelection());
488         
489         fJreCombo.setItems(LauncherUtils.getVMInstallNames());
490         String JavaDoc vmInstallName =
491             config.getAttribute(VMINSTALL, LauncherUtils.getDefaultVMInstallName());
492         fJreCombo.setText(vmInstallName);
493         if (fJreCombo.getSelectionIndex() == -1)
494             fJreCombo.setText(LauncherUtils.getDefaultVMInstallName());
495     }
496     
497     protected void initializeVMArgsSection(ILaunchConfiguration config) throws CoreException {
498         fVmArgsText.setText(config.getAttribute(VMARGS, "")); //$NON-NLS-1$
499
}
500     
501     protected void initializeProgArgsSection(ILaunchConfiguration config) throws CoreException {
502         fProgArgsText.setText(config.getAttribute(PROGARGS, "")); //$NON-NLS-1$
503
}
504     
505     private void initializeBootstrapEntriesSection(ILaunchConfiguration config) throws CoreException {
506         fBootstrap.setText(config.getAttribute(BOOTSTRAP_ENTRIES, "")); //$NON-NLS-1$
507
}
508
509     public void setDefaults(ILaunchConfigurationWorkingCopy config) {
510         config.setAttribute(LOCATION + "0", LauncherUtils.getDefaultWorkspace()); //$NON-NLS-1$
511
config.setAttribute(DOCLEAR, false);
512         config.setAttribute(ASKCLEAR, true);
513         config.setAttribute(PROGARGS, ""); //$NON-NLS-1$
514
config.setAttribute(VMARGS,""); //$NON-NLS-1$
515
config.setAttribute(BOOTSTRAP_ENTRIES, ""); //$NON-NLS-1$
516
String JavaDoc product = TargetPlatform.getDefaultProduct();
517         if (product != null) {
518             config.setAttribute(USE_PRODUCT, true);
519             config.setAttribute(PRODUCT, product); //$NON-NLS-1$
520
}
521     }
522     
523     private void updateStatus() {
524         updateStatus(getMoreSevere(fWorkspaceSelectionStatus, fJreSelectionStatus));
525     }
526
527     public void performApply(ILaunchConfigurationWorkingCopy config) {
528         try {
529             saveWorkspaceDataSection(config);
530             saveApplicationSection(config);
531             saveProductSection(config);
532             saveJRESection(config);
533             saveVMArgsSection(config);
534             saveProgArgsSection(config);
535             saveBootstrapEntriesSection(config);
536         } catch (CoreException e) {
537             PDEPlugin.logException(e);
538         }
539     }
540     
541     protected void saveWorkspaceDataSection(ILaunchConfigurationWorkingCopy config)
542         throws CoreException {
543         config.setAttribute(LOCATION + String.valueOf(0), fWorkspaceCombo.getText());
544         String JavaDoc[] items = fWorkspaceCombo.getItems();
545         int nEntries = Math.min(items.length, 5);
546         for (int i = 0; i < nEntries; i++) {
547             config.setAttribute(LOCATION + String.valueOf(i+1), items[i]);
548         }
549     
550         config.setAttribute(DOCLEAR, fClearWorkspaceCheck.getSelection());
551         config.setAttribute(ASKCLEAR, fAskClearCheck.getSelection());
552     }
553     
554     protected void saveJRESection(ILaunchConfigurationWorkingCopy config)
555         throws CoreException {
556         
557         String JavaDoc javaCommand = fJavawButton.getSelection() ? null : "java"; //$NON-NLS-1$
558
config.setAttribute(IJavaLaunchConfigurationConstants.ATTR_JAVA_COMMAND, javaCommand);
559         
560         if (fJreCombo.getSelectionIndex() == -1)
561             return;
562
563         String JavaDoc jre = fJreCombo.getText();
564         if (config.getAttribute(VMINSTALL, (String JavaDoc) null) != null) {
565             config.setAttribute(VMINSTALL, jre);
566         } else {
567             config.setAttribute(
568                 VMINSTALL,
569                 jre.equals(LauncherUtils.getDefaultVMInstallName()) ? null : jre);
570         }
571     }
572     
573     protected void saveVMArgsSection(ILaunchConfigurationWorkingCopy config) {
574         config.setAttribute(VMARGS, fVmArgsText.getText().trim());
575     }
576     
577     protected void saveProgArgsSection(ILaunchConfigurationWorkingCopy config) {
578         config.setAttribute(PROGARGS, fProgArgsText.getText().trim());
579     }
580     
581     protected void saveBootstrapEntriesSection(ILaunchConfigurationWorkingCopy config) {
582         config.setAttribute(BOOTSTRAP_ENTRIES, fBootstrap.getText().trim());
583     }
584     
585     protected void saveProductSection(ILaunchConfigurationWorkingCopy config) {
586         config.setAttribute(USE_PRODUCT, fProductButton.getSelection());
587         config.setAttribute(PRODUCT, fProductCombo.getText());
588     }
589
590     protected void saveApplicationSection(ILaunchConfigurationWorkingCopy config) {
591         String JavaDoc text = fApplicationCombo.getText();
592         String JavaDoc attribute = getApplicationAttribute();
593         if (text.length() == 0 || text.equals(LauncherUtils.getDefaultApplicationName()))
594             config.setAttribute(attribute, (String JavaDoc) null);
595         else
596             config.setAttribute(attribute, text);
597     }
598
599     private IPath chooseWorkspaceLocation() {
600         DirectoryDialog dialog = new DirectoryDialog(getControl().getShell());
601         dialog.setFilterPath(fWorkspaceCombo.getText());
602         dialog.setText(PDEUIMessages.BasicLauncherTab_workspace_title); //$NON-NLS-1$
603
dialog.setMessage(PDEUIMessages.BasicLauncherTab_workspace_message); //$NON-NLS-1$
604
String JavaDoc res = dialog.open();
605         return res != null ? new Path(res) : null;
606     }
607
608     private IStatus validateJRESelection() {
609         if (fJreCombo.getSelectionIndex() == -1) {
610             return createStatus(
611                 IStatus.ERROR,
612                 PDEUIMessages.BasicLauncherTab_noJRE); //$NON-NLS-1$
613
}
614         return createStatus(IStatus.OK, ""); //$NON-NLS-1$
615
}
616
617     private IStatus validateWorkspaceSelection() {
618         String JavaDoc location = fWorkspaceCombo.getText().trim();
619         if (!Path.ROOT.isValidPath(location)) {
620             return createStatus(
621                 IStatus.ERROR,
622                 PDEUIMessages.BasicLauncherTab_invalidWorkspace); //$NON-NLS-1$
623
}
624         
625         IPath curr = new Path(location);
626         if (curr.segmentCount() == 0 && curr.getDevice() == null) {
627             return createStatus(
628                 IStatus.ERROR,
629                 PDEUIMessages.BasicLauncherTab_noWorkspace); //$NON-NLS-1$
630
}
631
632         return createStatus(IStatus.OK, ""); //$NON-NLS-1$
633
}
634
635     public String JavaDoc getName() {
636         return PDEUIMessages.BasicLauncherTab_name;
637     }
638     
639     public Image getImage() {
640         return fImage;
641     }
642     
643 }
644
Popular Tags