KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > externaltools > internal > ui > BuilderPropertyPage


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.externaltools.internal.ui;
12
13
14 import java.lang.reflect.InvocationTargetException JavaDoc;
15 import java.util.ArrayList JavaDoc;
16 import java.util.HashMap JavaDoc;
17 import java.util.Iterator JavaDoc;
18 import java.util.List JavaDoc;
19 import java.util.Map JavaDoc;
20
21 import org.eclipse.core.resources.ICommand;
22 import org.eclipse.core.resources.IFolder;
23 import org.eclipse.core.resources.IProject;
24 import org.eclipse.core.resources.IProjectDescription;
25 import org.eclipse.core.resources.IResource;
26 import org.eclipse.core.resources.IWorkspace;
27 import org.eclipse.core.resources.IWorkspaceDescription;
28 import org.eclipse.core.resources.IncrementalProjectBuilder;
29 import org.eclipse.core.resources.ResourcesPlugin;
30 import org.eclipse.core.runtime.CoreException;
31 import org.eclipse.core.runtime.IAdaptable;
32 import org.eclipse.core.runtime.IExtension;
33 import org.eclipse.core.runtime.IProgressMonitor;
34 import org.eclipse.core.runtime.IStatus;
35 import org.eclipse.core.runtime.Platform;
36 import org.eclipse.core.runtime.Status;
37 import org.eclipse.debug.core.DebugPlugin;
38 import org.eclipse.debug.core.ILaunchConfiguration;
39 import org.eclipse.debug.core.ILaunchConfigurationListener;
40 import org.eclipse.debug.core.ILaunchConfigurationType;
41 import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
42 import org.eclipse.debug.core.ILaunchManager;
43 import org.eclipse.debug.ui.DebugUITools;
44 import org.eclipse.jface.dialogs.ErrorDialog;
45 import org.eclipse.jface.dialogs.IDialogConstants;
46 import org.eclipse.jface.dialogs.MessageDialog;
47 import org.eclipse.jface.dialogs.MessageDialogWithToggle;
48 import org.eclipse.jface.operation.IRunnableWithProgress;
49 import org.eclipse.jface.preference.IPreferenceStore;
50 import org.eclipse.jface.viewers.CheckStateChangedEvent;
51 import org.eclipse.jface.viewers.CheckboxTableViewer;
52 import org.eclipse.jface.viewers.ICheckStateListener;
53 import org.eclipse.jface.viewers.ILabelProvider;
54 import org.eclipse.jface.viewers.IStructuredSelection;
55 import org.eclipse.jface.window.Window;
56 import org.eclipse.osgi.util.NLS;
57 import org.eclipse.swt.SWT;
58 import org.eclipse.swt.events.SelectionAdapter;
59 import org.eclipse.swt.events.SelectionEvent;
60 import org.eclipse.swt.events.SelectionListener;
61 import org.eclipse.swt.graphics.Font;
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.Display;
68 import org.eclipse.swt.widgets.Event;
69 import org.eclipse.swt.widgets.Label;
70 import org.eclipse.swt.widgets.Listener;
71 import org.eclipse.swt.widgets.Shell;
72 import org.eclipse.swt.widgets.Table;
73 import org.eclipse.swt.widgets.TableItem;
74 import org.eclipse.ui.PlatformUI;
75 import org.eclipse.ui.dialogs.ElementListSelectionDialog;
76 import org.eclipse.ui.dialogs.PropertyPage;
77 import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsMainTab;
78 import org.eclipse.ui.externaltools.internal.launchConfigurations.ExternalToolsUtil;
79 import org.eclipse.ui.externaltools.internal.launchConfigurations.IgnoreWhiteSpaceComparator;
80 import org.eclipse.ui.externaltools.internal.model.BuilderUtils;
81 import org.eclipse.ui.externaltools.internal.model.ExternalToolBuilder;
82 import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
83 import org.eclipse.ui.externaltools.internal.model.IExternalToolConstants;
84 import org.eclipse.ui.externaltools.internal.model.IExternalToolsHelpContextIds;
85 import org.eclipse.ui.externaltools.internal.model.IPreferenceConstants;
86 import org.eclipse.ui.progress.IProgressService;
87
88 /**
89  * Property page to add external tools builders.
90  */

