KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > debug > internal > ui > launchConfigurations > LaunchConfigurationTabGroupViewer


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.debug.internal.ui.launchConfigurations;
12
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.util.HashSet JavaDoc;
16 import java.util.List JavaDoc;
17 import java.util.Set JavaDoc;
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.IProgressMonitor;
23 import org.eclipse.core.runtime.IStatus;
24 import org.eclipse.core.runtime.Status;
25 import org.eclipse.debug.core.DebugPlugin;
26 import org.eclipse.debug.core.ILaunchConfiguration;
27 import org.eclipse.debug.core.ILaunchConfigurationType;
28 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
29 import org.eclipse.debug.core.ILaunchDelegate;
30 import org.eclipse.debug.internal.core.LaunchConfigurationWorkingCopy;
31 import org.eclipse.debug.internal.ui.DebugUIPlugin;
32 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
33 import org.eclipse.debug.internal.ui.SWTFactory;
34 import org.eclipse.debug.ui.DebugUITools;
35 import org.eclipse.debug.ui.ILaunchConfigurationDialog;
36 import org.eclipse.debug.ui.ILaunchConfigurationTab;
37 import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
38 import org.eclipse.jface.dialogs.Dialog;
39 import org.eclipse.jface.dialogs.ErrorDialog;
40 import org.eclipse.jface.dialogs.IDialogConstants;
41 import org.eclipse.jface.operation.IRunnableWithProgress;
42 import org.eclipse.jface.resource.ColorRegistry;
43 import org.eclipse.jface.resource.JFaceResources;
44 import org.eclipse.jface.viewers.ISelection;
45 import org.eclipse.jface.viewers.IStructuredSelection;
46 import org.eclipse.jface.viewers.StructuredSelection;
47 import org.eclipse.jface.viewers.Viewer;
48 import org.eclipse.swt.SWT;
49 import org.eclipse.swt.custom.BusyIndicator;
50 import org.eclipse.swt.custom.CTabFolder;
51 import org.eclipse.swt.custom.CTabItem;
52 import org.eclipse.swt.custom.StackLayout;
53 import org.eclipse.swt.custom.ViewForm;
54 import org.eclipse.swt.events.ModifyEvent;
55 import org.eclipse.swt.events.ModifyListener;
56 import org.eclipse.swt.events.SelectionAdapter;
57 import org.eclipse.swt.events.SelectionEvent;
58 import org.eclipse.swt.events.SelectionListener;
59 import org.eclipse.swt.graphics.Color;
60 import org.eclipse.swt.graphics.Font;
61 import org.eclipse.swt.graphics.Image;
62 import org.eclipse.swt.layout.GridData;
63 import org.eclipse.swt.layout.GridLayout;
64 import org.eclipse.swt.widgets.Button;
65 import org.eclipse.swt.widgets.Composite;
66 import org.eclipse.swt.widgets.Control;
67 import org.eclipse.swt.widgets.Label;
68 import org.eclipse.swt.widgets.Link;
69 import org.eclipse.swt.widgets.Shell;
70 import org.eclipse.swt.widgets.Text;
71 import org.eclipse.ui.IWorkbenchPreferenceConstants;
72 import org.eclipse.ui.PlatformUI;
73
74 import com.ibm.icu.text.MessageFormat;
75
76 /**
77  * A viewer that displays tabs for a launch configuration, with apply and revert
78  * buttons.
79  */

