KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Sebastian Davids - Bug 137923
11  *******************************************************************************/

12 package org.eclipse.debug.internal.ui.launchConfigurations;
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.Iterator JavaDoc;
17 import java.util.Set JavaDoc;
18
19 import org.eclipse.core.runtime.CoreException;
20 import org.eclipse.core.runtime.IProgressMonitor;
21 import org.eclipse.core.runtime.IStatus;
22 import org.eclipse.core.runtime.ListenerList;
23 import org.eclipse.core.runtime.NullProgressMonitor;
24 import org.eclipse.core.runtime.SafeRunner;
25 import org.eclipse.core.runtime.Status;
26 import org.eclipse.debug.core.DebugPlugin;
27 import org.eclipse.debug.core.ILaunchConfiguration;
28 import org.eclipse.debug.core.ILaunchConfigurationType;
29 import org.eclipse.debug.core.ILaunchManager;
30 import org.eclipse.debug.core.IStatusHandler;
31 import org.eclipse.debug.internal.core.LaunchManager;
32 import org.eclipse.debug.internal.ui.DebugUIPlugin;
33 import org.eclipse.debug.internal.ui.IDebugHelpContextIds;
34 import org.eclipse.debug.internal.ui.IInternalDebugUIConstants;
35 import org.eclipse.debug.ui.DebugUITools;
36 import org.eclipse.debug.ui.IDebugUIConstants;
37 import org.eclipse.debug.ui.IDebugView;
38 import org.eclipse.debug.ui.ILaunchConfigurationDialog;
39 import org.eclipse.debug.ui.ILaunchConfigurationTab;
40 import org.eclipse.debug.ui.ILaunchConfigurationTabGroup;
41 import org.eclipse.jface.action.Action;
42 import org.eclipse.jface.action.IAction;
43 import org.eclipse.jface.action.Separator;
44 import org.eclipse.jface.action.ToolBarManager;
45 import org.eclipse.jface.dialogs.ErrorDialog;
46 import org.eclipse.jface.dialogs.IDialogConstants;
47 import org.eclipse.jface.dialogs.IDialogSettings;
48 import org.eclipse.jface.dialogs.IPageChangeProvider;
49 import org.eclipse.jface.dialogs.IPageChangedListener;
50 import org.eclipse.jface.dialogs.MessageDialog;
51 import org.eclipse.jface.dialogs.PageChangedEvent;
52 import org.eclipse.jface.dialogs.TitleAreaDialog;
53 import org.eclipse.jface.operation.IRunnableWithProgress;
54 import org.eclipse.jface.operation.ModalContext;
55 import org.eclipse.jface.resource.ImageDescriptor;
56 import org.eclipse.jface.util.IPropertyChangeListener;
57 import org.eclipse.jface.util.PropertyChangeEvent;
58 import org.eclipse.jface.util.SafeRunnable;
59 import org.eclipse.jface.viewers.ISelectionChangedListener;
60 import org.eclipse.jface.viewers.IStructuredSelection;
61 import org.eclipse.jface.viewers.SelectionChangedEvent;
62 import org.eclipse.jface.viewers.StructuredSelection;
63 import org.eclipse.jface.viewers.StructuredViewer;
64 import org.eclipse.jface.viewers.TreeViewer;
65 import org.eclipse.jface.viewers.Viewer;
66 import org.eclipse.jface.viewers.ViewerFilter;
67 import org.eclipse.jface.wizard.ProgressMonitorPart;
68 import org.eclipse.swt.SWT;
69 import org.eclipse.swt.custom.SashForm;
70 import org.eclipse.swt.custom.ViewForm;
71 import org.eclipse.swt.graphics.Font;
72 import org.eclipse.swt.graphics.Image;
73 import org.eclipse.swt.graphics.Point;
74 import org.eclipse.swt.graphics.Rectangle;
75 import org.eclipse.swt.layout.GridData;
76 import org.eclipse.swt.layout.GridLayout;
77 import org.eclipse.swt.widgets.Button;
78 import org.eclipse.swt.widgets.Composite;
79 import org.eclipse.swt.widgets.Control;
80 import org.eclipse.swt.widgets.Display;
81 import org.eclipse.swt.widgets.Shell;
82 import org.eclipse.swt.widgets.ToolBar;
83 import org.eclipse.swt.widgets.TreeItem;
84 import org.eclipse.ui.PlatformUI;
85 import org.eclipse.ui.progress.WorkbenchJob;
86
87 import com.ibm.icu.text.MessageFormat;
88  
89 /**
90  * The dialog used to edit and launch launch configurations.
91  */