91 public final class BuilderPropertyPage extends PropertyPage implements ICheckStateListener {
92
93     //locally mark a command's enabled state so it can be processed correctly on performOK
94
private static final String JavaDoc COMMAND_ENABLED= "CommandEnabled"; //$NON-NLS-1$
95

96     private Button upButton, downButton, newButton, importButton, editButton, removeButton;
97     
98     private boolean userHasMadeChanges= false;
99     
100     private List JavaDoc configsToBeDeleted= null;
101     private List JavaDoc commandsToBeDeleted= null;
102     
103     private CheckboxTableViewer viewer= null;
104     
105     private ILabelProvider labelProvider= new BuilderLabelProvider();
106     
107     /**
108      * Error configs are objects representing entries pointing to
109      * invalid launch configurations
110      */

111     public class ErrorConfig {
112         private ICommand command;
113         public ErrorConfig(ICommand command) {
114             this.command= command;
115         }
116         public ICommand getCommand() {
117             return command;
118         }
119     }
120     
121     /**
122      * Collection of configurations created while the page is open.
123      * Stored here so they can be deleted if the page is cancelled.
124      */

125     private List JavaDoc newConfigList= new ArrayList JavaDoc();
126     
127     private SelectionListener buttonListener= new SelectionAdapter() {
128         public void widgetSelected(SelectionEvent e) {
129             handleButtonPressed((Button) e.widget);
130         }
131     };
132     
133     /**
134      * Launch configuration listener which is responsible for updating items in
135      * the tree when the user renames configurations in the dialog.
136      *
137      * This is necessary because when we tell the configuration dialog to open
138      * on a launch config and the user renames that config, the old config (the
139      * one in the tree) is made obsolete and a new config is created. This
140      * listener hears when new configurations are created this way and replaces
141      * the old configuration with the new.
142      */

143     private ILaunchConfigurationListener configurationListener= new ILaunchConfigurationListener() {
144         /**
145          * A launch configuration has been added. If this config has been
146          * movedFrom a configuration in the tree, replace the old config with
147          * the new.
148          */

149         public void launchConfigurationAdded(final ILaunchConfiguration configuration) {
150             ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
151             final ILaunchConfiguration oldConfig= manager.getMovedFrom(configuration);
152             if (oldConfig == null) {
153                 return;
154             }
155             //Replace the movedFrom config in the list of newly created configs
156
if (newConfigList.remove(oldConfig)) {
157                 newConfigList.add(configuration);
158             }
159             
160             Display.getDefault().asyncExec(new Runnable JavaDoc() {
161                 public void run() {
162                     TableItem[] items= viewer.getTable().getItems();
163                     for (int i = 0; i < items.length; i++) {
164                         TableItem item = items[i];
165                         Object JavaDoc data= item.getData();
166                         if (data == oldConfig) {
167                             // Found the movedFrom config in the tree. Replace it with the new config
168
item.setData(configuration);
169                             viewer.update(configuration, null);
170                             break;
171                         }
172                     }
173                 }
174             });
175         }
176         public void launchConfigurationChanged(ILaunchConfiguration configuration) {
177         }
178         public void launchConfigurationRemoved(ILaunchConfiguration configuration) {
179         }
180     };
181
182     /**
183      * Creates an initialized property page
184      */

185     public BuilderPropertyPage() {
186         super();
187         noDefaultAndApplyButton();
188     }
189
190     /**
191      * Add the project's build to the table viewer.
192      */

193     private void addBuildersToTable() {
194         IProject project = getInputProject();
195         if (project == null) {
196             return;
197         }
198         //add build spec entries to the table
199
ICommand[] commands= null;
200         try {
201             commands = project.getDescription().getBuildSpec();
202         } catch (CoreException e) {
203             handleException(e);
204             return;
205         }
206     
207         boolean projectNeedsMigration= false;
208         for (int i = 0; i < commands.length; i++) {
209             String JavaDoc[] version= new String JavaDoc[] {""}; //$NON-NLS-1$
210
ILaunchConfiguration config = BuilderUtils.configFromBuildCommandArgs(project, commands[i].getArguments(), version);
211             if (BuilderUtils.VERSION_2_1.equals(version[0])) {
212                 // Storing the .project file of a project with 2.1 configs, will
213
// edit the file in a way that isn't backwards compatible.
214
projectNeedsMigration= true;
215             }
216             Object JavaDoc element= null;
217             if (config != null) {
218                 if (!config.isWorkingCopy() && !config.exists()) {
219                     Shell shell= getShell();
220                     if (shell == null) {
221                         return;
222                     }
223                     IStatus status = new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, 0, NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_Exists, new String JavaDoc[]{config.getLocation().toOSString()}), null);
224                     ErrorDialog.openError(getShell(), ExternalToolsUIMessages.BuilderPropertyPage_errorTitle,
225                                     NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_External_Tool_Builder__0__Not_Added_2, new String JavaDoc[]{config.getName()}),
226                                     status);
227                     userHasMadeChanges= true;
228                 } else {
229                     element= config;
230                 }
231             } else {
232                 String JavaDoc builderID = commands[i].getBuilderName();
233                 if (builderID.equals(ExternalToolBuilder.ID) && commands[i].getArguments().get(BuilderUtils.LAUNCH_CONFIG_HANDLE) != null) {
234                     // An invalid external tool entry.
235
element= new ErrorConfig(commands[i]);
236                 } else {
237                     element= commands[i];
238                 }
239             }
240             if (element != null) {
241                 viewer.add(element);
242                 viewer.setChecked(element, isEnabled(element));
243             }
244         }
245         if (projectNeedsMigration) {
246             IPreferenceStore store= ExternalToolsPlugin.getDefault().getPreferenceStore();
247             boolean prompt= store.getBoolean(IPreferenceConstants.PROMPT_FOR_PROJECT_MIGRATION);
248             boolean proceed= true;
249             if (prompt) {
250                 Shell shell= getShell();
251                 if (shell == null) {
252                     return;
253                 }
254                 MessageDialogWithToggle dialog= MessageDialogWithToggle.openYesNoQuestion(shell, ExternalToolsUIMessages.BuilderPropertyPage_0, ExternalToolsUIMessages.BuilderPropertyPage_1, ExternalToolsUIMessages.BuilderPropertyPage_2, false, null, null);
255                 proceed= dialog.getReturnCode() == IDialogConstants.YES_ID;
256                 store.setValue(IPreferenceConstants.PROMPT_FOR_PROJECT_MIGRATION, !dialog.getToggleState());
257             }
258             if (!proceed) {
259                 // Open the page read-only
260
viewer.getTable().setEnabled(false);
261                 downButton.setEnabled(false);
262                 editButton.setEnabled(false);
263                 importButton.setEnabled(false);
264                 newButton.setEnabled(false);
265                 removeButton.setEnabled(false);
266             }
267         }
268     }
269
270     /**
271      * Creates and returns a button with the given label, id, and enablement.
272      */

273     private Button createButton(Composite parent, String JavaDoc label) {
274         Button button = new Button(parent, SWT.PUSH);
275         GridData data = new GridData();
276         data.widthHint = convertHorizontalDLUsToPixels(IDialogConstants.BUTTON_WIDTH);
277         button.setLayoutData(data);
278         button.setFont(parent.getFont());
279         button.setText(label);
280         button.setEnabled(false);
281         button.addSelectionListener(buttonListener);
282         return button;
283     }
284
285     /* (non-Javadoc)
286      * Method declared on PreferencePage.
287      */