80 public class LaunchConfigurationTabGroupViewer extends Viewer {
81
82     private final String JavaDoc EMPTY_STRING = ""; //$NON-NLS-1$
83
/**
84      * Containing launch dialog
85      */

86     private ILaunchConfigurationDialog fDialog;
87     
88     /**
89      * The this viewer's input
90      */

91     private Object JavaDoc fInput;
92     
93     /**
94      * The launch configuration (original) being edited
95      */

96     private ILaunchConfiguration fOriginal;
97     
98     /**
99      * The working copy of the original
100      */

101     private ILaunchConfigurationWorkingCopy fWorkingCopy;
102     
103     /**
104      * This view's control, which contains a composite area of controls
105      */

106     private Composite fViewerControl;
107     
108     /**
109      * The composite which is hidden/displayed as tabs are required.
110      */

111     private Composite fVisibleArea;
112     
113     /**
114      * Name label widget
115      */

116     private Label fNameLabel;
117     
118     /**
119      * Name text widget
120      */

121     private Text fNameWidget;
122     
123     /**
124      * Composite containing the launch config tab widgets
125      */

126     private Composite fTabComposite;
127     
128     /**
129      * Tab folder
130      */

131     private CTabFolder fTabFolder;
132     
133     /**
134      * The current tab group being displayed
135      */

136     private ILaunchConfigurationTabGroup fTabGroup;
137
138     /**
139      * The type of config tabs are currently displayed
140      * for
141      */

142     private ILaunchConfigurationType fTabType;
143     
144     /**
145      * Index of the active tab
146      */

147     private int fCurrentTabIndex = -1;
148     
149     /**
150      * Apply & Revert buttons
151      */

152     private Button fApplyButton;
153     private Button fRevertButton;
154     
155     /**
156      * Whether tabs are currently being disposed or initialized
157      */

158     private boolean fDisposingTabs = false;
159     private boolean fInitializingTabs = false;
160
161     /**
162      * The description of the currently selected launch configuration or
163      * launch configuration type or <code>null</code> if none.
164      */

165     private String JavaDoc fDescription = null;
166     
167     /**
168      * A place holder for switching between the tabs for a config and the getting started tab
169      * @since 3.2
170      */

171     private Composite fTabPlaceHolder = null;
172     
173     /**
174      * A link to allow users to select a valid set of launch options for the specified mode
175      * @since 3.3
176      */

177     private Link fOptionsLink = null;
178     
179     /**
180      * A new composite replacing the perspectives tab
181      * @since 3.2
182      */

183     private Composite fGettingStarted = null;
184
185     private ViewForm fViewform;
186     
187     /**
188      * Constructs a viewer in the given composite, contained by the given
189      * launch configuration dialog.
190      *
191      * @param parent composite containing this viewer
192      * @param dialog containing launch configuration dialog
193      */

194     public LaunchConfigurationTabGroupViewer(Composite parent, ILaunchConfigurationDialog dialog) {
195         super();
196         fDialog = dialog;
197         createControl(parent);
198     }
199     
200     /**
201      * Cleanup
202      */

203     public void dispose() {
204         disposeTabGroup();
205     }
206
207     /**
208      * Dispose the active tab group, if any.
209      */

210     protected void disposeTabGroup() {
211         if (fTabGroup != null) {
212             fTabGroup.dispose();
213             fTabGroup = null;
214             fTabType = null;
215         }
216     }
217     
218     /**
219      * Creates this viewer's control This area displays the name of the launch
220      * configuration currently being edited, as well as a tab folder of tabs
221      * that are applicable to the launch configuration.
222      *
223      * @return the composite used for launch configuration editing
224      */

225     private void createControl(Composite parent) {
226         fViewerControl = new Composite(parent, SWT.NONE);
227         GridLayout layout = new GridLayout();
228         layout.numColumns = 1;
229         layout.marginHeight = 0;
230         layout.marginWidth = 0;
231         layout.horizontalSpacing = 0;
232         layout.verticalSpacing = 0;
233         fViewerControl.setLayout(layout);
234         GridData gd = new GridData(GridData.FILL_BOTH);
235         fViewerControl.setLayoutData(gd);
236         
237         fViewform = new ViewForm(fViewerControl, SWT.FLAT | SWT.BORDER);
238         layout = new GridLayout(1, false);
239         layout.horizontalSpacing = 0;
240         layout.verticalSpacing = 0;
241         fViewform.setLayout(layout);
242         gd = new GridData(GridData.FILL_BOTH);
243         fViewform.setLayoutData(gd);
244         fVisibleArea = fViewform;
245         fViewform.setTopLeft(null);
246         
247         Composite mainComp = new Composite(fViewform, SWT.FLAT);
248         layout = new GridLayout(1, false);
249         layout.verticalSpacing = 0;
250         layout.horizontalSpacing = 0;
251         mainComp.setLayout(layout);
252         fViewform.setContent(mainComp);
253
254         fTabPlaceHolder = new Composite(mainComp, SWT.NONE);
255         fTabPlaceHolder.setLayout(new StackLayout());
256         gd = new GridData(GridData.FILL_BOTH);
257         fTabPlaceHolder.setLayoutData(gd);
258         
259         fGettingStarted = new Composite(fTabPlaceHolder, SWT.NONE);
260         fGettingStarted.setLayout(new GridLayout());
261         gd = new GridData(GridData.FILL_BOTH);
262         fGettingStarted.setLayoutData(gd);
263         
264         createGettingStarted(fGettingStarted);
265         
266         fTabComposite = new Composite(fTabPlaceHolder, SWT.NONE);
267         layout = new GridLayout(2, false);
268         layout.verticalSpacing = 10;
269         layout.horizontalSpacing = 5;
270         fTabComposite.setLayout(layout);
271         gd = new GridData(GridData.FILL_BOTH);
272         fTabComposite.setLayoutData(gd);
273         
274         fNameLabel = new Label(fTabComposite, SWT.HORIZONTAL | SWT.LEFT);
275         fNameLabel.setText(LaunchConfigurationsMessages.LaunchConfigurationDialog__Name__16);
276         fNameLabel.setLayoutData(new GridData(GridData.HORIZONTAL_ALIGN_BEGINNING));
277        
278         fNameWidget = new Text(fTabComposite, SWT.SINGLE | SWT.BORDER);
279         fNameWidget.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
280         fNameWidget.addModifyListener(new ModifyListener() {
281                     public void modifyText(ModifyEvent e) {
282                         if(!fInitializingTabs) {
283                             handleNameModified();
284                         }
285                     }
286                 }
287             );
288             
289         createTabFolder(fTabComposite);
290         
291         Composite blComp = SWTFactory.createComposite(mainComp, mainComp.getFont(), 2, 1, GridData.FILL_HORIZONTAL);
292         Composite linkComp = SWTFactory.createComposite(blComp, blComp.getFont(), 1, 1, GridData.FILL_HORIZONTAL);
293
294     //a link for launch options
295
fOptionsLink = new Link(linkComp, SWT.WRAP);
296         fOptionsLink.setFont(linkComp.getFont());
297         gd = new GridData(SWT.LEFT);
298         gd.grabExcessHorizontalSpace = true;
299         fOptionsLink.setLayoutData(gd);
300         fOptionsLink.addSelectionListener(new SelectionListener() {
301             public void widgetSelected(SelectionEvent e) {
302                 //collect the options available
303
try {
304                     if(!canLaunchWithModes()) {
305                         SelectLaunchModesDialog sld = new SelectLaunchModesDialog(getShell(),
306                                 getLaunchConfigurationDialog().getMode(), getWorkingCopy());
307                         if(sld.open() == IDialogConstants.OK_ID) {
308                             //set the options to the config
309
Object JavaDoc[] res = sld.getResult();
310                             if(res != null) {
311                                 Set JavaDoc modes = (Set JavaDoc) res[0];
312                                 modes.remove(getLaunchConfigurationDialog().getMode());
313                                 ILaunchConfigurationWorkingCopy wc = getWorkingCopy();
314                                 wc.setModes(modes);
315                                 refreshStatus();
316                             }
317                         }
318                     }
319                     else if(hasMultipleDelegates()) {
320                         SelectLaunchersDialog sldd = new SelectLaunchersDialog(getShell(),
321                                 getWorkingCopy().getType().getDelegates(getCurrentModeSet()),
322                                 getWorkingCopy(),
323                                 getLaunchConfigurationDialog().getMode());
324                         if(sldd.open() == IDialogConstants.OK_ID) {
325                             displayInstanceTabs(true);
326                         }
327                     }
328                 } catch (CoreException ex) {}
329             }
330             public void widgetDefaultSelected(SelectionEvent e) {}
331         });
332         fOptionsLink.setVisible(false);
333         
334         Composite buttonComp = new Composite(blComp, SWT.NONE);
335         GridLayout buttonCompLayout = new GridLayout();
336         buttonCompLayout.numColumns = 2;
337         buttonComp.setLayout(buttonCompLayout);
338         gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
339         buttonComp.setLayoutData(gd);
340         
341         fApplyButton = new Button(buttonComp, SWT.PUSH);
342         fApplyButton.setText(LaunchConfigurationsMessages.LaunchConfigurationDialog__Apply_17);
343         gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
344         fApplyButton.setLayoutData(gd);
345         SWTFactory.setButtonDimensionHint(fApplyButton);
346         fApplyButton.addSelectionListener(new SelectionAdapter() {
347             public void widgetSelected(SelectionEvent evt) {
348                 handleApplyPressed();
349             }
350         });
351
352         fRevertButton = new Button(buttonComp, SWT.PUSH);
353         fRevertButton.setText(LaunchConfigurationsMessages.LaunchConfigurationDialog_Revert_2);
354         gd = new GridData(GridData.HORIZONTAL_ALIGN_END);
355         fRevertButton.setLayoutData(gd);
356         SWTFactory.setButtonDimensionHint(fRevertButton);
357         fRevertButton.addSelectionListener(new SelectionAdapter() {
358             public void widgetSelected(SelectionEvent evt) {
359                 handleRevertPressed();
360             }
361         });
362         Dialog.applyDialogFont(parent);
363     }
364     
365     /**
366      * Creates some help text for the tab group launch types
367      * @param parent the parent composite
368      * @since 3.2
369      */

370     private void createGettingStarted(Composite parent) {
371         Font font = parent.getFont();
372         GridData gd = null;
373         int width = parent.getBounds().width - 30;
374         SWTFactory.createWrapLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_1, 1, width);
375         SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_2, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_NEW_CONFIG), 1, width);
376         SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_6, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_DUPLICATE_CONFIG), 1, width);
377         SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_4, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_DELETE_CONFIG), 1, width);
378         SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_8, DebugUITools.getImage(IInternalDebugUIConstants.IMG_ELCL_FILTER_CONFIGS), 1, width);
379         SWTFactory.createWrapCLabel(parent, LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_3, DebugUITools.getImage(IInternalDebugUIConstants.IMG_OVR_TRANSPARENT), 1, width);
380         
381         SWTFactory.createHorizontalSpacer(parent, 2);
382         Link link = new Link(parent, SWT.LEFT | SWT.WRAP);
383         link.setText(LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_5);
384         link.setFont(font);
385         gd = new GridData(GridData.FILL_HORIZONTAL);
386         gd.widthHint = width;
387         link.setLayoutData(gd);
388         link.addSelectionListener(new SelectionListener() {
389             public void widgetSelected(SelectionEvent e) {
390                 SWTFactory.showPreferencePage("org.eclipse.debug.ui.PerspectivePreferencePage"); //$NON-NLS-1$
391
}
392             public void widgetDefaultSelected(SelectionEvent e) {}
393         });
394     }
395     
396     /**
397      * Creates the tab folder for displaying config instances
398      * @param parent
399      */

