Index: Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java,v retrieving revision 1.25 diff -u -r1.25 WorkbenchMessages.java --- Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java 9 May 2005 18:33:40 -0000 1.25 +++ Eclipse UI/org/eclipse/ui/internal/WorkbenchMessages.java 18 May 2005 19:32:07 -0000 @@ -387,6 +387,7 @@ public static String FileEditorPreference_existsMessage; public static String FileEditorPreference_defaultLabel; public static String FileEditorPreference_contentTypesRelatedLink; + public static String FileEditorPreference_isLocked; public static String FileExtension_extensionEmptyMessage; public static String FileExtension_fileNameInvalidMessage; Index: Eclipse UI/org/eclipse/ui/internal/messages.properties =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/messages.properties,v retrieving revision 1.262 diff -u -r1.262 messages.properties --- Eclipse UI/org/eclipse/ui/internal/messages.properties 18 May 2005 15:30:41 -0000 1.262 +++ Eclipse UI/org/eclipse/ui/internal/messages.properties 18 May 2005 19:32:07 -0000 @@ -374,6 +374,7 @@ FileEditorPreference_existsMessage = An entry already exists for that file type FileEditorPreference_defaultLabel = (default) FileEditorPreference_contentTypesRelatedLink = See ''{0}'' for content-type based file associations. +FileEditorPreference_isLocked = (locked) FileExtension_extensionEmptyMessage = The file extension cannot be empty FileExtension_fileNameInvalidMessage = The file name cannot include the wild card character (*) in the current location Index: Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java,v retrieving revision 1.11 diff -u -r1.11 FileEditorsPreferencePage.java --- Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java 23 Mar 2005 20:41:22 -0000 1.11 +++ Eclipse UI/org/eclipse/ui/internal/dialogs/FileEditorsPreferencePage.java 18 May 2005 19:32:07 -0000 @@ -16,6 +16,8 @@ import java.util.List; import java.util.Map; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.preference.PreferencePage; @@ -61,7 +63,12 @@ */ public class FileEditorsPreferencePage extends PreferencePage implements IWorkbenchPreferencePage, Listener { - protected Table resourceTypeTable; + + private static final String DATA_EDITOR = "editor"; //$NON-NLS-1$ + + private static final String DATA_FROM_CONTENT_TYPE = "type"; //$NON-NLS-1$ + + protected Table resourceTypeTable; protected Button addResourceTypeButton; @@ -320,7 +327,7 @@ for (int i = 0; i < array.length; i++) { IEditorDescriptor editor = array[i]; TableItem item = new TableItem(editorTable, SWT.NULL); - item.setData(editor); + item.setData(DATA_EDITOR, editor); // Check if it is the default editor String defaultString = null; FileEditorMapping ext = getSelectedResourceType(); @@ -337,12 +344,48 @@ } item.setImage(getImage(editor)); } + + // now add any content type editors + EditorRegistry registry = (EditorRegistry) WorkbenchPlugin + .getDefault().getEditorRegistry(); + IContentType[] contentTypes = Platform.getContentTypeManager() + .findContentTypesFor(resourceType.getLabel()); + for (int i = 0; i < contentTypes.length; i++) { + array = registry.getEditorsForContentType(contentTypes[i]); + for (int j = 0; j < array.length; j++) { + IEditorDescriptor editor = array[i]; + // don't add duplicates + TableItem[] items = editorTable.getItems(); + TableItem foundItem = null; + for (int k = 0; k < items.length; k++) { + if (items[k].getData(DATA_EDITOR).equals(editor)) { + foundItem = items[k]; + break; + } + } + if (foundItem == null) { + TableItem item = new TableItem(editorTable, SWT.NULL); + item.setData(DATA_EDITOR, editor); + item.setData(DATA_FROM_CONTENT_TYPE, Boolean.TRUE); + item + .setText(editor.getLabel() + + " " + WorkbenchMessages.FileEditorPreference_isLocked); //$NON-NLS-1$ + item.setImage(getImage(editor)); + } else { // update the item to reflect its origin + foundItem.setData(DATA_FROM_CONTENT_TYPE, Boolean.TRUE); + foundItem + .setText(foundItem.getText() + + " " + WorkbenchMessages.FileEditorPreference_isLocked); //$NON-NLS-1$ + } + } + } + } } /** - * Place the existing resource types in the table - */ + * Place the existing resource types in the table + */ protected void fillResourceTypeTable() { // Populate the table with the items IFileEditorMapping[] array = WorkbenchPlugin.getDefault() @@ -380,7 +423,7 @@ if (editorTable.getItemCount() > 0) { ArrayList editorList = new ArrayList(); for (int i = 0; i < editorTable.getItemCount(); i++) - editorList.add(editorTable.getItem(i).getData()); + editorList.add(editorTable.getItem(i).getData(DATA_EDITOR)); return (IEditorDescriptor[]) editorList .toArray(new IEditorDescriptor[editorList.size()]); @@ -473,7 +516,7 @@ int i = editorTable.getItemCount(); boolean isEmpty = i < 1; TableItem item = new TableItem(editorTable, SWT.NULL, i); - item.setData(editor); + item.setData(DATA_EDITOR, editor); if (isEmpty) item .setText(editor.getLabel() @@ -510,16 +553,20 @@ boolean defaultEditor = editorTable.getSelectionIndex() == 0; if (items.length > 0) { getSelectedResourceType().removeEditor( - (EditorDescriptor) items[0].getData()); + (EditorDescriptor) items[0].getData(DATA_EDITOR)); items[0].dispose(); //Table is single selection } if (defaultEditor && editorTable.getItemCount() > 0) { TableItem item = editorTable.getItem(0); if (item != null) item - .setText(((EditorDescriptor) (item.getData())) + .setText(((EditorDescriptor) (item.getData(DATA_EDITOR))) .getLabel() + " " + WorkbenchMessages.FileEditorPreference_defaultLabel); //$NON-NLS-1$ + if (!isEditorRemovable(item)) + item + .setText(item.getText() + + " " + WorkbenchMessages.FileEditorPreference_isLocked); //$NON-NLS-1$ } } @@ -545,19 +592,31 @@ // First change the label of the old default TableItem oldDefaultItem = editorTable.getItem(0); oldDefaultItem - .setText(((EditorDescriptor) oldDefaultItem.getData()) + .setText(((EditorDescriptor) oldDefaultItem.getData(DATA_EDITOR)) .getLabel()); + // update the label to reflect the locked state + if (!isEditorRemovable(oldDefaultItem)) + oldDefaultItem + .setText(oldDefaultItem.getText() + + " " + WorkbenchMessages.FileEditorPreference_isLocked); //$NON-NLS-1$ // Now set the new default - EditorDescriptor editor = (EditorDescriptor) items[0].getData(); + EditorDescriptor editor = (EditorDescriptor) items[0].getData(DATA_EDITOR); getSelectedResourceType().setDefaultEditor(editor); + Boolean fromContentType = (Boolean) items[0].getData(DATA_FROM_CONTENT_TYPE); items[0].dispose(); //Table is single selection TableItem item = new TableItem(editorTable, SWT.NULL, 0); - item.setData(editor); + item.setData(DATA_EDITOR, editor); + if (fromContentType != null) + item.setData(DATA_FROM_CONTENT_TYPE, fromContentType); item .setText(editor.getLabel() + " " + WorkbenchMessages.FileEditorPreference_defaultLabel); //$NON-NLS-1$ item.setImage(getImage(editor)); - editorTable.setSelection(new TableItem[] { item }); + if (!isEditorRemovable(item)) + item + .setText(item.getText() + + " " + WorkbenchMessages.FileEditorPreference_isLocked); //$NON-NLS-1$ + editorTable.setSelection(new TableItem[] { item }); } } @@ -572,15 +631,44 @@ removeResourceTypeButton.setEnabled(resourceTypeSelected); editorLabel.setEnabled(resourceTypeSelected); addEditorButton.setEnabled(resourceTypeSelected); - removeEditorButton.setEnabled(editorSelected); + removeEditorButton.setEnabled(editorSelected && isEditorRemovable()); defaultEditorButton.setEnabled(editorSelected); } - + /** - * Update the selected type. - */ + * 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 editor is removable + * @since 3.1 + */ + private boolean isEditorRemovable() { + TableItem[] items = editorTable.getSelection(); + if (items.length > 0) + return isEditorRemovable(items[0]); + return false; + } + + /** + * Return whether the given editor is removable. An editor is removable + * if it is not submitted via a content-type binding. + * + * @param item the item to test + * @return whether the selected editor is removable + * @since 3.1 + */ + private boolean isEditorRemovable(TableItem item) { + Boolean fromContentType = (Boolean) item.getData(DATA_FROM_CONTENT_TYPE); + if (fromContentType == null) + return true; + return !fromContentType.booleanValue(); + } + + /** + * Update the selected type. + */ public void updateSelectedResourceType() { - // TableItem item = resourceTypeTable.getSelection()[0]; //Single select + // TableItem item = resourceTypeTable.getSelection()[0]; //Single select // Image image = ((IFileEditorMapping)item.getData()).getImageDescriptor().getImage(); // imagesToDispose.addElement(image); // item.setImage(image); Index: Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java =================================================================== RCS file: /home/eclipse/org.eclipse.ui.workbench/Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java,v retrieving revision 1.42 diff -u -r1.42 EditorRegistry.java --- Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java 18 May 2005 17:44:13 -0000 1.42 +++ Eclipse UI/org/eclipse/ui/internal/registry/EditorRegistry.java 18 May 2005 19:32:08 -0000 @@ -1428,4 +1428,45 @@ } return allRelated.toArray(); } + + /** + * Return the editors bound to this content type, either directly or indirectly. + * + * @param type the content type to check + * @return the editors + * @since 3.1 + * + * TODO: this should be rolled in with the above findRelatedObjects code + */ + public IEditorDescriptor [] getEditorsForContentType(IContentType type) { + ArrayList allRelated = new ArrayList(); + if (type == null) + return new IEditorDescriptor [0]; + + Object [] related = relatedRegistry.getRelatedObjects(type); + for (int i = 0; i < related.length; i++) { + // we don't want to return duplicates + if (!allRelated.contains(related[i])) { + // if it's not filtered, add it to the list + if (!WorkbenchActivityHelper.filterItem(related[i])) + allRelated.add(related[i]); + + } + } + + // now add any indirectly related objects, walking up the content type hierarchy + while ((type = type.getBaseType()) != null) { + related = relatedRegistry.getRelatedObjects(type); + for (int i = 0; i < related.length; i++) { + // we don't want to return duplicates + if (!allRelated.contains(related[i])) { + // if it's not filtered, add it to the list + if (!WorkbenchActivityHelper.filterItem(related[i])) + allRelated.add(related[i]); + } + } + } + + return (IEditorDescriptor[]) allRelated.toArray(new IEditorDescriptor[allRelated.size()]); + } }