288     protected Control createContents(Composite parent) {
289         
290         PlatformUI.getWorkbench().getHelpSystem().setHelp(parent, IExternalToolsHelpContextIds.EXTERNAL_TOOLS_BUILDER_PROPERTY_PAGE);
291         
292         Font font = parent.getFont();
293
294         Composite topLevel = new Composite(parent, SWT.NONE);
295         GridLayout layout = new GridLayout();
296         layout.marginHeight = 0;
297         layout.marginWidth = 0;
298         topLevel.setLayout(layout);
299         topLevel.setLayoutData(new GridData(GridData.FILL_BOTH));
300
301         Label description = new Label(topLevel, SWT.WRAP);
302         description.setText(ExternalToolsUIMessages.BuilderPropertyPage_description);
303         description.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
304         description.setFont(font);
305
306         Composite tableAndButtons = new Composite(topLevel, SWT.NONE);
307         tableAndButtons.setLayoutData(new GridData(GridData.FILL_BOTH));
308         layout = new GridLayout();
309         layout.marginHeight = 0;
310         layout.marginWidth = 0;
311         layout.numColumns = 2;
312         tableAndButtons.setLayout(layout);
313
314         // table of builders and tools
315
viewer= CheckboxTableViewer.newCheckList(tableAndButtons, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER);
316         viewer.setLabelProvider(labelProvider);
317         viewer.addCheckStateListener(this);
318         Table builderTable= viewer.getTable();
319         builderTable.setLayoutData(new GridData(GridData.FILL_BOTH));
320         builderTable.setFont(font);
321         builderTable.addSelectionListener(new SelectionAdapter() {
322             public void widgetSelected(SelectionEvent e) {
323                 handleTableSelectionChanged();
324             }
325         });
326         
327         builderTable.addListener(SWT.MouseDoubleClick, new Listener() {
328             public void handleEvent(Event event) {
329                 handleEditButtonPressed();
330             }
331         });
332         
333         //button area
334
Composite buttonArea = new Composite(tableAndButtons, SWT.NONE);
335         layout = new GridLayout();
336         layout.marginHeight = 0;
337         layout.marginWidth = 0;
338         buttonArea.setLayout(layout);
339         buttonArea.setFont(font);
340         buttonArea.setLayoutData(new GridData(GridData.FILL_VERTICAL));
341         newButton = createButton(buttonArea, ExternalToolsUIMessages.BuilderPropertyPage_newButton);
342         importButton = createButton(buttonArea, ExternalToolsUIMessages.BuilderPropertyPage__Import____3);
343         editButton = createButton(buttonArea, ExternalToolsUIMessages.BuilderPropertyPage_editButton);
344         removeButton = createButton(buttonArea, ExternalToolsUIMessages.BuilderPropertyPage_removeButton);
345         new Label(buttonArea, SWT.LEFT);
346         upButton = createButton(buttonArea, ExternalToolsUIMessages.BuilderPropertyPage_upButton);
347         downButton = createButton(buttonArea, ExternalToolsUIMessages.BuilderPropertyPage_downButton);
348
349         newButton.setEnabled(true);
350         importButton.setEnabled(true);
351
352         //populate widget contents
353
addBuildersToTable();
354
355         return topLevel;
356     }
357     
358     /**
359      * Turns auto-building on or off in the workspace.
360      */

361     private void setAutobuild(boolean newState) throws CoreException {
362         IWorkspace workspace= ResourcesPlugin.getWorkspace();
363         IWorkspaceDescription wsDescription= workspace.getDescription();
364         boolean oldState= wsDescription.isAutoBuilding();
365         if (oldState != newState) {
366             wsDescription.setAutoBuilding(newState);
367             workspace.setDescription(wsDescription);
368         }
369     }
370
371     /**
372      * Returns the project that is the input for this property page,
373      * or <code>null</code>.
374      */

375     private IProject getInputProject() {
376         IAdaptable element = getElement();
377         if (element instanceof IProject) {
378             return (IProject) element;
379         }
380         Object JavaDoc resource = element.getAdapter(IResource.class);
381         if (resource instanceof IProject) {
382             return (IProject) resource;
383         }
384         return null;
385     }
386
387     /**
388      * One of the buttons has been pressed, act accordingly.
389      */

390     private void handleButtonPressed(Button button) {
391         if (button == newButton) {
392             handleNewButtonPressed();
393         } else if (button == importButton) {
394             handleImportButtonPressed();
395         } else if (button == editButton) {
396             handleEditButtonPressed();
397         } else if (button == removeButton) {
398             handleRemoveButtonPressed();
399         } else if (button == upButton) {
400             moveSelectionUp();
401         } else if (button == downButton) {
402             moveSelectionDown();
403         }
404         if (getControl().isDisposed()) {
405             return;
406         }
407         handleTableSelectionChanged();
408         viewer.getTable().setFocus();
409     }
410
411     /* (non-Javadoc)
412      * @see org.eclipse.jface.viewers.ICheckStateListener#checkStateChanged(org.eclipse.jface.viewers.CheckStateChangedEvent)
413      */

414     public void checkStateChanged(CheckStateChangedEvent event) {
415         Object JavaDoc element= event.getElement();
416         boolean checked = event.getChecked();
417         if (element instanceof ILaunchConfiguration) {
418             enableLaunchConfiguration((ILaunchConfiguration) element, checked);
419         } else if (element instanceof ICommand) {
420             Shell shell= getShell();
421             if (shell == null) {
422                 return;
423             }
424             if (checked) {
425                 enableCommand((ICommand)element, checked);
426             } else if (MessageDialog.openConfirm(shell, ExternalToolsUIMessages.BuilderPropertyPage_6, ExternalToolsUIMessages.BuilderPropertyPage_7)) {
427                 enableCommand((ICommand)element, checked);
428             } else {
429                 viewer.removeCheckStateListener(this);
430                 viewer.setChecked(element, true);
431                 viewer.addCheckStateListener(this);
432             }
433         }
434     }
435
436     private void enableLaunchConfiguration(ILaunchConfiguration configuration, boolean enable) {
437         ILaunchConfigurationWorkingCopy workingCopy= null;
438         try {
439             if (configuration instanceof ILaunchConfigurationWorkingCopy) {
440                 workingCopy = (ILaunchConfigurationWorkingCopy) configuration;
441             } else {
442                 // Replace the config with a working copy
443
TableItem[] items= viewer.getTable().getItems();
444                 for (int i = 0; i < items.length; i++) {
445                     TableItem item = items[i];
446                     if (item.getData() == configuration) {
447                         workingCopy = configuration.getWorkingCopy();
448                         item.setData(workingCopy);
449                     }
450                 }
451             }
452             if (workingCopy != null) {
453                 workingCopy.setAttribute(IExternalToolConstants.ATTR_BUILDER_ENABLED, enable);
454             }
455         } catch (CoreException e) {
456             return;
457         }
458         userHasMadeChanges= true;
459     }
460     
461     private void enableCommand(ICommand command, boolean enable) {
462         Map JavaDoc args= command.getArguments();
463         if (args == null) {
464             args= new HashMap JavaDoc(1);
465         }
466         args.put(COMMAND_ENABLED, Boolean.valueOf(enable));
467         command.setArguments(args);
468         userHasMadeChanges= true;
469     }
470
471     /**
472      * The user has pressed the import button. Prompt them to select a
473      * configuration to import from the workspace.
474      */