400     private void createTabFolder(Composite parent) {
401         if (fTabFolder == null) {
402             ColorRegistry reg = JFaceResources.getColorRegistry();
403             Color c1 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_START"), //$NON-NLS-1$
404
c2 = reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_BG_END"); //$NON-NLS-1$
405
fTabFolder = new CTabFolder(parent, SWT.NO_REDRAW_RESIZE | SWT.NO_TRIM | SWT.FLAT);
406             GridData gd = new GridData(GridData.FILL_BOTH);
407             gd.horizontalSpan = 2;
408             fTabFolder.setSelectionBackground(new Color[] {c1, c2}, new int[] {100}, true);
409             fTabFolder.setSelectionForeground(reg.get("org.eclipse.ui.workbench.ACTIVE_TAB_TEXT_COLOR")); //$NON-NLS-1$
410
fTabFolder.setSimple(PlatformUI.getPreferenceStore().getBoolean(IWorkbenchPreferenceConstants.SHOW_TRADITIONAL_STYLE_TABS));
411             fTabFolder.setLayoutData(gd);
412             fTabFolder.setBorderVisible(true);
413             fTabFolder.setFont(parent.getFont());
414             fTabFolder.addSelectionListener(new SelectionAdapter() {
415                 public void widgetSelected(SelectionEvent event) {
416                     if (!fInitializingTabs) {
417                         handleTabSelected();
418                         refresh();
419                     }
420                 }
421             });
422         }
423     }
424     
425     /**
426      * Returns the apply button
427      */

428     protected Button getApplyButton() {
429         return fApplyButton;
430     }
431
432     /**
433      * Returns the revert button
434      */

435     protected Button getRevertButton() {
436         return fRevertButton;
437     }
438     
439     /**
440      * Sets the tab folder
441      */

442     protected CTabFolder getTabFolder() {
443         return fTabFolder;
444     }
445     
446     /**
447      * Sets the current name
448      */

449     public void setName(String JavaDoc name) {
450         if (getWorkingCopy() != null) {
451             if (name == null) {
452                 fNameWidget.setText(EMPTY_STRING);
453             }
454             else {
455                 fNameWidget.setText(name.trim());
456             }
457             refreshStatus();
458         }
459     }
460
461     /**
462      * @see org.eclipse.jface.viewers.Viewer#getControl()
463      */

464     public Control getControl() {
465         return fViewerControl;
466     }
467     
468     /**
469      * Returns the shell this viewer is contained in.
470      */

471     protected Shell getShell() {
472         return getControl().getShell();
473     }
474
475     /**
476      * @see org.eclipse.jface.viewers.IInputProvider#getInput()
477      */

478     public Object JavaDoc getInput() {
479         return fInput;
480     }
481
482     /**
483      * @see org.eclipse.jface.viewers.ISelectionProvider#getSelection()
484      */

485     public ISelection getSelection() {
486         return new StructuredSelection(fWorkingCopy);
487     }
488
489     /**
490      * @see org.eclipse.jface.viewers.Viewer#refresh()
491      */

492     public void refresh() {
493         if (fInitializingTabs) {
494             return;
495         }
496         ILaunchConfigurationTab[] tabs = getTabs();
497         if (tabs != null) {
498             // update the working copy from the active tab
499
boolean newwc = !getWorkingCopy().isDirty();
500             getActiveTab().performApply(getWorkingCopy());
501             if(getOriginal() instanceof ILaunchConfigurationWorkingCopy && newwc) {
502                 try {
503                     getWorkingCopy().doSave();
504                 }
505                 catch (CoreException e) {DebugUIPlugin.log(e);}
506             }
507             updateButtons();
508             // update error ticks
509
CTabItem item = null;
510             boolean error = false;
511             Image image = null;
512             for (int i = 0; i < tabs.length; i++) {
513                 item = fTabFolder.getItem(i);
514                 image = tabs[i].getImage();
515                 item.setImage(image);
516                 if(!tabs[i].isValid(getWorkingCopy())) {
517                     error = tabs[i].getErrorMessage() != null;
518                     if(error) {
519                         item.setImage(DebugUIPlugin.getDefault().getLaunchConfigurationManager().getErrorTabImage(tabs[i]));
520                     }
521                 }
522             }
523             showLink();
524         }
525     }
526     
527     /**
528      * Shows the link for either multiple launch delegates or bad launch mode combinations
529      *
530      * @since 3.3
531      */