92 public class LaunchConfigurationsDialog extends TitleAreaDialog implements ILaunchConfigurationDialog, IPageChangeProvider, IPropertyChangeListener {
93
94     /**
95      * Keep track of the currently visible dialog instance
96      */

97     private static ILaunchConfigurationDialog fgCurrentlyVisibleLaunchConfigurationDialog;
98     /**
99      * Id for 'Launch' button.
100      */

101     protected static final int ID_LAUNCH_BUTTON = IDialogConstants.CLIENT_ID + 1;
102         
103     /**
104      * Id for 'Close' button.
105      */

106     protected static final int ID_CLOSE_BUTTON = IDialogConstants.CLIENT_ID + 2;
107     /**
108      * Id for 'Cancel' button.
109      */

110     protected static final int ID_CANCEL_BUTTON = IDialogConstants.CLIENT_ID + 3;
111     
112     /**
113      * The id for the 'No' button on the discard changes message box
114      * @since 3.3
115      */

116     protected static final int ID_DISCARD_BUTTON = IDialogConstants.CLIENT_ID + 4;
117     
118     /**
119      * Constant specifying how wide this dialog is allowed to get (as a percentage of
120      * total available screen width) as a result of tab labels in the edit area.
121      */

122     protected static final float MAX_DIALOG_WIDTH_PERCENT = 0.75f;
123     /**
124      * Constant specifying how tall this dialog is allowed to get (as a percentage of
125      * total available screen height) as a result of preferred tab size.
126      */

127     protected static final float MAX_DIALOG_HEIGHT_PERCENT = 0.60f;
128     /**
129      * Size of this dialog if there is no preference specifying a size.
130      */

131     protected static final Point DEFAULT_INITIAL_DIALOG_SIZE = new Point(800, 640);
132     /**
133      * defines some default sashweights when we have a new workspace
134      * @since 3.2
135      */

136     private static final int[] DEFAULT_SASH_WEIGHTS = new int[] {190, 610};
137     /**
138      * Constant specifying that this dialog should be opened with the last configuration launched
139      * in the workspace selected.
140      */

141     public static final int LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_LAST_LAUNCHED = 2;
142     /**
143      * Constant specifying that this dialog should be opened with the value specified via
144      * <code>setInitialSelection()</code> selected.
145      */

146     public static final int LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_SELECTION = 3;
147     /**
148      * Constant specifying that a new launch configuration dialog was not opened. Instead
149      * an existing launch configuration dialog was used.
150      */

151     public static final int LAUNCH_CONFIGURATION_DIALOG_REUSE_OPEN = 4;
152     /**
153      * defines the empty string
154      * @since 3.2
155      */

156     private static final String JavaDoc EMPTY_STRING = ""; //$NON-NLS-1$
157
/**
158      * defines the delimiter used in the persistence of the expanded state
159      * @since 3.2
160      */

161     private static final String JavaDoc DELIMITER = ", "; //$NON-NLS-1$
162
/**
163      * Specifies how this dialog behaves when opened. Value is one of the
164      * 'LAUNCH_CONFIGURATION_DIALOG' constants defined in this class.
165      */

166     private int fOpenMode = LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_LAST_LAUNCHED;
167     
168     /**
169      * dialog settings
170      */

171     private static final String JavaDoc DIALOG_SASH_WEIGHTS_1 = IDebugUIConstants.PLUGIN_ID + ".DIALOG_SASH_WEIGHTS_1"; //$NON-NLS-1$
172
private static final String JavaDoc DIALOG_SASH_WEIGHTS_2 = IDebugUIConstants.PLUGIN_ID + ".DIALOG_SASH_WEIGHTS_2"; //$NON-NLS-1$
173
private static final String JavaDoc DIALOG_EXPANDED_NODES = IDebugUIConstants.PLUGIN_ID + ".EXPANDED_NODES"; //$NON-NLS-1$
174

175     /**
176      * Returns the currently visible dialog
177      * @return the currently visible launch dialog
178      */

179     public static ILaunchConfigurationDialog getCurrentlyVisibleLaunchConfigurationDialog() {
180         return fgCurrentlyVisibleLaunchConfigurationDialog;
181     }
182     /**
183      * Sets which launch dialog is currently the visible one
184      * @param dialog the dialog to set as the visible one
185      */

186     public static void setCurrentlyVisibleLaunchConfigurationDialog(ILaunchConfigurationDialog dialog) {
187         fgCurrentlyVisibleLaunchConfigurationDialog = dialog;
188     }
189     
190     /**
191      * widgets
192      */

193     private Control fLastControl;
194     private Composite fButtonComp;
195     private SashForm fSashForm;
196     private LaunchConfigurationView fLaunchConfigurationView;
197     private LaunchConfigurationTabGroupViewer fTabViewer;
198     private Button fProgressMonitorCancelButton;
199     private ProgressMonitorPart fProgressMonitorPart;
200     private LaunchGroupExtension fGroup;
201     private Image fBannerImage;
202     
203     /**
204      * When this dialog is opened in <code>LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_SELECTION</code>
205      * mode, this specifies the selection that is initially shown in the dialog.
206      */

207     private IStructuredSelection fInitialSelection;
208         
209     /**
210      * The status to open the dialog on, or <code>null</code> if none.
211      */

212     private IStatus fInitialStatus;
213
214     /**
215      * Listener for a list
216      */

217     private ListenerList changeListeners = new ListenerList();
218     
219     /**
220      * The number of 'long-running' operations currently taking place in this dialog
221      */

222     private long fActiveRunningOperations = 0;
223
224     /**
225      * Double-click action
226      */

227     private IAction fDoubleClickAction;
228     
229     /**
230      * Filters for the LCD
231      * @since 3.2
232      */

233     private ClosedProjectFilter fClosedProjectFilter;
234     private DeletedProjectFilter fDeletedProjectFilter;
235     private LaunchConfigurationTypeFilter fLCTFilter;
236     private WorkingSetsFilter fWorkingSetsFilter;
237     
238     /**
239      * set of reserved names that should not be considered when generating a new name for a launch configuration
240      */

241     protected Set JavaDoc fReservedNames = null;
242     
243     /**
244      * Constructs a new launch configuration dialog on the given
245      * parent shell.
246      *
247      * @param shell the parent shell
248      * @param group the group of launch configuration to display
249      */

250     public LaunchConfigurationsDialog(Shell shell, LaunchGroupExtension group) {
251         super(shell);
252         setShellStyle(getShellStyle() | SWT.RESIZE);
253         setLaunchGroup(group);
254     }
255
256     /**
257      * Adds content to the dialog area
258      *
259      * @param dialogComp
260      */

261     protected void addContent(Composite dialogComp) {
262         GridData gd;
263         Composite topComp = new Composite(dialogComp, SWT.NONE);
264         gd = new GridData(GridData.FILL_BOTH);
265         topComp.setLayoutData(gd);
266         GridLayout topLayout = new GridLayout(2, false);
267         topLayout.marginHeight = 5;
268         topLayout.marginWidth = 5;
269         topComp.setLayout(topLayout);
270         
271         // Set the things that TitleAreaDialog takes care of
272
setTitle(LaunchConfigurationsMessages.LaunchConfigurationDialog_Create__manage__and_run_launch_configurations_8);
273         setMessage(LaunchConfigurationsMessages.LaunchConfigurationDialog_Ready_to_launch_2);
274         setModeLabelState();
275         
276         // Create the SashForm that contains the selection area on the left,
277
// and the edit area on the right
278
gd = new GridData(GridData.FILL_BOTH);
279         gd.horizontalSpan = 2;
280         SashForm sash = new SashForm(topComp, SWT.SMOOTH);
281         sash.setOrientation(SWT.HORIZONTAL);
282         sash.setLayoutData(gd);
283         sash.setFont(dialogComp.getFont());
284         sash.setVisible(true);
285         fSashForm = sash;
286         
287         // Build the launch configuration selection area and put it into the composite.
288
Control launchConfigSelectionArea = createLaunchConfigurationSelectionArea(fSashForm);
289         gd = new GridData(GridData.FILL_VERTICAL);
290         launchConfigSelectionArea.setLayoutData(gd);
291         
292         // Build the launch configuration edit area and put it into the composite.
293
Composite editAreaComp = createLaunchConfigurationEditArea(fSashForm);
294         gd = new GridData(GridData.FILL_BOTH);
295         editAreaComp.setLayoutData(gd);
296         
297         dialogComp.layout(true);
298         applyDialogFont(dialogComp);
299     }
300
301     /* (non-Javadoc)
302      * @see org.eclipse.jface.dialogs.IPageChangeProvider#addPageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener)
303      */

304     public void addPageChangedListener(IPageChangedListener listener) {
305         changeListeners.add(listener);
306     }
307     
308     /**
309      * Handle the 'close' & 'launch' buttons here, all others are handled
310      * in <code>Dialog</code>
311      *
312      * @see org.eclipse.jface.dialogs.Dialog#buttonPressed(int)
313      */

314     protected void buttonPressed(int buttonId) {
315         if (buttonId == ID_LAUNCH_BUTTON) {
316             handleLaunchPressed();
317         }
318         else if (buttonId == ID_CLOSE_BUTTON) {
319             handleClosePressed();
320         }
321         else {
322             super.buttonPressed(buttonId);
323         }
324     }
325
326     /**
327      * Return whether the current configuration should be saved or discarded. This involves determining
328      * if it is dirty, and if it is, asking the user what to do.
329      *
330      * @return if we can discard the current config or not
331      */

332     protected int shouldSaveCurrentConfig() {
333         if (getTabViewer().isDirty()) {
334             if (getTabViewer().canSave()) {
335                 return showSaveChangesDialog();
336             }
337             return showUnsavedChangesDialog();
338         }
339         return IDialogConstants.NO_ID;
340     }
341     
342     /* (non-Javadoc)
343      * @see org.eclipse.jface.window.Window#close()
344      */

345     public boolean close() {
346         if (!isSafeToClose()) {
347             return false;
348         }
349         persistSashWeights();
350         persistExpansion();
351         setCurrentlyVisibleLaunchConfigurationDialog(null);
352         getBannerImage().dispose();
353         getTabViewer().dispose();
354         if (fLaunchConfigurationView != null) {
355             fLaunchConfigurationView.dispose();
356         }
357         DebugUIPlugin.getDefault().getPreferenceStore().removePropertyChangeListener(this);
358         return super.close();
359     }
360     
361     /**
362      * Sets the title for the dialog, and establishes the help context.
363      *
364      * @see org.eclipse.jface.window.Window#configureShell(org.eclipse.swt.widgets.Shell);
365      */

366     protected void configureShell(Shell shell) {
367         super.configureShell(shell);
368         shell.setText(getShellTitle());
369     }
370     
371     /* (non-Javadoc)
372      * @see org.eclipse.jface.window.Window#create()
373      */

374     public void create() {
375         super.create();
376         if (getTabViewer().getInput() == null) {
377             getTabViewer().inputChanged(null);
378         }
379     }
380     
381     /* (non-Javadoc)
382      * @see org.eclipse.jface.dialogs.Dialog#createButtonBar(org.eclipse.swt.widgets.Composite)
383      */

384     protected Control createButtonBar(Composite parent) {
385         Font font = parent.getFont();
386         Composite composite = new Composite(parent, SWT.NULL);
387         GridLayout layout = new GridLayout();
388         layout.numColumns = 2;
389         layout.marginHeight= 0;
390         layout.marginWidth= 0;
391         layout.marginLeft = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_MARGIN);
392         composite.setLayout(layout);
393         composite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
394         composite.setFont(font);
395         // create help control if needed
396
if (isHelpAvailable()) {
397             createHelpControl(composite);
398         }
399         Composite monitorComposite = new Composite(composite, SWT.NULL);
400         layout = new GridLayout();
401         layout.marginHeight = 0;
402         layout.marginWidth = 0;
403         layout.numColumns = 2;
404         monitorComposite.setLayout(layout);
405         monitorComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
406         GridLayout pmLayout = new GridLayout();
407         fProgressMonitorPart = new ProgressMonitorPart(monitorComposite, pmLayout);
408         fProgressMonitorPart.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
409         fProgressMonitorPart.setFont(font);
410         fProgressMonitorCancelButton = createButton(monitorComposite, ID_CANCEL_BUTTON, LaunchConfigurationsMessages.LaunchConfigurationDialog_Cancel_3, true);
411         fProgressMonitorCancelButton.setFont(font);
412         monitorComposite.setVisible(false);
413
414         /*
415          * Create the rest of the button bar, but tell it not to
416          * create a help button (we've already created it).
417          */

418         boolean helpAvailable = isHelpAvailable();
419         setHelpAvailable(false);
420         fButtonComp = (Composite) super.createButtonBar(composite);
421         setHelpAvailable(helpAvailable);
422         return composite;
423     }
424
425     
426     
427     /**
428      * A launch configuration dialog overrides this method
429      * to create a custom set of buttons in the button bar.
430      * This dialog has 'Launch' and 'Cancel'
431      * buttons.
432      *
433      * @see org.eclipse.jface.dialogs.Dialog#createButtonsForButtonBar(org.eclipse.swt.widgets.Composite)
434      */