475     private void handleImportButtonPressed() {
476         ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
477         List JavaDoc toolTypes= getConfigurationTypes(IExternalToolConstants.ID_EXTERNAL_TOOLS_LAUNCH_CATEGORY);
478         List JavaDoc configurations= new ArrayList JavaDoc();
479         Iterator JavaDoc iter= toolTypes.iterator();
480         while (iter.hasNext()) {
481             try {
482                 ILaunchConfiguration[] configs= manager.getLaunchConfigurations((ILaunchConfigurationType) iter.next());
483                 for (int i = 0; i < configs.length; i++) {
484                     ILaunchConfiguration launchConfiguration = configs[i];
485                     if (!DebugUITools.isPrivate(launchConfiguration)) {
486                         configurations.add(launchConfiguration);
487                     }
488                 }
489             } catch (CoreException e) {
490             }
491         }
492         Shell shell= getShell();
493         if (shell == null) {
494             return;
495         }
496         ElementListSelectionDialog dialog= new ElementListSelectionDialog(shell, new BuilderLabelProvider());
497         dialog.setTitle(ExternalToolsUIMessages.BuilderPropertyPage_4);
498         dialog.setMessage(ExternalToolsUIMessages.BuilderPropertyPage_5);
499         dialog.setElements(configurations.toArray());
500         if (dialog.open() == Window.CANCEL) {
501             return;
502         }
503         Object JavaDoc results[]= dialog.getResult();
504         if (results.length == 0) { //OK pressed with nothing selected
505
return;
506         }
507         ILaunchConfiguration config= (ILaunchConfiguration) results[0];
508         ILaunchConfiguration newConfig= null;
509         boolean wasAutobuilding= ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
510         try {
511             setAutobuild(false);
512             newConfig= BuilderUtils.duplicateConfiguration(getInputProject(), config);
513         } catch (CoreException e) {
514             handleException(e);
515         } finally {
516             try {
517                 setAutobuild(wasAutobuilding);
518             } catch (CoreException e) {
519                 handleException(e);
520             }
521         }
522         if (newConfig != null) {
523             userHasMadeChanges= true;
524             viewer.add(newConfig);
525             viewer.setChecked(newConfig, isEnabled(newConfig));
526             newConfigList.add(newConfig);
527         }
528     }
529     
530     /**
531      * The user has pressed the remove button. Delete the selected builder.
532      */

533     private void handleRemoveButtonPressed() {
534         IStructuredSelection selection = (IStructuredSelection) viewer.getSelection();
535         if (selection != null) {
536             int numSelected= selection.size();
537             userHasMadeChanges= true;
538             Iterator JavaDoc iterator= selection.iterator();
539             while (iterator.hasNext()) {
540                 Object JavaDoc item= iterator.next();
541                 if (item instanceof ILaunchConfiguration) {
542                     if (configsToBeDeleted == null) {
543                         configsToBeDeleted= new ArrayList JavaDoc(numSelected);
544                     }
545                     configsToBeDeleted.add(item);
546                 } else if (item instanceof ICommand) {
547                     if (commandsToBeDeleted == null) {
548                         commandsToBeDeleted= new ArrayList JavaDoc(numSelected);
549                     }
550                     commandsToBeDeleted.add(item);
551                 }
552                 viewer.remove(item);
553             }
554         }
555     }
556     
557     /**
558      * The user has pressed the new button. Create a new configuration and open
559      * the launch configuration edit dialog on the new config.
560      */

561     private void handleNewButtonPressed() {
562         ILaunchConfigurationType type = promptForConfigurationType();
563         if (type == null) {
564             return;
565         }
566         boolean wasAutobuilding= ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
567         try {
568             ILaunchConfigurationWorkingCopy workingCopy = null;
569             String JavaDoc name= DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(ExternalToolsUIMessages.BuilderPropertyPage_New_Builder_7);
570             workingCopy = type.newInstance(BuilderUtils.getBuilderFolder(getInputProject(), true), name);
571             
572             StringBuffer JavaDoc buffer= new StringBuffer JavaDoc(IExternalToolConstants.BUILD_TYPE_FULL);
573             buffer.append(',');
574             buffer.append(IExternalToolConstants.BUILD_TYPE_INCREMENTAL);
575             buffer.append(',');
576             workingCopy.setAttribute(IExternalToolConstants.ATTR_RUN_BUILD_KINDS, buffer.toString());
577             workingCopy.setAttribute(ExternalToolsMainTab.FIRST_EDIT, true);
578             ILaunchConfiguration config = null;
579             setAutobuild(false);
580             config = workingCopy.doSave();
581             //needs to be added here in case the user hits apply in the edit dialog
582
//then we can correctly update the list with the new config.
583
newConfigList.add(config);
584             int code= editConfiguration(config);
585             if (code == Window.CANCEL) {
586                 // If the user cancelled, delete the newly created config
587
newConfigList.remove(config);
588                 config.delete();
589             } else {
590                 userHasMadeChanges= true;
591                 //retrieve the last "new" config
592
//may have been changed by the user pressing apply in the edit dialog
593
config= (ILaunchConfiguration)newConfigList.get(newConfigList.size() - 1);
594                 viewer.add(config);
595                 viewer.setChecked(config, isEnabled(config));
596             }
597         } catch (CoreException e) {
598             handleException(e);
599         } finally {
600             try {
601                 setAutobuild(wasAutobuilding);
602             } catch (CoreException e) {
603                 handleException(e);
604             }
605         }
606     }
607     
608     /**
609      * Prompts the user to edit the given launch configuration. Returns the
610      * return code from opening the launch configuration dialog.
611      */