532     private void showLink() {
533         String JavaDoc text = null;
534         if(!canLaunchWithModes()) {
535             text = LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_13;
536         }
537         else if(hasMultipleDelegates()) {
538             ILaunchDelegate delegate = getPreferredDelegate();
539             if(delegate != null) {
540                 String JavaDoc name = delegate.getName();
541                 if(name == null) {
542                     text = LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_15;
543                 }
544                 else {
545                     text = MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_16, new String JavaDoc[] {name});
546                 }
547             }
548             else {
549                 text = LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_17;
550             }
551         }
552         if(text != null) {
553             fOptionsLink.setText(text);
554         }
555         fOptionsLink.setVisible(!canLaunchWithModes() || hasMultipleDelegates());
556         fOptionsLink.getParent().getParent().layout(true);
557     }
558     
559     /**
560      * Returns the preferred launch delegate for the current launch configuration and mode set
561      * @return the preferred launch delegate
562      *
563      * @since 3.3
564      */

565     protected ILaunchDelegate getPreferredDelegate() {
566         ILaunchDelegate preferred = null;
567         ILaunchConfigurationWorkingCopy config = getWorkingCopy();
568         if(config != null) {
569             try {
570                 Set JavaDoc modes = getCurrentModeSet();
571                 preferred = config.getPreferredDelegate(modes);
572                 if(preferred == null) {
573                     preferred = config.getType().getPreferredDelegate(modes);
574                 }
575             }
576             catch(CoreException ce) {DebugUIPlugin.log(ce);}
577         }
578         return preferred;
579     }
580     
581     /**
582      * Returns the listing of modes for the current config
583      * @return the listing of modes for the current config
584      * @since 3.3
585      */

586     private Set JavaDoc getCurrentModeSet() {
587         Set JavaDoc set = new HashSet JavaDoc();
588         ILaunchConfigurationWorkingCopy config = getWorkingCopy();
589         if(config != null) {
590             try {
591                 set.addAll(config.getModes());
592                 set.add(getLaunchConfigurationDialog().getMode());
593             }
594             catch(CoreException ce) {DebugUIPlugin.log(ce);}
595         }
596         return set;
597     }
598     
599     /**
600      * updates the button states
601      */

602     private void updateButtons() {
603         boolean dirty = isDirty();
604         fApplyButton.setEnabled(dirty && canSave());
605         fRevertButton.setEnabled(dirty);
606     }
607
608     /* (non-Javadoc)
609      * @see org.eclipse.jface.viewers.Viewer#setInput(java.lang.Object)
610      */

611     public void setInput(final Object JavaDoc input) {
612         if(DebugUIPlugin.getStandardDisplay().getThread().equals(Thread.currentThread())) {
613             setInput0(input);
614         }
615         else {
616             DebugUIPlugin.getStandardDisplay().syncExec(new Runnable JavaDoc() {
617                 public void run() {
618                     setInput0(input);
619                 }
620             });
621         }
622         
623     }
624     /**
625      * Sets the input to the tab group viewer
626      * @param input the new input
627      * @since 3.3
628      */

629     private void setInput0(Object JavaDoc input) {
630         if (input == null) {
631             if (fInput == null) {
632                 return;
633             }
634             inputChanged(input);
635         } else {
636             if (!input.equals(fInput)) {
637                 inputChanged(input);
638             }
639         }
640     }
641     
642     /**
643      * The input has changed to the given object, possibly <code>null</code>.
644      *
645      * @param input the new input, possibly <code>null</code>
646      */

647     protected void inputChanged(Object JavaDoc input) {
648         fInput = input;
649         Runnable JavaDoc r = new Runnable JavaDoc() {
650             public void run() {
651                 try {
652                     fVisibleArea.setRedraw(false);
653                     if (fInput instanceof ILaunchConfiguration) {
654                         ILaunchConfiguration configuration = (ILaunchConfiguration)fInput;
655                         boolean refreshtabs = !delegatesEqual(fWorkingCopy, configuration);
656                         fOriginal = configuration;
657                         fWorkingCopy = configuration.getWorkingCopy();
658                         displayInstanceTabs(refreshtabs);
659                     } else if (fInput instanceof ILaunchConfigurationType) {
660                         fDescription = getDescription((ILaunchConfigurationType)fInput);
661                         setNoInput();
662                         refreshStatus();
663                     } else {
664                         setNoInput();
665                         refreshStatus();
666                     }
667                 } catch (CoreException ce) {
668                     errorDialog(ce);
669                     setNoInput();
670                 }
671                 finally {
672                     fVisibleArea.setRedraw(true);
673                 }
674             }
675         };
676         BusyIndicator.showWhile(getShell().getDisplay(), r);
677     }
678     
679     /**
680      * Sets the tab group viewer to have no input, this is the case when null is passed as an input type
681      * Setting no input is equivalent to resetting all items, clearing any messages and showing the 'getting started' pane
682      * @since 3.2
683      */

684     private void setNoInput() {
685         fOriginal = null;
686         fWorkingCopy = null;
687         disposeExistingTabs();
688         updateButtons();
689         updateVisibleControls(false);
690         ILaunchConfigurationDialog lcd = getLaunchConfigurationDialog();
691         if(lcd instanceof LaunchConfigurationsDialog) {
692             if(((LaunchConfigurationsDialog)lcd).isTreeSelectionEmpty()) {
693                 fDescription = EMPTY_STRING;
694             }
695         }
696     }
697     
698     /**
699      * Returns if the two configurations are using the same <code>ILaunchDelegate</code> or not
700      * @param config1
701      * @param config2
702      * @return true if the configurations are using the same <code>ILaunchDelegate</code> or false if they are not
703      * @since 3.3
704      */

705     protected boolean delegatesEqual(ILaunchConfiguration config1, ILaunchConfiguration config2) {
706         try {
707             if(config1 == null || config2 == null) {
708                 return false;
709             }
710             Set JavaDoc modes = getCurrentModeSet();
711             ILaunchDelegate d1 = config1.getPreferredDelegate(modes);
712             if(d1 == null) {
713                 d1 = config1.getType().getPreferredDelegate(modes);
714             }
715             ILaunchDelegate d2 = config2.getPreferredDelegate(modes);
716             if(d2 == null) {
717                 d2 = config2.getType().getPreferredDelegate(modes);
718             }
719             if(d1 != null) {
720                 return d1.equals(d2);
721             }
722         }
723         catch(CoreException ce) {DebugUIPlugin.log(ce);}
724         return false;
725     }
726     
727     /**
728      * Updates the visibility of controls based on the status provided
729      * @param visible the visibility status to be applied to the controls
730      */