435     protected void createButtonsForButtonBar(Composite parent) {
436         Button button = createButton(parent, ID_LAUNCH_BUTTON, getLaunchButtonText(), true);
437         button.setEnabled(false);
438         createButton(parent, ID_CLOSE_BUTTON, LaunchConfigurationsMessages.LaunchConfigurationDialog_Close_1, false);
439     }
440     
441     /* (non-Javadoc)
442      * @see org.eclipse.jface.window.Window#createContents(org.eclipse.swt.widgets.Composite)
443      */

444     protected Control createContents(Composite parent) {
445         Control contents = super.createContents(parent);
446         initializeContent();
447         PlatformUI.getWorkbench().getHelpSystem().setHelp(getShell(), getHelpContextId());
448         return contents;
449     }
450     
451     /* (non-Javadoc)
452      * @see org.eclipse.jface.dialogs.Dialog#createDialogArea(org.eclipse.swt.widgets.Composite)
453      */

454     protected Control createDialogArea(Composite parent) {
455         Composite dialogComp = (Composite)super.createDialogArea(parent);
456         addContent(dialogComp);
457         if(fLaunchConfigurationView != null) {
458             fLaunchConfigurationView.updateFilterLabel();
459         }
460         return dialogComp;
461     }
462             
463     /**
464      * Creates the launch configuration edit area of the dialog.
465      * This area displays the name of the launch configuration
466      * currently being edited, as well as a tab folder of tabs
467      * that are applicable to the launch configuration.
468      *
469      * @return the composite used for launch configuration editing
470      */

471     protected Composite createLaunchConfigurationEditArea(Composite parent) {
472         setTabViewer(new LaunchConfigurationTabGroupViewer(parent, this));
473         getTabViewer().addSelectionChangedListener(new ISelectionChangedListener() {
474             public void selectionChanged(SelectionChangedEvent event) {
475                 handleTabSelectionChanged();
476             }
477         });
478         return (Composite)getTabViewer().getControl();
479     }
480     
481     /**
482      * Creates all of the actions for the toolbar
483      * @param toolbar
484      * @since 3.2
485      */

486     protected void createToolbarActions(ToolBarManager tmanager) {
487         tmanager.add(getNewAction());
488         tmanager.add(getDuplicateAction());
489         tmanager.add(getDeleteAction());
490         tmanager.add(new Separator());
491         tmanager.add(getCollapseAllAction());
492         tmanager.add(getFilterAction());
493         tmanager.update(true);
494         DebugUIPlugin.getDefault().getPreferenceStore().addPropertyChangeListener(this);
495     }
496     
497     /**
498      * Creates the launch configuration selection area of the dialog.
499      * This area displays a tree of launch configurations that the user
500      * may select, and allows users to create new configurations, and
501      * delete and duplicate existing configurations.
502      *
503      * @return the composite used for launch configuration selection area
504      */

505     protected Control createLaunchConfigurationSelectionArea(Composite parent) {
506         Composite comp = new Composite(parent, SWT.FLAT);
507         GridLayout gridLayout = new GridLayout(1, false);
508         gridLayout.marginHeight = 0;
509         gridLayout.marginWidth = 0;
510         comp.setLayout(gridLayout);
511         comp.setLayoutData(new GridData(GridData.FILL_BOTH));
512         
513         ViewForm viewForm = new ViewForm(comp, SWT.FLAT | SWT.BORDER);
514         ToolBar toolBar = new ToolBar(viewForm, SWT.FLAT);
515         toolBar.setBackground(parent.getBackground());
516         ToolBarManager toolBarManager= new ToolBarManager(toolBar);
517         viewForm.setTopLeft(toolBar);
518         viewForm.setLayoutData(new GridData(GridData.FILL_BOTH));
519         
520         Composite viewFormContents = new Composite(viewForm, SWT.FLAT);
521         gridLayout = new GridLayout();
522         gridLayout.marginHeight = 5;
523         gridLayout.marginWidth = 5;
524         viewFormContents.setLayout(gridLayout);
525         viewFormContents.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND));
526         fLaunchConfigurationView = new LaunchConfigurationView(getLaunchGroup(), createViewerFilters());
527         fLaunchConfigurationView.createLaunchDialogControl(viewFormContents);
528         
529     //create toolbar actions, we reuse the actions from the view so we wait until after
530
//the view is created to add them to the toolbar
531
createToolbarActions(toolBarManager);
532         fDoubleClickAction = new Action() {
533             public void run() {
534                 IStructuredSelection selection = (IStructuredSelection)fLaunchConfigurationView.getViewer().getSelection();
535                 Object JavaDoc target = selection.getFirstElement();
536                 if (target instanceof ILaunchConfiguration) {
537                     if (getTabViewer().canLaunch() & getTabViewer().canLaunchWithModes() & !getTabViewer().hasDuplicateDelegates()) {
538                         handleLaunchPressed();
539                     }
540                 } else {
541                     getNewAction().run();
542                 }
543             }
544         };
545         fLaunchConfigurationView.setAction(IDebugView.DOUBLE_CLICK_ACTION, fDoubleClickAction);
546         Viewer viewer = fLaunchConfigurationView.getViewer();
547         
548         Control control = viewer.getControl();
549         GridData gd = new GridData(GridData.FILL_BOTH);
550         control.setLayoutData(gd);
551         viewForm.setContent(viewFormContents);
552         AbstractLaunchConfigurationAction.IConfirmationRequestor requestor = new AbstractLaunchConfigurationAction.IConfirmationRequestor() {
553             public boolean getConfirmation() {
554                 int status = shouldSaveCurrentConfig();
555                 if(status == IDialogConstants.YES_ID) {
556                     fTabViewer.handleApplyPressed();
557                     return true;
558                 }
559                 else if(status == IDialogConstants.NO_ID) {
560                     fTabViewer.handleRevertPressed();
561                     return true;
562                 }
563                 return false;
564             }
565         };
566         getDuplicateAction().setConfirmationRequestor(requestor);
567         getNewAction().setConfirmationRequestor(requestor);
568         ((StructuredViewer) viewer).addPostSelectionChangedListener(new ISelectionChangedListener() {
569             public void selectionChanged(SelectionChangedEvent event) {
570                 handleLaunchConfigurationSelectionChanged(event);
571                 getNewAction().setEnabled(getNewAction().isEnabled());
572                 getDeleteAction().setEnabled(getDeleteAction().isEnabled());
573                 getDuplicateAction().setEnabled(getDuplicateAction().isEnabled());
574             }
575         });
576         return comp;
577     }
578
579     /**
580      * Create the filters to be initially applied to the viewer.
581      * The initial filters are based on the persisted preferences
582      * @return the array of initial filters
583      * @since 3.2
584      */