612     private int editConfiguration(ILaunchConfiguration config) {
613         ILaunchManager manager= DebugPlugin.getDefault().getLaunchManager();
614         manager.addLaunchConfigurationListener(configurationListener);
615         Shell shell= getShell();
616         if (shell == null) {
617             return Window.CANCEL;
618         }
619         int code= DebugUITools.openLaunchConfigurationPropertiesDialog(shell, config, IExternalToolConstants.ID_EXTERNAL_TOOLS_BUILDER_LAUNCH_GROUP);
620         manager.removeLaunchConfigurationListener(configurationListener);
621         return code;
622     }
623     
624     /**
625      * Prompts the user to choose a launch configuration type to create and
626      * returns the type the user selected or <code>null</code> if the user
627      * cancelled.
628      *
629      * @return the configuration type selected by the user or <code>null</code>
630      * if the user cancelled.
631      */

632     private ILaunchConfigurationType promptForConfigurationType() {
633         List JavaDoc externalToolTypes= getConfigurationTypes(IExternalToolConstants.ID_EXTERNAL_TOOLS_BUILDER_LAUNCH_CATEGORY);
634         Shell shell= getShell();
635         if (shell == null) {
636             return null;
637         }
638         ElementListSelectionDialog dialog = new ElementListSelectionDialog(shell, new BuilderLabelProvider());
639         dialog.setElements(externalToolTypes.toArray());
640         dialog.setMultipleSelection(false);
641         dialog.setTitle(ExternalToolsUIMessages.BuilderPropertyPage_Choose_configuration_type_8);
642         dialog.setMessage(ExternalToolsUIMessages.BuilderPropertyPage_Choose_an_external_tool_type_to_create_9);
643         dialog.open();
644         Object JavaDoc result[] = dialog.getResult();
645         if (result == null || result.length == 0) {
646             return null;
647         }
648         return (ILaunchConfigurationType) result[0];
649     }
650     
651     /**
652      * Returns the launch configuration types of the given category
653      */

654     private List JavaDoc getConfigurationTypes(String JavaDoc category) {
655         ILaunchConfigurationType types[] = DebugPlugin.getDefault().getLaunchManager().getLaunchConfigurationTypes();
656         List JavaDoc externalToolTypes = new ArrayList JavaDoc();
657         for (int i = 0; i < types.length; i++) {
658             ILaunchConfigurationType configurationType = types[i];
659             if (category.equals(configurationType.getCategory())) {
660                 externalToolTypes.add(configurationType);
661             }
662         }
663         return externalToolTypes;
664     }
665     
666     /**
667      * The user has pressed the edit button or double-clicked. Open the launch configuration edit
668      * dialog on the selection after migrating the tool if necessary.
669      */

670     private void handleEditButtonPressed() {
671         TableItem[] items= viewer.getTable().getSelection();
672         if (items.length == 0) {
673             return;
674         }
675         TableItem selection= items[0];
676         if (selection != null) {
677             Object JavaDoc data = selection.getData();
678             if (data instanceof ILaunchConfiguration) {
679                 ILaunchConfiguration config= (ILaunchConfiguration) data;
680                 if (BuilderUtils.isUnmigratedConfig(config)) {
681                     if (!shouldProceedWithMigration()) {
682                         return;
683                     }
684                     try {
685                         config= BuilderUtils.migrateBuilderConfiguration(getInputProject(), (ILaunchConfigurationWorkingCopy) config);
686                     } catch (CoreException e) {
687                         handleException(e);
688                         return;
689                     }
690                     // Replace the working copy in the table with the migrated configuration
691
selection.setData(config);
692                 }
693                 userHasMadeChanges= true;
694                 boolean wasAutobuilding= ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
695                 try {
696                     setAutobuild(false);
697                     editConfiguration(config);
698                 } catch (CoreException e) {
699                     handleException(e);
700                 } finally {
701                     try {
702                         setAutobuild(wasAutobuilding);
703                     } catch (CoreException e) {
704                         handleException(e);
705                     }
706                 }
707             } else if (data instanceof ICommand) {
708                 ICommand command= (ICommand) data;
709                 if (command.isConfigurable()) {
710                     if (editCommand(command)) {
711                         userHasMadeChanges= true;
712                     }
713                 }
714             }
715         }
716     }
717     
718     private boolean editCommand(ICommand data) {
719         EditCommandDialog dialog= new EditCommandDialog(getShell(), data);
720         return Window.OK == dialog.open();
721     }
722
723     /**
724      * Prompts the user to proceed with the migration of a project builder from
725      * the old format to the new, launch configuration-based, format and returns
726      * whether or not the user wishes to proceed with the migration.
727      *
728      * @return boolean whether or not the user wishes to proceed with migration
729      */

730     private boolean shouldProceedWithMigration() {
731         if (!ExternalToolsPlugin.getDefault().getPreferenceStore().getBoolean(IPreferenceConstants.PROMPT_FOR_TOOL_MIGRATION)) {
732             // User has asked not to be prompted
733
return true;
734         }
735         Shell shell= getShell();
736         if (shell == null) {
737             return false;
738         }
739         // Warn the user that editing an old config will cause storage migration.
740
MessageDialogWithToggle dialog= MessageDialogWithToggle.openYesNoQuestion(getShell(),
741             ExternalToolsUIMessages.BuilderPropertyPage_Migrate_project_builder_10,
742             ExternalToolsUIMessages.BuilderPropertyPage_Not_Support,
743             ExternalToolsUIMessages.BuilderPropertyPage_Prompt,
744             false,
745             ExternalToolsPlugin.getDefault().getPreferenceStore(),
746             IPreferenceConstants.PROMPT_FOR_TOOL_MIGRATION);
747         return dialog.getReturnCode() == IDialogConstants.YES_ID;
748     }
749
750     /**
751      * Handles unexpected internal exceptions
752      */

753     private void handleException(Exception JavaDoc e) {
754         final IStatus[] status= new IStatus[1];
755         if (e instanceof CoreException) {
756             status[0] = ((CoreException) e).getStatus();
757         } else {
758             status[0] = new Status(IStatus.ERROR, IExternalToolConstants.PLUGIN_ID, 0, ExternalToolsUIMessages.BuilderPropertyPage_statusMessage, e);
759         }
760         Display.getDefault().asyncExec(new Runnable JavaDoc() {
761             public void run() {
762                 Shell shell= getShell();
763                 if (shell != null) {
764                     ErrorDialog.openError(shell, ExternalToolsUIMessages.BuilderPropertyPage_errorTitle,
765                             ExternalToolsUIMessages.BuilderPropertyPage_errorMessage,
766                             status[0]);
767                 }
768             }
769         });
770     }
771
772     /**
773      * The user has selected a different builder in table.
774      * Update button enablement.
775      */