731     private void updateVisibleControls(boolean visible) {
732         fApplyButton.setVisible(visible);
733         fRevertButton.setVisible(visible);
734         fOptionsLink.setVisible(visible);
735         if(visible) {
736             ((StackLayout)fTabPlaceHolder.getLayout()).topControl = fTabComposite;
737             fTabComposite.layout();
738         }
739         else {
740             ((StackLayout)fTabPlaceHolder.getLayout()).topControl = fGettingStarted;
741         }
742         fTabPlaceHolder.layout(true);
743     }
744     
745     /**
746      * sets the current widget focus to the 'Name' widget
747      */

748     protected void setFocusOnName() {
749         fNameWidget.setFocus();
750     }
751     
752     /**
753      * Displays tabs for the current working copy
754      */

755     protected void displayInstanceTabs(boolean redrawTabs) {
756         // Turn on initializing flag to ignore message updates
757
fInitializingTabs = true;
758         ILaunchConfigurationType type = null;
759         try {
760             type = getWorkingCopy().getType();
761         }
762         catch (CoreException e) {
763             errorDialog(e);
764             fInitializingTabs = false;
765             return;
766         }
767         if(redrawTabs) {
768             showInstanceTabsFor(type);
769         }
770         // show the name area
771
updateVisibleControls(true);
772
773         // Retrieve the current tab group. If there is none, clean up and leave
774
ILaunchConfigurationTabGroup tabGroup = getTabGroup();
775         if (tabGroup == null) {
776             IStatus status = new Status(IStatus.ERROR, DebugUIPlugin.getUniqueIdentifier(), 0, MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_No_tabs_defined_for_launch_configuration_type__0__1, new String JavaDoc[]{type.getName()}), null);
777             CoreException e = new CoreException(status);
778             errorDialog(e);
779             fInitializingTabs = false;
780             return;
781         }
782
783         // Update the tabs with the new working copy
784
tabGroup.initializeFrom(getWorkingCopy());
785
786         // Update the name field
787
fNameWidget.setText(getWorkingCopy().getName());
788         
789         fCurrentTabIndex = fTabFolder.getSelectionIndex();
790
791         // Turn off initializing flag to update message
792
fInitializingTabs = false;
793         
794         if (!fVisibleArea.isVisible()) {
795             fVisibleArea.setVisible(true);
796         }
797         refreshStatus();
798     }
799     
800     /**
801      * Populate the tabs in the configuration edit area to be appropriate to the current
802      * launch configuration type.
803      */

804     private void showInstanceTabsFor(ILaunchConfigurationType configType) {
805         // try to keep on same tab
806
Class JavaDoc tabKind = null;
807         if (getActiveTab() != null) {
808             tabKind = getActiveTab().getClass();
809         }
810         // Build the new tabs
811
ILaunchConfigurationTabGroup group = null;
812         try {
813             group = createGroup();
814         } catch (CoreException ce) {
815             DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Error_19, LaunchConfigurationsMessages.LaunchConfigurationDialog_Exception_occurred_creating_launch_configuration_tabs_27,ce); //
816
return;
817         }
818         disposeExistingTabs();
819         fTabGroup = group;
820         fTabType = configType;
821         ILaunchConfigurationTab[] tabs = getTabs();
822         CTabItem tab = null;
823         String JavaDoc name = EMPTY_STRING;
824         Control control = null;
825         for (int i = 0; i < tabs.length; i++) {
826             tab = new CTabItem(fTabFolder, SWT.BORDER);
827             name = tabs[i].getName();
828             if (name == null) {
829                 name = LaunchConfigurationsMessages.LaunchConfigurationDialog_unspecified_28;
830             }
831             tab.setText(name);
832             tab.setImage(tabs[i].getImage());
833             tabs[i].createControl(tab.getParent());
834             control = tabs[i].getControl();
835             if (control != null) {
836                 tab.setControl(control);
837             }
838         }
839         //set the default tab as the first one
840
setActiveTab(tabs[0]);
841         // select same tab as before, if possible
842
for (int i = 0; i < tabs.length; i++) {
843             if (tabs[i].getClass().equals(tabKind)) {
844                 setActiveTab(tabs[i]);
845                 break;
846             }
847         }
848         fDescription = getDescription(configType);
849     }
850
851     /**
852      * Returns the description of the given configuration type
853      * in the current mode or <code>null</code> if none.
854      *
855      * @param configType the config type
856      * @return the description of the given configuration type or <code>null</code>
857      */

858     private String JavaDoc getDescription(ILaunchConfigurationType configType) {
859         String JavaDoc description = null;
860         if(configType != null) {
861             String JavaDoc mode = fDialog.getMode();
862             description = LaunchConfigurationPresentationManager.getDefault().getDescription(configType, mode);
863         }
864         if (description == null) {
865             description = EMPTY_STRING;
866         }
867         return description;
868     }
869     
870     /**
871      * Returns tab group for the given type of launch configuration.
872      * Tabs are initialized to be contained in this dialog.
873      *
874      * @exception CoreException if unable to instantiate a tab group
875      */

876     protected ILaunchConfigurationTabGroup createGroup() throws CoreException {
877         // Use a final Object array to store the tab group and any exception that
878
// results from the Runnable
879
final Object JavaDoc[] finalArray = new Object JavaDoc[2];
880         Runnable JavaDoc runnable = new Runnable JavaDoc() {
881             public void run() {
882                 ILaunchConfigurationTabGroup tabGroup = null;
883                 try {
884                     tabGroup = LaunchConfigurationPresentationManager.getDefault().getTabGroup(getWorkingCopy(), getLaunchConfigurationDialog().getMode());
885                     finalArray[0] = tabGroup;
886                 } catch (CoreException ce) {
887                     finalArray[1] = ce;
888                     return;
889                 }
890                 tabGroup.createTabs(getLaunchConfigurationDialog(), getLaunchConfigurationDialog().getMode());
891                 ILaunchConfigurationTab[] tabs = tabGroup.getTabs();
892                 for (int i = 0; i < tabs.length; i++) {
893                     tabs[i].setLaunchConfigurationDialog(getLaunchConfigurationDialog());
894                 }
895             }
896         };
897
898         // Creating the tabs can result in plug-in loading, so we show the busy cursor
899
BusyIndicator.showWhile(getControl().getDisplay(), runnable);
900
901         // Re-throw any CoreException if there was one
902
if (finalArray[1] != null) {
903             throw (CoreException)finalArray[1];
904         }
905
906         // Otherwise return the tab group
907
return (ILaunchConfigurationTabGroup)finalArray[0];
908     }
909
910     /**
911      * @see org.eclipse.jface.viewers.Viewer#setSelection(org.eclipse.jface.viewers.ISelection, boolean)
912      */