585     private ViewerFilter[] createViewerFilters() {
586         ArrayList JavaDoc filters = new ArrayList JavaDoc();
587         fClosedProjectFilter = new ClosedProjectFilter();
588         if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_CLOSED)) {
589             filters.add(fClosedProjectFilter);
590         }
591         fDeletedProjectFilter = new DeletedProjectFilter();
592         if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_DELETED)) {
593             filters.add(fDeletedProjectFilter);
594         }
595         fLCTFilter = new LaunchConfigurationTypeFilter();
596         if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES)) {
597             filters.add(fLCTFilter);
598         }
599         fWorkingSetsFilter = new WorkingSetsFilter();
600         if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_WORKING_SETS)) {
601             filters.add(fWorkingSetsFilter);
602         }
603         return (ViewerFilter[]) filters.toArray(new ViewerFilter[filters.size()]);
604     }
605     
606     /**
607      * Set the initial selection in the tree.
608      */

609     public void doInitialTreeSelection() {
610         fLaunchConfigurationView.getViewer().setSelection(fInitialSelection);
611     }
612     
613     /**
614      * Notifies any selection changed listeners that the selected page
615      * has changed.
616      * Only listeners registered at the time this method is called are notified.
617      *
618      * @param event a selection changed event
619      *
620      * @see IPageChangedListener#pageChanged
621      */

622     protected void firePageChanged(final PageChangedEvent event) {
623         Object JavaDoc[] listeners = changeListeners.getListeners();
624         for (int i = 0; i < listeners.length; ++i) {
625             final IPageChangedListener l = (IPageChangedListener) listeners[i];
626             SafeRunner.run(new SafeRunnable() {
627                 public void run() {
628                     l.pageChanged(event);
629                 }
630             });
631         }
632     }
633     
634     /* (non-Javadoc)
635      * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#generateName(java.lang.String)
636      */

637     public String JavaDoc generateName(String JavaDoc name) {
638         if (name == null) {
639             name = EMPTY_STRING;
640         }
641         return getLaunchManager().generateUniqueLaunchConfigurationNameFrom(name);
642     }
643     
644     /**
645      * Generates and returns a unique name using the specified name as a prefix in the event
646      * the specified name already exists or is contained in the set of reserved names.
647      * @param name the name to use as a prefix for generating a new name
648      * @param reservednames a listing of names that should be considered as 'taken' and cannot be generated
649      * by this method
650      * @return a new name based on the specified name.
651      *
652      * @since 3.3
653      */

654     public String JavaDoc generateName(String JavaDoc name, Set JavaDoc reservednames) {
655         if(name == null) {
656             name = EMPTY_STRING;
657         }
658         return ((LaunchManager)getLaunchManager()).generateUniqueLaunchConfigurationNameFrom(name, reservednames);
659     }
660     
661     /* (non-Javadoc)
662      * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#getActiveTab()
663      */

664     public ILaunchConfigurationTab getActiveTab() {
665         return getTabViewer().getActiveTab();
666     }
667     
668     /**
669      * Returns the banner image to display in the title area
670      */

671     protected Image getBannerImage() {
672         if (fBannerImage == null) {
673             ImageDescriptor descriptor = getLaunchGroup().getBannerImageDescriptor();
674             if (descriptor != null) {
675                 fBannerImage = descriptor.createImage();
676             }
677         }
678         return fBannerImage;
679     }
680     
681     /**
682      * Gets the delete menu action
683      *
684      * @return the delete menu action
685      */

686     protected AbstractLaunchConfigurationAction getDeleteAction() {
687         return (AbstractLaunchConfigurationAction)fLaunchConfigurationView.getAction(DeleteLaunchConfigurationAction.ID_DELETE_ACTION);
688     }
689
690     /**
691      * Gets the filter action
692      * @return the filter menu action
693      * @since 3.2
694      */

695     protected IAction getFilterAction() {
696         return fLaunchConfigurationView.getAction(FilterLaunchConfigurationAction.ID_FILTER_ACTION);
697     }
698     
699     /**
700      * Gets the collapse all action
701      * @return the collapse all action
702      * @since 3.2
703      */

704     protected IAction getCollapseAllAction() {
705         return fLaunchConfigurationView.getAction(CollapseAllLaunchConfigurationAction.ID_COLLAPSEALL_ACTION);
706     }
707     
708      /* (non-Javadoc)
709      * @see org.eclipse.jface.dialogs.Dialog#getDialogBoundsSettings()
710      * @since 3.2
711      */

712     protected IDialogSettings getDialogBoundsSettings() {
713         return getDialogSettings();
714     }
715     
716     /**
717      * Returns the dialog settings for this dialog. Subclasses should override
718      * <code>getDialogSettingsSectionName()</code>.
719      *
720      * @return IDialogSettings
721      */

722     protected IDialogSettings getDialogSettings() {
723         IDialogSettings settings = DebugUIPlugin.getDefault().getDialogSettings();
724         IDialogSettings section = settings.getSection(getDialogSettingsSectionName());
725         if (section == null) {
726             section = settings.addNewSection(getDialogSettingsSectionName());
727         }
728         return section;
729     }
730
731     /**
732      * Returns the name of the section that this dialog stores its settings in
733      *
734      * @return String
735      */

736     protected String JavaDoc getDialogSettingsSectionName() {
737         return IDebugUIConstants.PLUGIN_ID + ".LAUNCH_CONFIGURATIONS_DIALOG_SECTION"; //$NON-NLS-1$
738
}
739         
740     /**
741      * Gets the current display
742      *
743      * @return the display
744      */

745     protected Display getDisplay() {
746         Shell shell = getShell();
747         if (shell != null) {
748             return shell.getDisplay();
749         }
750         return Display.getDefault();
751     }
752     
753     /**
754      * Gets the duplicate menu action
755      *
756      * @return the duplicate menu action
757      */

758     protected AbstractLaunchConfigurationAction getDuplicateAction() {
759         return (AbstractLaunchConfigurationAction)fLaunchConfigurationView.getAction(DuplicateLaunchConfigurationAction.ID_DUPLICATE_ACTION);
760     }
761     
762     /**
763      * Gets the help context id
764      *
765      * @return the help context id
766      */

767     protected String JavaDoc getHelpContextId() {
768         return IDebugHelpContextIds.LAUNCH_CONFIGURATION_DIALOG;
769     }
770  
771     /**
772      * Returns the status the dialog was opened on or <code>null</code> if none.
773      *
774      * @return IStatus
775      */

776     protected IStatus getInitialStatus() {
777         return fInitialStatus;
778     }
779             
780     /**
781      * Return the last launched configuration in the workspace.
782      *
783      * @return the last launched configuration
784      */