776     private void handleTableSelectionChanged() {
777         newButton.setEnabled(true);
778         Table builderTable= viewer.getTable();
779         TableItem[] items = builderTable.getSelection();
780         boolean validSelection= items != null && items.length > 0;
781         boolean enableEdit= validSelection;
782         boolean enableRemove= validSelection;
783         boolean enableUp= validSelection;
784         boolean enableDown= validSelection;
785         if (validSelection) {
786             if (items.length > 1) {
787                 enableEdit= false;
788             }
789             int indices[]= builderTable.getSelectionIndices();
790             int max = builderTable.getItemCount();
791             enableUp= indices[0] != 0;
792             enableDown= indices[indices.length - 1] < max - 1;
793             for (int i = 0; i < items.length; i++) {
794                 TableItem item = items[i];
795                 Object JavaDoc data= item.getData();
796                 if (data instanceof ILaunchConfiguration) {
797                     ILaunchConfiguration config= (ILaunchConfiguration)data;
798                     String JavaDoc builderName= null;
799                     try {
800                         builderName = config.getAttribute(IExternalToolConstants.ATTR_DISABLED_BUILDER, (String JavaDoc)null);
801                     } catch (CoreException e) {
802                     }
803                     if (builderName != null) {
804                         //do not allow "wrapped" builders to be removed or edited if they are valid
805
IExtension ext= Platform.getExtensionRegistry().getExtension(ResourcesPlugin.PI_RESOURCES, ResourcesPlugin.PT_BUILDERS, builderName);
806                         enableEdit= false;
807                         enableRemove= ext == null;
808                     }
809                 } else {
810                     if (data instanceof ErrorConfig) {
811                         enableEdit= false;
812                         continue;
813                     }
814                     ICommand command= (ICommand) data;
815                     enableEdit= command.isConfigurable();
816                     IExtension ext= Platform.getExtensionRegistry().getExtension(ResourcesPlugin.PI_RESOURCES, ResourcesPlugin.PT_BUILDERS, command.getBuilderName());
817                     enableRemove= ext == null;
818                     break;
819                 }
820             }
821         }
822         editButton.setEnabled(enableEdit);
823         removeButton.setEnabled(enableRemove);
824         upButton.setEnabled(enableUp);
825         downButton.setEnabled(enableDown);
826     }
827     
828     /**
829      * Returns whether the given element (command or launch config)
830      * is enabled.
831      *
832      * @param element the element
833      * @return whether the given element is enabled
834      */

835     private boolean isEnabled(Object JavaDoc element) {
836         if (element instanceof ICommand) {
837             Boolean JavaDoc enabled= (Boolean JavaDoc)((ICommand) element).getArguments().get(COMMAND_ENABLED);
838             if (enabled != null) {
839                 return enabled.booleanValue();
840             }
841         } else if (element instanceof ILaunchConfiguration) {
842             try {
843                 return ExternalToolsUtil.isBuilderEnabled((ILaunchConfiguration) element);
844             } catch (CoreException e) {
845             }
846         } else if (element instanceof ErrorConfig) {
847             return false;
848         }
849         return true;
850     }
851
852     /**
853      * Moves an entry in the builder table to the given index.
854      */

855     private void move(TableItem item, int index) {
856         userHasMadeChanges= true;
857         Object JavaDoc data = item.getData();
858         item.dispose();
859         viewer.insert(data, index);
860         viewer.setChecked(data, isEnabled(data));
861     }
862
863     /**
864      * Move the current selection in the build list down.
865      */

866     private void moveSelectionDown() {
867         Table builderTable= viewer.getTable();
868         int indices[]= builderTable.getSelectionIndices();
869         if (indices.length < 1) {
870             return;
871         }
872         int newSelection[]= new int[indices.length];
873         int max= builderTable.getItemCount() - 1;
874         for (int i = indices.length - 1; i >= 0; i--) {
875             int index= indices[i];
876             if (index < max) {
877                 move (builderTable.getItem(index), index + 1);
878                 newSelection[i]= index + 1;
879             }
880         }
881         builderTable.setSelection(newSelection);
882     }
883
884     /**
885      * Move the current selection in the build list up.
886      */

887     private void moveSelectionUp() {
888         Table builderTable= viewer.getTable();
889         int indices[]= builderTable.getSelectionIndices();
890         int newSelection[]= new int[indices.length];
891         for (int i = 0; i < indices.length; i++) {
892             int index= indices[i];
893             if (index > 0) {
894                 move (builderTable.getItem(index), index - 1);
895                 newSelection[i]= index - 1;
896             }
897         }
898         builderTable.setSelection(newSelection);
899     }
900
901     /* (non-Javadoc)
902      * @see org.eclipse.jface.preference.IPreferencePage#performOk()
903      */