913     public void setSelection(ISelection selection, boolean reveal) {
914         if (getWorkingCopy() != null) {
915             if (selection instanceof IStructuredSelection) {
916                 IStructuredSelection structuredSelection = (IStructuredSelection)selection;
917                 Object JavaDoc object = structuredSelection.getFirstElement();
918                 if (object instanceof ILaunchConfigurationTab) {
919                     ILaunchConfigurationTab[] tabs = getTabs();
920                     for (int i = 0; i < tabs.length; i++) {
921                         if (tabs[i].equals(object)) {
922                             fCurrentTabIndex = i;
923                             fTabFolder.setSelection(i);
924                         }
925                         return;
926                     }
927                 }
928             }
929         }
930             
931     }
932
933     /**
934      * Returns the tabs currently being displayed, or
935      * <code>null</code> if none.
936      *
937      * @return currently displayed tabs, or <code>null</code>
938      */

939     public ILaunchConfigurationTab[] getTabs() {
940         if (getTabGroup() != null) {
941             return getTabGroup().getTabs();
942         }
943         return null;
944     }
945
946     /**
947      * Returns the currently active <code>ILaunchConfigurationTab</code>
948      * being displayed, or <code>null</code> if there is none.
949      *
950      * @return currently active <code>ILaunchConfigurationTab</code>, or <code>null</code>.
951      */

952     public ILaunchConfigurationTab getActiveTab() {
953         ILaunchConfigurationTab[] tabs = getTabs();
954         if (fTabFolder != null && tabs != null) {
955             int pageIndex = fTabFolder.getSelectionIndex();
956             if (pageIndex >= 0) {
957                 return tabs[pageIndex];
958             }
959         }
960         return null;
961     }
962     
963     /**
964      * Returns whether the launch configuration being edited is dirty (i.e.
965      * needs saving)
966      *
967      * @return whether the launch configuration being edited needs saving
968      */

969     public boolean isDirty() {
970         ILaunchConfigurationWorkingCopy workingCopy = getWorkingCopy();
971         if (workingCopy == null) {
972             return false;
973         }
974         if(workingCopy.getParent() != null) {
975             return !workingCopy.getParent().contentsEqual(workingCopy);
976         }
977         // Working copy hasn't been saved
978
if (workingCopy.getOriginal() == null) {
979             return true;
980         }
981         ILaunchConfiguration original = getOriginal();
982         return !original.contentsEqual(workingCopy);
983     }
984     
985     /**
986      * Update apply & revert buttons, as well as buttons and message on the
987      * launch config dialog.
988      */

989     protected void refreshStatus() {
990         if (!fInitializingTabs) {
991             getLaunchConfigurationDialog().updateButtons();
992             getLaunchConfigurationDialog().updateMessage();
993         }
994     }
995     
996     /**
997      * Returns the containing launch dialog
998      */

999     protected ILaunchConfigurationDialog getLaunchConfigurationDialog() {
1000        return fDialog;
1001    }
1002
1003    /**
1004     * Returns the original launch configuration being edited, possibly
1005     * <code>null</code>.
1006     *
1007     * @return ILaunchConfiguration
1008     */

1009    protected ILaunchConfiguration getOriginal() {
1010        return fOriginal;
1011    }
1012    
1013    /**
1014     * Returns the working copy used to edit the original, possibly
1015     * <code>null</code>.
1016     */

1017    protected ILaunchConfigurationWorkingCopy getWorkingCopy() {
1018        return fWorkingCopy;
1019    }
1020    
1021    /**
1022     * Return whether the current configuration can be saved.
1023     * <p>
1024     * Note this is NOT the same thing as the config simply being valid. It
1025     * is possible to save a config that does not validate. This method
1026     * determines whether the config can be saved without causing a serious
1027     * error. For example, a shared config that has no specified location would
1028     * cause this method to return <code>false</code>.
1029     * </p>
1030     */

1031    public boolean canSave() {
1032        if (fInitializingTabs) {
1033            return false;
1034        }
1035        // First make sure that name doesn't prevent saving the config
1036
try {
1037            verifyName();
1038        } catch (CoreException ce) {
1039            return false;
1040        }
1041
1042        // Next, make sure none of the tabs object to saving the config
1043
ILaunchConfigurationTab[] tabs = getTabs();
1044        if (tabs == null) {
1045            return false;
1046        }
1047        for (int i = 0; i < tabs.length; i++) {
1048            if (!tabs[i].canSave()) {
1049                return false;
1050            }
1051        }
1052        if(getWorkingCopy() != null) {
1053            return !getWorkingCopy().isReadOnly();
1054        }
1055        return true;
1056    }
1057    
1058    /**
1059     * @see ILaunchConfigurationDialog#canLaunch()
1060     */

1061    public boolean canLaunch() {
1062        if(fInitializingTabs) {
1063            return false;
1064        }
1065        if (getWorkingCopy() == null) {
1066            return false;
1067        }
1068        try {
1069            verifyName();
1070        } catch (CoreException e) {
1071            return false;
1072        }
1073
1074        ILaunchConfigurationTab[] tabs = getTabs();
1075        if (tabs == null) {
1076            return false;
1077        }
1078        for (int i = 0; i < tabs.length; i++) {
1079            if (!tabs[i].isValid(getWorkingCopy())) {
1080                return false;
1081            }
1082        }
1083        return true;
1084    }
1085    
1086    /**
1087     * Determines if the tab groups that is currently visible can launch with the currently selected
1088     * set of options.
1089     *
1090     * @return true if the dialog can launch with the given set of modes, false otherwise
1091     *
1092     * @since 3.3
1093     */