785     protected ILaunchConfiguration getLastLaunchedWorkbenchConfiguration() {
786         return DebugUIPlugin.getDefault().getLaunchConfigurationManager().getLastLaunch(getLaunchGroup().getIdentifier());
787     }
788
789     /**
790      * Returns the appropriate text for the launch button - run or debug.
791      *
792      * @return the launch button text
793      */

794     protected String JavaDoc getLaunchButtonText() {
795         return DebugPlugin.getDefault().getLaunchManager().getLaunchMode(getMode()).getLabel();
796     }
797      
798     /**
799      * Returns the launch group being displayed.
800      *
801      * @return launch group
802      */

803     public LaunchGroupExtension getLaunchGroup() {
804         return fGroup;
805     }
806             
807     /* (non-Javadoc)
808      * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#getMode()
809      */

810     public String JavaDoc getMode() {
811         return getLaunchGroup().getMode();
812     }
813     
814     /**
815      * Gets the new menu action
816      *
817      * @return the new menu action
818      */

819     protected AbstractLaunchConfigurationAction getNewAction() {
820         return (AbstractLaunchConfigurationAction)fLaunchConfigurationView.getAction(CreateLaunchConfigurationAction.ID_CREATE_ACTION);
821     }
822     
823     /**
824      * Returns the reserved name set (if there is one), <code>null</code> otherwise
825      * @return the reserved name set or <code>null</code>
826      * @since 3.3
827      *
828      */

829     public Set JavaDoc getReservedNameSet() {
830         return fReservedNames;
831     }
832     
833     /**
834      * returns the open mode
835      *
836      * @return the open mode
837      */

838     protected int getOpenMode() {
839         return fOpenMode;
840     }
841     
842     /* (non-Javadoc)
843      * @see org.eclipse.jface.dialogs.IPageChangeProvider#getSelectedPage()
844      */

845     public Object JavaDoc getSelectedPage() {
846         return getActiveTab();
847     }
848     
849     /**
850      * Returns the title of the shell
851      * @return the shell title
852      */

853     protected String JavaDoc getShellTitle() {
854         String JavaDoc title = null;
855         if(getLaunchGroup() != null) {
856              title = DebugUIPlugin.removeAccelerators(getLaunchGroup().getLabel());
857         }
858         if (title == null) {
859             title = LaunchConfigurationsMessages.LaunchConfigurationDialog_Launch_Configurations_18;
860         }
861         return title;
862     }
863
864     /**
865      * Returns the current tab group
866      *
867      * @return the current tab group, or <code>null</code> if none
868      */

869     public ILaunchConfigurationTabGroup getTabGroup() {
870         if (getTabViewer() != null) {
871             return getTabViewer().getTabGroup();
872         }
873         return null;
874     }
875
876     /* (non-Javadoc)
877      * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#getTabs()
878      */

879     public ILaunchConfigurationTab[] getTabs() {
880         if (getTabGroup() == null) {
881             return null;
882         }
883         return getTabGroup().getTabs();
884     }
885
886     /**
887      * Returns the viewer used to display the tabs for a launch configuration.
888      *
889      * @return LaunchConfigurationTabGroupViewer
890      */

891     protected LaunchConfigurationTabGroupViewer getTabViewer() {
892         return fTabViewer;
893     }
894
895     /**
896      * Notification the 'Close' button has been pressed.
897      */

898     protected void handleClosePressed() {
899         int status = shouldSaveCurrentConfig();
900         if(status != IDialogConstants.CANCEL_ID) {
901             if(status != ID_DISCARD_BUTTON) {
902                 if(status == IDialogConstants.YES_ID) {
903                     getTabViewer().handleApplyPressed();
904                 }
905                 cancelPressed();
906             }
907         }
908     }
909     
910     /**
911      * Notification that selection has changed in the launch configuration tree.
912      * <p>
913      * If the currently displayed configuration is not saved,
914      * prompt for saving before moving on to the new selection.
915      * </p>
916      *
917      * @param event selection changed event
918      */

919     protected void handleLaunchConfigurationSelectionChanged(SelectionChangedEvent event) {
920         Object JavaDoc input = getTabViewer().getInput();
921         Object JavaDoc newInput = null;
922         IStructuredSelection selection = (IStructuredSelection) event.getSelection();
923         if (!selection.isEmpty()) {
924             if (selection.size() == 1) {
925                 newInput = selection.getFirstElement();
926             }
927         }
928         if (!isEqual(input, newInput)) {
929             LaunchConfigurationTabGroupViewer viewer = getTabViewer();
930             ILaunchConfiguration original = viewer.getOriginal();
931             if (original != null && newInput == null && getLaunchManager().getMovedTo(original) != null) {
932                 return;
933             }
934             boolean deleted = false;
935             if (original != null) {
936                 deleted = !original.exists();
937             }
938             boolean renamed = false;
939             if (newInput instanceof ILaunchConfiguration) {
940                 renamed = getLaunchManager().getMovedFrom((ILaunchConfiguration)newInput) != null;
941             }
942             Object JavaDoc in = input;
943             if (viewer.isDirty() && !deleted && !renamed) {
944                 if(fLaunchConfigurationView != null) {
945                     fLaunchConfigurationView.setAutoSelect(false);
946                 }
947                 int ret = showUnsavedChangesDialog();
948                 boolean cansave = viewer.canSave();
949                 if(ret == IDialogConstants.YES_ID) {
950                     if(cansave) {
951                         viewer.handleApplyPressed();
952                     }
953                     else {
954                         viewer.handleRevertPressed();
955                     }
956                     in = newInput;
957                 }
958                 else if(ret == IDialogConstants.NO_ID) {
959                     if(cansave) {
960                         viewer.handleRevertPressed();
961                         if(viewer.isDirty()) {
962                             viewer.handleApplyPressed();
963                         }
964                         in = newInput;
965                     }
966                 }
967                 if(fLaunchConfigurationView != null) {
968                     if(in != null) {
969                         fLaunchConfigurationView.getViewer().setSelection(new StructuredSelection(in));
970                     }
971                     fLaunchConfigurationView.setAutoSelect(true);
972                 }
973             }
974             else {
975                 viewer.setInput(newInput);
976                 if(newInput != null) {
977                     if(viewer.isDirty()) {
978                         viewer.handleApplyPressed();
979                     }
980                     if (getShell() != null && getShell().isVisible()) {
981                         resize();
982                     }
983                 }
984             }
985             
986         }
987     }
988     
989     /**
990      * Notification the 'launch' button has been pressed.
991      * Save and launch.
992      */

993     protected void handleLaunchPressed() {
994         ILaunchConfiguration config = getTabViewer().getOriginal();
995         if (getTabViewer().isDirty() & getTabViewer().canSave()) {
996             getTabViewer().handleApplyPressed();
997             config = getTabViewer().getOriginal();
998         }
999         String JavaDoc mode = getMode();
1000        close();
1001        if(config != null) {
1002            DebugUITools.launch(config, mode);
1003        }
1004    }
1005
1006    /**
1007     * Consult a status handler for the given status, if any. The status handler
1008     * is passed this launch config dialog as an argument.
1009     *
1010     * @param status the status to be handled
1011     */

1012    public void handleStatus(IStatus status) {
1013        IStatusHandler handler = DebugPlugin.getDefault().getStatusHandler(status);
1014        if (handler != null) {
1015            try {
1016                handler.handleStatus(status, this);
1017                return;
1018            }
1019            catch (CoreException e) {status = e.getStatus();}
1020        }
1021        // if no handler, or handler failed, display error/warning dialog
1022
String JavaDoc title = null;
1023        switch (status.getSeverity()) {
1024            case IStatus.ERROR:
1025                title = LaunchConfigurationsMessages.LaunchConfigurationsDialog_Error_1;
1026                break;
1027            case IStatus.WARNING:
1028                title = LaunchConfigurationsMessages.LaunchConfigurationsDialog_Warning_2;
1029                break;
1030            default:
1031                title = LaunchConfigurationsMessages.LaunchConfigurationsDialog_Information_3;
1032                break;
1033        }
1034        ErrorDialog.openError(getShell(), title, null, status);
1035    }
1036    
1037    /**
1038     * Notification that tab selection has changed.
1039     *
1040     */