904     public boolean performOk() {
905         if (!userHasMadeChanges) {
906             return super.performOk();
907         }
908         userHasMadeChanges= false;
909         Table builderTable= viewer.getTable();
910         int numCommands = builderTable.getItemCount();
911         final Object JavaDoc[] itemData= new Object JavaDoc[numCommands];
912         for (int i = 0; i < numCommands; i++) {
913             itemData[i]= builderTable.getItem(i).getData();
914         }
915         IRunnableWithProgress runnable= new IRunnableWithProgress() {
916             public void run(IProgressMonitor monitor)
917                     throws InvocationTargetException JavaDoc, InterruptedException JavaDoc {
918                 doPerformOk(monitor, itemData);
919                 if (monitor.isCanceled()) {
920                     throw new InterruptedException JavaDoc();
921                 }
922             }
923         };
924         
925         IProgressService service= PlatformUI.getWorkbench().getProgressService();
926         try {
927             service.busyCursorWhile(runnable);
928         } catch (InvocationTargetException JavaDoc e) {
929             return false;
930         } catch (InterruptedException JavaDoc e) {
931             return false;
932         }
933         return super.performOk();
934     }
935     
936     private void doPerformOk(IProgressMonitor monitor, Object JavaDoc[] itemData) {
937         if (monitor.isCanceled()) {
938             return;
939         }
940         
941         IProject project = getInputProject();
942         //get all the build commands
943
int numCommands = itemData.length;
944         monitor.beginTask(ExternalToolsUIMessages.BuilderPropertyPage_3, numCommands + 1);
945         List JavaDoc possibleCommands= new ArrayList JavaDoc(numCommands);
946         for (int i = 0; i < numCommands; i++) {
947             Object JavaDoc data = itemData[i];
948             if (data instanceof ICommand) {
949                 if (commandsToBeDeleted != null && commandsToBeDeleted.contains(data)) {
950                     //command specified to be removed
951
data= null;
952                 }
953                 ICommand command= (ICommand)data;
954                 Map JavaDoc args= command.getArguments();
955                 Boolean JavaDoc enabled= (Boolean JavaDoc)args.get(COMMAND_ENABLED);
956                 if (enabled != null && enabled.equals(Boolean.FALSE)) {
957                     ILaunchConfiguration config= disableCommand(command);
958                     if (config != null) {
959                         data= BuilderUtils.commandFromLaunchConfig(project,config);
960                     }
961                 } else {
962                     args.remove(COMMAND_ENABLED);
963                     command.setArguments(args);
964                 }
965             } else if (data instanceof ILaunchConfiguration) {
966                 ILaunchConfiguration config= (ILaunchConfiguration) data;
967                 String JavaDoc disabledBuilderName;
968                 try {
969                     disabledBuilderName = config.getAttribute(IExternalToolConstants.ATTR_DISABLED_BUILDER, (String JavaDoc)null);
970                     if (disabledBuilderName != null && ExternalToolsUtil.isBuilderEnabled(config)) {
971                         possibleCommands.add(translateBackToCommand(config, project));
972                         continue;
973                     }
974                 } catch (CoreException e1) {
975                 }
976                 
977                 if (!BuilderUtils.isUnmigratedConfig(config) && (config instanceof ILaunchConfigurationWorkingCopy)) {
978                     ILaunchConfigurationWorkingCopy workingCopy= ((ILaunchConfigurationWorkingCopy) config);
979                     // Save any changes to the config (such as enable/disable)
980
if (workingCopy.isDirty()) {
981                         try {
982                             workingCopy.doSave();
983                         } catch (CoreException e) {
984                             Shell shell= getShell();
985                             if (shell != null) {
986                                 MessageDialog.openError(shell, ExternalToolsUIMessages.BuilderPropertyPage_39, NLS.bind(ExternalToolsUIMessages.BuilderPropertyPage_40, new String JavaDoc[] {workingCopy.getName()}));
987                             }
988                         }
989                     }
990                 }
991                 data= BuilderUtils.commandFromLaunchConfig(project, config);
992             } else if (data instanceof ErrorConfig) {
993                 data= ((ErrorConfig) data).getCommand();
994             }
995             if (data != null) {
996                 possibleCommands.add(data);
997             }
998             monitor.worked(1);
999         }
1000        ICommand[] commands= new ICommand[possibleCommands.size()];
1001        possibleCommands.toArray(commands);
1002        if (checkCommandsForChange(commands)) {
1003            //set the build spec
1004
try {
1005                IProjectDescription desc = project.getDescription();
1006                desc.setBuildSpec(commands);
1007                project.setDescription(desc, IResource.FORCE, monitor);
1008            } catch (CoreException e) {
1009                handleException(e);
1010                performCancel();
1011            }
1012        }
1013        
1014        if (configsToBeDeleted != null) {
1015            deleteConfigurations();
1016        }
1017        monitor.done();
1018    }
1019    
1020    private void checkBuilderFolder() {
1021        try {
1022            IFolder builderFolder= BuilderUtils.getBuilderFolder(getInputProject(), false);
1023            if (builderFolder != null && builderFolder.exists() && builderFolder.members().length == 0) {
1024                // All files in the builder folder have been deleted. Clean up
1025
builderFolder.delete(true, false, null);
1026            }
1027        } catch (CoreException e) {
1028            handleException(e);
1029        }
1030    }
1031
1032    /**
1033     * A non-external tool builder builder was disabled.
1034     * It has been re-enabled. Translate the disabled external tool builder launch configuration
1035     * wrapper back into the full fledged builder command.
1036     */

1037    private ICommand translateBackToCommand(ILaunchConfiguration config, IProject project) {
1038        try {
1039            ICommand newCommand = project.getDescription().newCommand();
1040            String JavaDoc builderName= config.getAttribute(IExternalToolConstants.ATTR_DISABLED_BUILDER, (String JavaDoc)null);
1041            Map JavaDoc args= config.getAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, new HashMap JavaDoc(0));
1042            
1043            newCommand.setBuilderName(builderName);
1044            newCommand.setArguments(args);
1045            if (configsToBeDeleted == null) {
1046                configsToBeDeleted= new ArrayList JavaDoc();
1047            }
1048            configsToBeDeleted.add(config);
1049            return newCommand;
1050        } catch (CoreException exception) {
1051            Shell shell= getShell();
1052            if (shell != null) {
1053                MessageDialog.openError(shell, ExternalToolsUIMessages.BuilderPropertyPage_13, ExternalToolsUIMessages.BuilderPropertyPage_error);
1054            }
1055            return null;
1056        }
1057    }
1058    
1059    /**
1060     * Disables a builder by wrappering the builder command as a disabled external tool builder.
1061     * The details of the command is persisted in the launch configuration.
1062     */

