diff options
| author | Remy Suen | 2010-11-09 13:48:39 +0000 |
|---|---|---|
| committer | Remy Suen | 2011-10-06 15:10:19 +0000 |
| commit | 93eac155097c7a396ece7b233e58491f904eb42e (patch) | |
| tree | d2f7c6f58abe79592e9b533a179b6bda4b0bf56f | |
| parent | 4b74a1c2437f017ebbe547422a3c5586de6cbe3b (diff) | |
| download | eclipse.platform.ui-93eac155097c7a396ece7b233e58491f904eb42e.tar.gz eclipse.platform.ui-93eac155097c7a396ece7b233e58491f904eb42e.tar.xz eclipse.platform.ui-93eac155097c7a396ece7b233e58491f904eb42e.zip | |
Bug 5023 [EditorMgmt] associations: Editor selection dialog needs to be multiselect
| -rw-r--r-- | bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java | 68 |
1 files changed, 36 insertions, 32 deletions
diff --git a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java index 0e7eb89fd4d..c3966a8dcf4 100644 --- a/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java +++ b/bundles/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2007 IBM Corporation and others. + * Copyright (c) 2000, 2010 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at @@ -186,7 +186,7 @@ public class FileEditorsPreferencePage extends PreferencePage implements data.horizontalSpan = 2; label.setLayoutData(data); - resourceTypeTable = new Table(pageComponent, SWT.SINGLE | SWT.BORDER + resourceTypeTable = new Table(pageComponent, SWT.MULTI | SWT.BORDER | SWT.FULL_SELECTION); resourceTypeTable.addListener(SWT.Selection, this); resourceTypeTable.addListener(SWT.DefaultSelection, this); @@ -234,7 +234,7 @@ public class FileEditorsPreferencePage extends PreferencePage implements data.horizontalSpan = 2; editorLabel.setLayoutData(data); - editorTable = new Table(pageComponent, SWT.SINGLE | SWT.BORDER); + editorTable = new Table(pageComponent, SWT.MULTI | SWT.BORDER); editorTable.addListener(SWT.Selection, this); editorTable.addListener(SWT.DefaultSelection, this); data = new GridData(GridData.FILL_BOTH); @@ -412,8 +412,8 @@ public class FileEditorsPreferencePage extends PreferencePage implements protected FileEditorMapping getSelectedResourceType() { TableItem[] items = resourceTypeTable.getSelection(); - if (items.length > 0) { - return (FileEditorMapping) items[0].getData(); //Table is single select + if (items.length == 1) { + return (FileEditorMapping) items[0].getData(); } return null; } @@ -566,21 +566,19 @@ public class FileEditorsPreferencePage extends PreferencePage implements TableItem[] items = editorTable.getSelection(); boolean defaultEditor = editorTable.getSelectionIndex() == 0; if (items.length > 0) { - getSelectedResourceType().removeEditor( - (EditorDescriptor) items[0].getData(DATA_EDITOR)); - items[0].dispose(); //Table is single selection + for (int i = 0; i < items.length; i++) { + getSelectedResourceType().removeEditor( + (EditorDescriptor) items[i].getData(DATA_EDITOR)); + items[i].dispose(); + } } if (defaultEditor && editorTable.getItemCount() > 0) { TableItem item = editorTable.getItem(0); - // explicitly set the new editor first editor to default + // explicitly set the first editor as the default getSelectedResourceType().setDefaultEditor( (EditorDescriptor) item.getData(DATA_EDITOR)); - if (item != null) { - item - .setText(((EditorDescriptor) (item.getData(DATA_EDITOR))) - .getLabel() - + " " + WorkbenchMessages.FileEditorPreference_defaultLabel); //$NON-NLS-1$ - } + item.setText(((EditorDescriptor) (item.getData(DATA_EDITOR))).getLabel() + + " " + WorkbenchMessages.FileEditorPreference_defaultLabel); //$NON-NLS-1$ if (!isEditorRemovable(item)) { setLockedItemText(item, item.getText()); } @@ -593,8 +591,8 @@ public class FileEditorsPreferencePage extends PreferencePage implements */ public void removeSelectedResourceType() { TableItem[] items = resourceTypeTable.getSelection(); - if (items.length > 0) { - items[0].dispose(); //Table is single selection + for (int i = 0; i < items.length; i++) { + items[i].dispose(); } //Clear out the editors too editorTable.removeAll(); @@ -641,29 +639,35 @@ public class FileEditorsPreferencePage extends PreferencePage implements */ public void updateEnabledState() { //Update enabled state - boolean resourceTypeSelected = resourceTypeTable.getSelectionIndex() != -1; - boolean editorSelected = editorTable.getSelectionIndex() != -1; - - removeResourceTypeButton.setEnabled(resourceTypeSelected); - editorLabel.setEnabled(resourceTypeSelected); - addEditorButton.setEnabled(resourceTypeSelected); - removeEditorButton.setEnabled(editorSelected && isEditorRemovable()); - defaultEditorButton.setEnabled(editorSelected); + int selectedResources = resourceTypeTable.getSelectionCount(); + int selectedEditors = editorTable.getSelectionCount(); + + removeResourceTypeButton.setEnabled(selectedResources != 0); + editorLabel.setEnabled(selectedResources == 1); + addEditorButton.setEnabled(selectedResources == 1); + removeEditorButton.setEnabled(areEditorsRemovable()); + defaultEditorButton.setEnabled(selectedEditors == 1); } /** - * Return whether the selected editor is removable. An editor is removable - * if it is not submitted via a content-type binding. + * Return whether the selected editors are removable. An editor is removable + * if it was not submitted via a content-type binding. * - * @return whether the selected editor is removable + * @return whether all the selected editors are removable or not * @since 3.1 */ - private boolean isEditorRemovable() { + private boolean areEditorsRemovable() { TableItem[] items = editorTable.getSelection(); - if (items.length > 0) { - return isEditorRemovable(items[0]); + if (items.length == 0) { + return false; + } + + for (int i = 0; i < items.length; i++) { + if (!isEditorRemovable(items[i])) { + return false; + } } - return false; + return true; } /** |