1041    protected void handleTabSelectionChanged() {
1042        updateMessage();
1043        firePageChanged(new PageChangedEvent(this, getSelectedPage()));
1044    }
1045
1046    /* (non-Javadoc)
1047     * @see org.eclipse.jface.window.Window#initializeBounds()
1048     */

1049    protected void initializeBounds() {
1050        IDialogSettings settings = getDialogSettings();
1051        if (fSashForm != null) {
1052            int w1, w2;
1053            try {
1054                w1 = settings.getInt(DIALOG_SASH_WEIGHTS_1);
1055                w2 = settings.getInt(DIALOG_SASH_WEIGHTS_2);
1056            }
1057            catch(NumberFormatException JavaDoc nfe) {
1058                w1 = DEFAULT_SASH_WEIGHTS[0];
1059                w2 = DEFAULT_SASH_WEIGHTS[1];
1060            }
1061            fSashForm.setWeights(new int[] {w1, w2});
1062        }
1063        super.initializeBounds();
1064    }
1065    
1066    /* (non-Javadoc)
1067     * @see org.eclipse.jface.dialogs.TitleAreaDialog#getInitialSize()
1068     */

1069    protected Point getInitialSize() {
1070        IDialogSettings settings = getDialogSettings();
1071        if(settings.get(DIALOG_SASH_WEIGHTS_1) != null) {
1072            return super.getInitialSize();
1073        }
1074        return DEFAULT_INITIAL_DIALOG_SIZE;
1075    }
1076
1077    /**
1078     * Performs initialization of the content by setting the initial tree selection
1079     */

1080    protected void initializeContent() {
1081        doInitialTreeSelection();
1082        IStatus status = getInitialStatus();
1083        if (status != null) {
1084            handleStatus(status);
1085        }
1086        fLaunchConfigurationView.getFilteringTextControl().setFocus();
1087        restoreExpansion();
1088    }
1089    
1090    /**
1091     * Compares two objects to determine their equality
1092     *
1093     * @param o1 the first object
1094     * @param o2 the object to compare to object one
1095     * @return true if they are equal, false if object 1 is null, the result of o1.equals(o2) otherwise
1096     */

1097    protected boolean isEqual(Object JavaDoc o1, Object JavaDoc o2) {
1098        if (o1 == o2) {
1099            return true;
1100        } else if (o1 == null) {
1101            return false;
1102        } else {
1103            return o1.equals(o2);
1104        }
1105    }
1106
1107    /**
1108     * Returns whether the dialog can be closed
1109     *
1110     * @return whether the dialog can be closed
1111     */

1112    protected boolean isSafeToClose() {
1113        return fActiveRunningOperations == 0;
1114    }
1115    
1116    /**
1117     * Determine the initial configuration for this dialog.
1118     * Open the dialog in the mode set using #setOpenMode(int) and return one of
1119     * <code>Window. OK</code> or <code>Window.CANCEL</code>.
1120     *
1121     * @see org.eclipse.jface.window.Window#open()
1122     * @return the int status of opening the dialog
1123     */

1124    public int open() {
1125        int mode = getOpenMode();
1126        setCurrentlyVisibleLaunchConfigurationDialog(this);
1127        if (mode == LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_LAST_LAUNCHED) {
1128            ILaunchConfiguration lastLaunchedConfig = getLastLaunchedWorkbenchConfiguration();
1129            if (lastLaunchedConfig != null) {
1130                setInitialSelection(new StructuredSelection(lastLaunchedConfig));
1131            }
1132        }
1133        return super.open();
1134    }
1135    
1136    /**
1137     * saves which of the nodes are expanded at the time the dialog is closed
1138     * @since 3.2
1139     */

1140    protected void persistExpansion() {
1141        if(fLaunchConfigurationView != null) {
1142            IDialogSettings settings = getDialogSettings();
1143            TreeItem[] items = fLaunchConfigurationView.getTreeViewer().getTree().getItems();
1144            String JavaDoc value = settings.get(DIALOG_EXPANDED_NODES);
1145            if(value == null) {
1146                value = EMPTY_STRING;
1147            }
1148            ArrayList JavaDoc list = new ArrayList JavaDoc();
1149            String JavaDoc[] persisted = value.split(DELIMITER);
1150            for(int i = 0; i < persisted.length; i++) {
1151                list.add(persisted[i]);
1152            }
1153            String JavaDoc type = EMPTY_STRING;
1154            //if the item is not in the list and is expanded add it, otherwise if it
1155
//is not expanded do a remove...either way for the else we query the list
1156
for(int i = 0; i < items.length; i++) {
1157                type = ((ILaunchConfigurationType)items[i].getData()).getIdentifier();
1158                if(!list.contains(type) & items[i].getExpanded()) {
1159                    list.add(type);
1160                }
1161                else if(!items[i].getExpanded()) {
1162                    list.remove(type);
1163                }
1164            }
1165            value = EMPTY_STRING;
1166            //build the preference string
1167
for(Iterator JavaDoc iter = list.iterator(); iter.hasNext();) {
1168                value += iter.next() + DELIMITER;
1169            }
1170            settings.put(DIALOG_EXPANDED_NODES, value);
1171        }
1172    }
1173    
1174    /**
1175     * Restore the original expansion state of the nodes in the viewer
1176     * @since 3.2
1177     */

1178    protected void restoreExpansion() {
1179        if(fLaunchConfigurationView != null) {
1180            IDialogSettings settings = getDialogSettings();
1181            String JavaDoc value = settings.get(DIALOG_EXPANDED_NODES);
1182            if(value != null) {
1183                String JavaDoc[] nodes = value.split(DELIMITER);
1184                TreeItem[] items = fLaunchConfigurationView.getTreeViewer().getTree().getItems();
1185                ArrayList JavaDoc toexpand = new ArrayList JavaDoc();
1186                // if we have a selection make sure it is expanded
1187
if(fInitialSelection != null && !fInitialSelection.isEmpty()) {
1188                    Object JavaDoc obj = fInitialSelection.getFirstElement();
1189                    if(obj instanceof ILaunchConfigurationType) {
1190                        toexpand.add(obj);
1191                    }
1192                    else if(obj instanceof ILaunchConfiguration) {
1193                        try {
1194                            toexpand.add(((ILaunchConfiguration) obj).getType());
1195                        }
1196                        catch (CoreException e) {DebugUIPlugin.log(e);}
1197                    }
1198                }
1199                for(int i = 0; i < nodes.length; i++) {
1200                    for(int k = 0; k < items.length; k++) {
1201                        ILaunchConfigurationType type = (ILaunchConfigurationType)items[k].getData();
1202                        if(type.getIdentifier().equals(nodes[i])) {
1203                            toexpand.add(type);
1204                        }
1205                    }
1206                }
1207                fLaunchConfigurationView.getTreeViewer().setExpandedElements(toexpand.toArray());
1208            }
1209        }
1210    }
1211    
1212    /**
1213     * Save the current sash weights
1214     */

1215    protected void persistSashWeights() {
1216        IDialogSettings settings = getDialogSettings();
1217        if (fSashForm != null) {
1218            int[] sashWeights = fSashForm.getWeights();
1219            settings.put(DIALOG_SASH_WEIGHTS_1, sashWeights[0]);
1220            settings.put(DIALOG_SASH_WEIGHTS_2, sashWeights[1]);
1221        }
1222    }
1223    
1224    /**
1225     * Update buttons and message.
1226     */