1063    private ILaunchConfiguration disableCommand(ICommand command) {
1064        Map JavaDoc arguments= command.getArguments();
1065        if (arguments != null) {
1066            arguments.remove(COMMAND_ENABLED);
1067        }
1068        List JavaDoc externalToolTypes= getConfigurationTypes(IExternalToolConstants.ID_EXTERNAL_TOOLS_BUILDER_LAUNCH_CATEGORY);
1069        if (externalToolTypes.size() == 0) {
1070            return null;
1071        }
1072        ILaunchConfigurationType type= (ILaunchConfigurationType)externalToolTypes.get(0);
1073        if (type == null) {
1074            return null;
1075        }
1076        boolean wasAutobuilding= ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
1077        try {
1078            ILaunchConfigurationWorkingCopy workingCopy = null;
1079            String JavaDoc builderName = command.getBuilderName();
1080            String JavaDoc name= DebugPlugin.getDefault().getLaunchManager().generateUniqueLaunchConfigurationNameFrom(builderName);
1081            workingCopy = type.newInstance(BuilderUtils.getBuilderFolder(getInputProject(), true), name);
1082                    
1083            workingCopy.setAttribute(IExternalToolConstants.ATTR_DISABLED_BUILDER, builderName);
1084            if (arguments != null) {
1085                workingCopy.setAttribute(IExternalToolConstants.ATTR_TOOL_ARGUMENTS, arguments);
1086            }
1087            workingCopy.setAttribute(IExternalToolConstants.ATTR_BUILDER_ENABLED, false);
1088            ILaunchConfiguration config = null;
1089            setAutobuild(false);
1090            config = workingCopy.doSave();
1091            return config;
1092        } catch (CoreException e) {
1093            handleException(e);
1094        } finally {
1095            try {
1096                setAutobuild(wasAutobuilding);
1097            } catch (CoreException e) {
1098                handleException(e);
1099            }
1100        }
1101        return null;
1102    }
1103
1104    private void deleteConfigurations() {
1105        boolean wasAutobuilding= ResourcesPlugin.getWorkspace().getDescription().isAutoBuilding();
1106        try {
1107            setAutobuild(false);
1108        
1109            Iterator JavaDoc itr= configsToBeDeleted.iterator();
1110            while (itr.hasNext()) {
1111                ILaunchConfiguration element = (ILaunchConfiguration) itr.next();
1112                element.delete();
1113            }
1114            
1115            checkBuilderFolder();
1116        } catch (CoreException e) {
1117            handleException(e);
1118        } finally {
1119            try {
1120                setAutobuild(wasAutobuilding);
1121            } catch (CoreException e) {
1122                handleException(e);
1123            }
1124        }
1125    }
1126    
1127    /**
1128     * Returns whether any of the commands have changed.
1129     */

1130    private boolean checkCommandsForChange(ICommand[] newCommands) {
1131        try {
1132            ICommand[] oldCommands = getInputProject().getDescription().getBuildSpec();
1133            if (oldCommands.length != newCommands.length) {
1134                return true;
1135            }
1136            IgnoreWhiteSpaceComparator comparator= new IgnoreWhiteSpaceComparator();
1137            for (int i = 0; i < oldCommands.length; i++) {
1138                ICommand oldCommand = oldCommands[i];
1139                ICommand newCommand= newCommands[i];
1140                String JavaDoc oldName= oldCommand.getBuilderName();
1141                String JavaDoc newName= newCommand.getBuilderName();
1142                if (oldName == null && newName != null) {
1143                    return true;
1144                }
1145                
1146                if(oldName != null && !oldName.equals(newName)) {
1147                    return true;
1148                }
1149                Map JavaDoc oldArgs= oldCommand.getArguments();
1150                Map JavaDoc newArgs= newCommand.getArguments();
1151                if (oldArgs == null && newArgs != null) {
1152                    return true;
1153                }
1154                if (oldArgs == null && newArgs == null) {
1155                    continue;
1156                }
1157                if(oldArgs.size() != newArgs.size()) {
1158                    return true;
1159                }
1160                Iterator JavaDoc keySet= oldArgs.keySet().iterator();
1161                while (keySet.hasNext()) {
1162                    Object JavaDoc key = keySet.next();
1163                    Object JavaDoc oldArg= oldArgs.get(key);
1164                    Object JavaDoc newArg= newArgs.get(key);
1165                    if (oldArg instanceof String JavaDoc && newArg instanceof String JavaDoc) {
1166                        if (comparator.compare(oldArg, newArg) != 0) {
1167                            return true;
1168                        }
1169                    } else if (!oldArg.equals(newArg)){
1170                        return true;
1171                    }
1172                }
1173                
1174                if (oldCommand.isBuilding(IncrementalProjectBuilder.AUTO_BUILD) != newCommand.isBuilding(IncrementalProjectBuilder.AUTO_BUILD)
1175                        || oldCommand.isBuilding(IncrementalProjectBuilder.CLEAN_BUILD) != newCommand.isBuilding(IncrementalProjectBuilder.CLEAN_BUILD)
1176                        || oldCommand.isBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD) != newCommand.isBuilding(IncrementalProjectBuilder.INCREMENTAL_BUILD)
1177                        || oldCommand.isBuilding(IncrementalProjectBuilder.FULL_BUILD) != newCommand.isBuilding(IncrementalProjectBuilder.FULL_BUILD)) {
1178                    return true;
1179                }
1180            }
1181        } catch (CoreException ce) {
1182            return true;
1183        }
1184        return false;
1185    }
1186
1187    /* (non-Javadoc)
1188     * @see org.eclipse.jface.preference.IPreferencePage#performCancel()
1189     */

1190    public boolean performCancel() {
1191        Iterator JavaDoc iter= newConfigList.iterator();
1192        while (iter.hasNext()) {
1193            try {
1194                ((ILaunchConfiguration) iter.next()).delete();
1195            } catch (CoreException e) {
1196                handleException(e);
1197            }
1198        }
1199        
1200        checkBuilderFolder();
1201        
1202        //remove the local marking of the enabled state of the commands
1203
Table builderTable= viewer.getTable();
1204        int numCommands = builderTable.getItemCount();
1205        for (int i = 0; i < numCommands; i++) {
1206            Object JavaDoc data = builderTable.getItem(i).getData();
1207            if (data instanceof ICommand) {
1208                ICommand command= (ICommand)data;
1209                Map JavaDoc args= command.getArguments();
1210                args.remove(COMMAND_ENABLED);
1211                command.setArguments(args);
1212            }
1213        }
1214        return super.performCancel();
1215    }
1216    
1217    public Shell getShell() {
1218        if (getControl().isDisposed()) {
1219            return null;
1220        }
1221        return super.getShell();
1222    }
1223}
1224
Popular Tags