1094    public boolean canLaunchWithModes() {
1095        if(fInitializingTabs) {
1096            return false;
1097        }
1098        //check if selected options exist and that the selected combination can be launched
1099
try {
1100            ILaunchConfigurationWorkingCopy wc = getWorkingCopy();
1101            if(wc != null) {
1102                return wc.getType().supportsModeCombination(getCurrentModeSet());
1103            }
1104        } catch (CoreException e) {
1105        }
1106        return true;
1107    }
1108    
1109    /**
1110     * Returns if the type currently showing in the tab group viewer has duplicate launch delegates for the given set of modes.
1111     *
1112     * The given set of modes comprises the current mode that the launch dialog was opened in as well as any modes that have been set on the launch
1113     * configuration.
1114     * @return the true if there are duplicates, false otherwise
1115     *
1116     * @since 3.3
1117     */

1118    public boolean hasDuplicateDelegates() {
1119        if(fInitializingTabs) {
1120            return false;
1121        }
1122        ILaunchConfiguration config = getWorkingCopy();
1123        if(config != null) {
1124            if(hasMultipleDelegates()) {
1125                return getPreferredDelegate() == null;
1126            }
1127        }
1128        return false;
1129    }
1130    
1131    /**
1132     * Determines if the currently showing launch configuration has multiple launch delegates for the same mode set, but does not care
1133     * if there has been a default selected yet or not
1134     * @return true if the current launch configuration has multiple launch delegates, false otherwise
1135     */

1136    private boolean hasMultipleDelegates() {
1137        ILaunchConfiguration config = getWorkingCopy();
1138        if(config != null) {
1139            try {
1140                Set JavaDoc modes = getCurrentModeSet();
1141                ILaunchDelegate[] delegates = LaunchConfigurationManager.filterLaunchDelegates(fTabType, modes);
1142                return delegates.length > 1;
1143            }
1144            catch (CoreException ce) {DebugUIPlugin.log(ce);}
1145        }
1146        return false;
1147    }
1148    
1149    /**
1150     * Returns the current error message or <code>null</code> if none.
1151     */

1152    public String JavaDoc getErrorMesssage() {
1153        if (fInitializingTabs) {
1154            return null;
1155        }
1156        
1157        if (getWorkingCopy() == null) {
1158            return null;
1159        }
1160        try {
1161            verifyName();
1162        } catch (CoreException ce) {
1163            return ce.getStatus().getMessage();
1164        }
1165    
1166        String JavaDoc message = null;
1167        ILaunchConfigurationTab activeTab = getActiveTab();
1168        if (activeTab == null) {
1169            return null;
1170        }
1171        message = activeTab.getErrorMessage();
1172        if (message != null) {
1173            return message;
1174        }
1175        
1176        ILaunchConfigurationTab[] allTabs = getTabs();
1177        for (int i = 0; i < allTabs.length; i++) {
1178            ILaunchConfigurationTab tab = allTabs[i];
1179            if (tab == activeTab) {
1180                continue;
1181            }
1182            message = tab.getErrorMessage();
1183            if (message != null) {
1184                StringBuffer JavaDoc temp= new StringBuffer JavaDoc();
1185                temp.append('[');
1186                temp.append(DebugUIPlugin.removeAccelerators(tab.getName()));
1187                temp.append("]: "); //$NON-NLS-1$
1188
temp.append(message);
1189                return temp.toString();
1190            }
1191        }
1192        if(getWorkingCopy().isReadOnly()) {
1193            return LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_9;
1194        }
1195        if(!canLaunchWithModes()) {
1196            Set JavaDoc modes = getCurrentModeSet();
1197            List JavaDoc names = LaunchConfigurationPresentationManager.getDefault().getLaunchModeNames(modes);
1198            return MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_14, new String JavaDoc[]{names.toString()});
1199        }
1200        if(hasDuplicateDelegates()) {
1201            return LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_18;
1202        }
1203        return null;
1204    }
1205    
1206    /**
1207     * Returns the current message or <code>null</code> if none.
1208     * @return Returns an appropriate message for display to user. The message returned will be:
1209     * The message defined by the visible tab,
1210     * or The tab group description for the particular launch mode,
1211     * or The generic tab group description,
1212     * or <code>null</code> if no message is defined
1213     */

1214    public String JavaDoc getMessage() {
1215        if (fInitializingTabs) {
1216            return null;
1217        }
1218        
1219        String JavaDoc message = fDescription;
1220        
1221        ILaunchConfigurationTab tab = getActiveTab();
1222        if (tab != null) {
1223            String JavaDoc tabMessage = tab.getMessage();
1224            if (tabMessage != null) {
1225                message = tabMessage;
1226            }
1227        }
1228        
1229        return message;
1230    }
1231        
1232    /**
1233     * Verify that the launch configuration name is valid.
1234     */

1235    protected void verifyName() throws CoreException {
1236        if (fNameWidget.isVisible()) {
1237            String JavaDoc currentName = fNameWidget.getText().trim();
1238    
1239            // If there is no name, complain
1240
if (currentName.length() < 1) {
1241                throw new CoreException(new Status(IStatus.ERROR,
1242                                                     DebugUIPlugin.getUniqueIdentifier(),
1243                                                     0,
1244                                                     LaunchConfigurationsMessages.LaunchConfigurationDialog_Name_required_for_launch_configuration_11,
1245                                                     null));
1246            }
1247    
1248            // See if name contains any 'illegal' characters
1249
IStatus status = ResourcesPlugin.getWorkspace().validateName(currentName, IResource.FILE);
1250            if (status.getCode() != IStatus.OK) {
1251                throw new CoreException(new Status(IStatus.ERROR,
1252                                                     DebugUIPlugin.getUniqueIdentifier(),
1253                                                     0,
1254                                                     status.getMessage(),
1255                                                     null));
1256            }
1257            
1258            // See if name contains any characters that we deem illegal.
1259
// '@' and '&' are disallowed because they corrupt menu items.
1260
char[] disallowedChars = new char[] { '@', '&' };
1261            for (int i = 0; i < disallowedChars.length; i++) {
1262                char c = disallowedChars[i];
1263                if (currentName.indexOf(c) > -1) {
1264                    throw new CoreException(new Status(IStatus.ERROR,
1265                                                        DebugUIPlugin.getUniqueIdentifier(),
1266                                                        0,
1267                                                        MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationTabGroupViewer_0, new String JavaDoc[] { new String JavaDoc(new char[] {c}), currentName }),
1268                                                        null));
1269                }
1270            }
1271    
1272            // Otherwise, if there's already a config with the same name, complain
1273
if (!getOriginal().getName().equals(currentName)) {
1274                Set JavaDoc reservednames = ((LaunchConfigurationsDialog)getLaunchConfigurationDialog()).getReservedNameSet();
1275                if (DebugPlugin.getDefault().getLaunchManager().isExistingLaunchConfigurationName(currentName) || (reservednames != null ? reservednames.contains(currentName) : false)) {
1276                    throw new CoreException(new Status(IStatus.ERROR,
1277                                                         DebugUIPlugin.getUniqueIdentifier(),
1278                                                         0,
1279                                                         LaunchConfigurationsMessages.LaunchConfigurationDialog_Launch_configuration_already_exists_with_this_name_12,
1280                                                         null));
1281                }
1282            }
1283        }
1284    }
1285    
1286    /**
1287     * Remove the existing tabs that are showing
1288     */