1227    protected void refreshStatus() {
1228        updateMessage();
1229        updateButtons();
1230    }
1231    
1232    /* (non-Javadoc)
1233     * @see org.eclipse.jface.dialogs.IPageChangeProvider#removePageChangedListener(org.eclipse.jface.dialogs.IPageChangedListener)
1234     */

1235    public void removePageChangedListener(IPageChangedListener listener) {
1236        changeListeners.remove(listener);
1237    }
1238
1239    /**
1240     * resize the dialog to show all relevant content, maintains aspect in all resolutions down to 1024x768
1241     */

1242    protected void resize() {
1243        if(getTabGroup() != null) {
1244            Point shell = getShell().getSize();
1245            int maxx = (int)(getDisplay().getBounds().width * MAX_DIALOG_WIDTH_PERCENT),
1246                maxy = (int) (getDisplay().getBounds().height * MAX_DIALOG_HEIGHT_PERCENT);
1247            maxx = (maxx < DEFAULT_INITIAL_DIALOG_SIZE.x ? DEFAULT_INITIAL_DIALOG_SIZE.x : maxx);
1248            maxy = (maxy < DEFAULT_INITIAL_DIALOG_SIZE.y ? DEFAULT_INITIAL_DIALOG_SIZE.y : maxy);
1249            Point psize = getShell().computeSize(SWT.DEFAULT, maxy);
1250            if((psize.x > maxx ? maxx : psize.x) > shell.x || (psize.y > maxy ? maxy : psize.y) > shell.y) {
1251                setShellSize(Math.min(psize.x, maxx), Math.min(psize.y, maxy));
1252            }
1253        }
1254    }
1255
1256    /* (non-Javadoc)
1257     * @see org.eclipse.jface.operation.IRunnableContext#run(boolean, boolean, org.eclipse.jface.operation.IRunnableWithProgress)
1258     */

1259    public void run(boolean fork, boolean cancelable, IRunnableWithProgress runnable) throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
1260        if (getShell() != null && getShell().isVisible()) {
1261            // Save focus control
1262
fLastControl = getShell().getDisplay().getFocusControl();
1263            if (fLastControl != null && fLastControl.getShell() != getShell()) {
1264                fLastControl = null;
1265            }
1266            fProgressMonitorCancelButton.setEnabled(cancelable);
1267            // Attach the progress monitor part to the cancel button
1268
fProgressMonitorPart.attachToCancelComponent(fProgressMonitorCancelButton);
1269            fProgressMonitorPart.getParent().setVisible(true);
1270            fProgressMonitorCancelButton.setFocus();
1271            fActiveRunningOperations++;
1272            
1273        //do work here collecting enabled states, otherwise to get these states we would need to
1274
//perform the validation of the dialog again, which is expensive and would cause flashing of widgets.
1275
Control[] children = ((Composite)fButtonComp.getChildren()[0]).getChildren();
1276            boolean[] prev = new boolean[children.length+2];
1277            prev[0] = getTabViewer().getApplyButton().isEnabled();
1278            prev[1] = getTabViewer().getRevertButton().isEnabled();
1279            for(int i = 0; i < children.length; i++) {
1280                prev[i+2] = children[i].isEnabled();
1281            }
1282            try {
1283                updateRunnnableControls(false, prev);
1284                ModalContext.run(runnable, fork, fProgressMonitorPart, getShell().getDisplay());
1285            }
1286            finally {
1287                fActiveRunningOperations--;
1288                updateRunnnableControls(true, prev);
1289                if (getShell() != null) {
1290                    fProgressMonitorPart.getParent().setVisible(false);
1291                    fProgressMonitorPart.removeFromCancelComponent(fProgressMonitorCancelButton);
1292                    if (fLastControl != null) {
1293                        fLastControl.setFocus();
1294                    }
1295                }
1296            }
1297        }
1298        else {
1299            PlatformUI.getWorkbench().getProgressService().run(fork, cancelable, runnable);
1300        }
1301    }
1302    
1303    /**
1304     * Updates the enablement of the runnable controls to appear disabled as a job is running
1305     * @param enabled the desired enable status of the dialog area, revert//apply buttons, and
1306     * @param prev the previous settings for the apply and revert buttons to be reset to, only takes effect if enable is set to true
1307     * any children of the button bar
1308     * @since 3.3.0
1309     */

1310    private void updateRunnnableControls(boolean enabled, boolean[] prev) {
1311        getTabViewer().getApplyButton().setEnabled(enabled ? prev[0] : enabled);
1312        getTabViewer().getRevertButton().setEnabled(enabled ? prev[1] : enabled);
1313        //the arrangement never differs: button comp has one child that holds all the buttons
1314
Control[] children = ((Composite)fButtonComp.getChildren()[0]).getChildren();
1315        for(int i = 0; i < children.length; i++) {
1316            children[i].setEnabled(enabled ? prev[i+2] : enabled);
1317        }
1318        getDialogArea().setEnabled(enabled);
1319    }
1320    
1321    /* (non-Javadoc)
1322     * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#setActiveTab(org.eclipse.debug.ui.ILaunchConfigurationTab)
1323     */

1324    public void setActiveTab(ILaunchConfigurationTab tab) {
1325        getTabViewer().setActiveTab(tab);
1326    }
1327    
1328    /* (non-Javadoc)
1329     * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#setActiveTab(int)
1330     */

1331    public void setActiveTab(int index) {
1332        getTabViewer().setActiveTab(index);
1333    }
1334    
1335    /**
1336     * Sets the initial selection for the dialog when opened in
1337     * <code>LAUNCH_CONFIGURATION_DIALOG_OPEN_ON_SELECTION</code> mode.
1338     */

1339    public void setInitialSelection(IStructuredSelection selection) {
1340        fInitialSelection = selection;
1341    }
1342    
1343    /**
1344     * Sets the status to open the dialog on.
1345     *
1346     * @param status the initial status for the dialog
1347     */

1348    public void setInitialStatus(IStatus status) {
1349        fInitialStatus = status;
1350    }
1351    
1352    /**
1353     * Sets the launch group to display.
1354     *
1355     * @param group launch group
1356     */

1357    protected void setLaunchGroup(LaunchGroupExtension group) {
1358        fGroup = group;
1359    }
1360    
1361    /**
1362     * Set the title area image based on the mode this dialog was initialized with
1363     */

1364    protected void setModeLabelState() {
1365        setTitleImage(getBannerImage());
1366    }
1367
1368    /* (non-Javadoc)
1369     * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#setName(java.lang.String)
1370     */

1371    public void setName(String JavaDoc name) {
1372        getTabViewer().setName(name);
1373    }
1374    
1375    /**
1376     * Returns the current launch manager
1377     * @return the current launch manager
1378     */

1379    protected ILaunchManager getLaunchManager() {
1380        return DebugPlugin.getDefault().getLaunchManager();
1381    }
1382    
1383    /**
1384     * Set the flag indicating how this dialog behaves when the <code>open()</code> method is called.
1385     * Valid values are defined by the LAUNCH_CONFIGURATION_DIALOG... constants in this class.
1386     */

1387    public void setOpenMode(int mode) {
1388        fOpenMode = mode;
1389    }
1390    
1391    /**
1392     * Increase the size of this dialog's <code>Shell</code> by the specified amounts.
1393     * Do not increase the size of the Shell beyond the bounds of the Display.
1394     */

1395    protected void setShellSize(int width, int height) {
1396        Rectangle bounds = getShell().getMonitor().getBounds();
1397        getShell().setSize(Math.min(width, bounds.width), Math.min(height, bounds.height));
1398    }
1399
1400    /**
1401     * Sets the viewer used to display the tabs for a launch configuration.
1402     *
1403     * @param viewer the new view to set
1404     */

1405    protected void setTabViewer(LaunchConfigurationTabGroupViewer viewer) {
1406        fTabViewer = viewer;
1407    }
1408
1409    /**
1410     * Create and return a dialog that asks the user whether they want to discard
1411     * unsaved changes.
1412     *
1413     * @return the return code based on the button selected.
1414     * The value will be one of <code>YES_ID</code> or <code>NO_ID</code> from
1415     * <code>IDialogConstants</code>.
1416     */

1417    private int showDiscardChangesDialog() {
1418        StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationDialog_The_configuration___35, new String JavaDoc[]{getTabViewer().getWorkingCopy().getName()}));
1419        buffer.append(getTabViewer().getErrorMesssage());
1420        buffer.append(LaunchConfigurationsMessages.LaunchConfigurationDialog_Do_you_wish_to_discard_changes_37);
1421        MessageDialog dialog = new MessageDialog(getShell(),
1422                                                 LaunchConfigurationsMessages.LaunchConfigurationDialog_Discard_changes__38,
1423                                                 null,
1424                                                 buffer.toString(),
1425                                                 MessageDialog.QUESTION,
1426                                                 new String JavaDoc[] {LaunchConfigurationsMessages.LaunchConfigurationDialog_Yes_32,
1427                                                               LaunchConfigurationsMessages.LaunchConfigurationDialog_No_33},
1428                                                 1);
1429        int val = IDialogConstants.NO_ID;
1430        if (dialog.open() == 0) {
1431            if (fLaunchConfigurationView != null) {
1432                fLaunchConfigurationView.setAutoSelect(false);
1433            }
1434            getTabViewer().handleRevertPressed();
1435            val = IDialogConstants.YES_ID;
1436            if (fLaunchConfigurationView != null) {
1437                fLaunchConfigurationView.setAutoSelect(true);
1438            }
1439        }
1440        if(val == IDialogConstants.NO_ID) {
1441            val = ID_DISCARD_BUTTON;
1442        }
1443        return val;
1444    }
1445
1446    /**
1447     * Create and return a dialog that asks the user whether they want to save
1448     * unsaved changes.
1449     *
1450     * @return the return code based on the button selected.
1451     * The value will be one of <code>YES_ID</code>, <code>NO_ID</code>, or <code>CANCEL_ID</code>, from
1452     * <code>IDialogConstants</code>.
1453     */

1454    private int showSaveChangesDialog() {
1455        String JavaDoc message = MessageFormat.format(LaunchConfigurationsMessages.LaunchConfigurationDialog_The_configuration___29, new String JavaDoc[]{getTabViewer().getWorkingCopy().getName()});
1456        MessageDialog dialog = new MessageDialog(getShell(),
1457                                                 LaunchConfigurationsMessages.LaunchConfigurationDialog_Save_changes__31,
1458                                                 null,
1459                                                 message,
1460                                                 MessageDialog.QUESTION,
1461                                                 new String JavaDoc[] {LaunchConfigurationsMessages.LaunchConfigurationDialog_Yes_32,
1462                                                               LaunchConfigurationsMessages.LaunchConfigurationDialog_No_33,
1463                                                               LaunchConfigurationsMessages.LaunchConfigurationsDialog_c_ancel},
1464                                                 0);
1465        int ret = dialog.open();
1466        int val = IDialogConstants.CANCEL_ID;
1467        if (ret == 0 || ret == 1) {
1468            if (ret == 0) {
1469                val = IDialogConstants.YES_ID;
1470            }
1471            else {
1472                val = IDialogConstants.NO_ID;
1473            }
1474        }
1475        return val;
1476    }
1477
1478    /**
1479     * Show the user a dialog appropriate to whether the unsaved changes in the current config
1480     * can be saved or not. Return <code>true</code> if the user indicated that they wish to replace
1481     * the current config, either by saving changes or by discarding the, return <code>false</code>
1482     * otherwise.
1483     *
1484     * @return returns the <code>showSaveChangesDialog</code> return value
1485     */

1486    private int showUnsavedChangesDialog() {
1487        if (getTabViewer().canSave()) {
1488            return showSaveChangesDialog();
1489        }
1490        return showDiscardChangesDialog();
1491    }
1492
1493    /* (non-Javadoc)
1494     * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#updateButtons()
1495     */

1496    public void updateButtons() {
1497        // New, Delete, & Duplicate toolbar actions
1498
getNewAction().setEnabled(getNewAction().isEnabled());
1499        getDeleteAction().setEnabled(getDeleteAction().isEnabled());
1500        getDuplicateAction().setEnabled(getDuplicateAction().isEnabled());
1501        getTabViewer().refresh();
1502        getButton(ID_LAUNCH_BUTTON).setEnabled(getTabViewer().canLaunch() & getTabViewer().canLaunchWithModes() & !getTabViewer().hasDuplicateDelegates());
1503    }
1504
1505    /* (non-Javadoc)
1506     * @see org.eclipse.debug.ui.ILaunchConfigurationDialog#updateMessage()
1507     */

1508    public void updateMessage() {
1509        setErrorMessage(getTabViewer().getErrorMesssage());
1510        setMessage(getTabViewer().getMessage());
1511    }
1512    
1513    /**
1514     * Returns if there is a selection in the tree viewer or not
1515     * @return true if something in the tree is selected, false otherwise
1516     * @since 3.2
1517     */

1518    public boolean isTreeSelectionEmpty() {
1519        return fLaunchConfigurationView.getTreeViewer().getSelection().isEmpty();
1520    }
1521    
1522    /* (non-Javadoc)
1523     * @see org.eclipse.jface.util.IPropertyChangeListener#propertyChange(org.eclipse.jface.util.PropertyChangeEvent)
1524     */

1525    public void propertyChange(final PropertyChangeEvent event) {
1526        WorkbenchJob job = new WorkbenchJob(EMPTY_STRING) {
1527            public IStatus runInUIThread(IProgressMonitor monitor) {
1528                TreeViewer viewer = fLaunchConfigurationView.getTreeViewer();
1529                boolean newvalue = Boolean.valueOf(event.getNewValue().toString()).booleanValue();
1530                if(event.getProperty().equals(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_CLOSED)) {
1531                    updateFilter(newvalue, fClosedProjectFilter);
1532                }
1533                else if(event.getProperty().equals(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_DELETED)) {
1534                    updateFilter(newvalue, fDeletedProjectFilter);
1535                }
1536                else if(event.getProperty().equals(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES)) {
1537                    updateFilter(newvalue, fLCTFilter);
1538                }
1539                else if(event.getProperty().equals(IInternalDebugUIConstants.PREF_FILTER_WORKING_SETS)) {
1540                    updateFilter(newvalue, fWorkingSetsFilter);
1541                }
1542                else if(event.getProperty().equals(IInternalDebugUIConstants.PREF_FILTER_TYPE_LIST)) {
1543                    if(DebugUIPlugin.getDefault().getPreferenceStore().getBoolean(IInternalDebugUIConstants.PREF_FILTER_LAUNCH_TYPES)) {
1544                        viewer.refresh();
1545                        fLaunchConfigurationView.updateFilterLabel();
1546                    }
1547                }
1548                
1549                return Status.OK_STATUS;
1550            }
1551        };
1552        job.runInUIThread(new NullProgressMonitor());
1553    }
1554
1555    /**
1556     * Updates the state of a filter based on the state variable
1557     * @param state if the filter needs to be added or removed, true indicates add, false indicates remove
1558     * @param filter the filter to update
1559     */

1560    private void updateFilter(boolean state, ViewerFilter filter) {
1561        TreeViewer viewer = (TreeViewer)fLaunchConfigurationView.getViewer();
1562        if(state) {
1563            viewer.addFilter(filter);
1564        }
1565        else {
1566            viewer.removeFilter(filter);
1567        }
1568        fLaunchConfigurationView.updateFilterLabel();
1569    }
1570}
1571
Popular Tags