1289    private void disposeExistingTabs() {
1290        fDisposingTabs = true;
1291        fTabFolder.dispose();
1292        fTabFolder = null;
1293        createTabFolder(fTabComposite);
1294        disposeTabGroup();
1295        fDisposingTabs = false;
1296    }
1297
1298    /**
1299     * Returns the current tab group
1300     *
1301     * @return the current tab group, or <code>null</code> if none
1302     */

1303    public ILaunchConfigurationTabGroup getTabGroup() {
1304        return fTabGroup;
1305    }
1306    
1307    /**
1308     * Notification that a tab has been selected
1309     *
1310     * Disallow tab changing when the current tab is invalid.
1311     * Update the config from the tab being left, and refresh
1312     * the tab being entered.
1313     */

1314    protected void handleTabSelected() {
1315        if (fDisposingTabs || fInitializingTabs) {
1316            return;
1317        }
1318        ILaunchConfigurationTab[] tabs = getTabs();
1319        if (fCurrentTabIndex == fTabFolder.getSelectionIndex() || tabs == null || tabs.length == 0 || fCurrentTabIndex > (tabs.length - 1)) {
1320            return;
1321        }
1322        if (fCurrentTabIndex != -1) {
1323            ILaunchConfigurationTab tab = tabs[fCurrentTabIndex];
1324            ILaunchConfigurationWorkingCopy wc = getWorkingCopy();
1325            if (wc != null) {
1326                tab.deactivated(wc);
1327                getActiveTab().activated(wc);
1328            }
1329        }
1330        fCurrentTabIndex = fTabFolder.getSelectionIndex();
1331    }
1332    
1333    /**
1334     * Notification the name field has been modified
1335     */

1336    protected void handleNameModified() {
1337        getWorkingCopy().rename(fNameWidget.getText().trim());
1338        refreshStatus();
1339    }
1340    
1341    /**
1342     * Notification that the 'Apply' button has been pressed
1343     */

1344    protected void handleApplyPressed() {
1345        Exception JavaDoc exception = null;
1346        try {
1347            // update launch config
1348
fInitializingTabs = true;
1349            // trim name
1350
String JavaDoc trimmed = fNameWidget.getText().trim();
1351            fNameWidget.setText(trimmed);
1352            if(fWorkingCopy == null) {
1353                fWorkingCopy = fOriginal.getWorkingCopy();
1354            }
1355            fWorkingCopy.rename(trimmed);
1356            getTabGroup().performApply(fWorkingCopy);
1357            if (isDirty()) {
1358                if(!fWorkingCopy.isLocal()) {
1359                    IRunnableWithProgress runnable = new IRunnableWithProgress() {
1360                        public void run(IProgressMonitor monitor) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
1361                            try {
1362                                ((LaunchConfigurationWorkingCopy)fWorkingCopy).doSave(monitor);
1363                            }
1364                            catch (CoreException e) {DebugUIPlugin.log(e);}
1365                        }
1366                    };
1367                    getLaunchConfigurationDialog().run(true, false, runnable);
1368                }
1369                else {
1370                    fWorkingCopy.doSave();
1371                }
1372            }
1373            updateButtons();
1374            fInitializingTabs = false;
1375        }
1376        catch (CoreException e) {exception = e;}
1377        catch (InvocationTargetException JavaDoc e) {exception = e;}
1378        catch (InterruptedException JavaDoc e) {exception = e;}
1379        if(exception != null) {
1380            DebugUIPlugin.errorDialog(getShell(), LaunchConfigurationsMessages.LaunchConfigurationDialog_Launch_Configuration_Error_46, LaunchConfigurationsMessages.LaunchConfigurationDialog_Exception_occurred_while_saving_launch_configuration_47, exception); //
1381
return;
1382        }
1383    }
1384
1385    /**
1386     * Notification that the 'Revert' button has been pressed
1387     */

1388    protected void handleRevertPressed() {
1389        try {
1390            if(fTabGroup != null) {
1391                fTabGroup.initializeFrom(fOriginal);
1392                fNameWidget.setText(fOriginal.getName());
1393                fWorkingCopy = fOriginal.getWorkingCopy();
1394                refreshStatus();
1395            }
1396        }
1397        catch (CoreException e) {DebugUIPlugin.log(e);}
1398    }
1399    
1400    /**
1401     * Show an error dialog on the given exception.
1402     *
1403     * @param exception
1404     */

1405    protected void errorDialog(CoreException exception) {
1406        ErrorDialog.openError(getShell(), null, null, exception.getStatus());
1407    }
1408
1409    /**
1410     * Sets the displayed tab to the given tab. Has no effect if the specified
1411     * tab is not one of the tabs being displayed in the dialog currently.
1412     *
1413     * @param tab the tab to display/activate
1414     */

1415    public void setActiveTab(ILaunchConfigurationTab tab) {
1416        ILaunchConfigurationTab[] tabs = getTabs();
1417        if(tabs != null) {
1418            for (int i = 0; i < tabs.length; i++) {
1419                if (tabs[i].getClass().equals(tab.getClass())) {
1420                    setActiveTab(i);
1421                    return;
1422                }
1423            }
1424        }
1425    }
1426    
1427    /**
1428     * Sets the displayed tab to the tab with the given index. Has no effect if
1429     * the specified index is not within the limits of the tabs returned by
1430     * <code>getTabs()</code>.
1431     *
1432     * @param index the index of the tab to display
1433     */

1434    public void setActiveTab(int index) {
1435        ILaunchConfigurationTab[] tabs = getTabs();
1436        if (index >= 0 && index < tabs.length) {
1437            fTabFolder.setSelection(index);
1438            handleTabSelected();
1439        }
1440    }
1441
1442}
1443
Popular Tags