diff --git a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/OpenWithMenu.java b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/OpenWithMenu.java index 8b69681..15c16c0 100644 --- a/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/OpenWithMenu.java +++ b/bundles/org.eclipse.ui.ide/extensions/org/eclipse/ui/actions/OpenWithMenu.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2000, 2010 IBM Corporation and others. + * Copyright (c) 2000, 2011 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 @@ -20,6 +20,7 @@ import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IResource; import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.content.IContentType; import org.eclipse.jface.action.ContributionItem; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.jface.window.Window; @@ -221,21 +222,27 @@ }; menuItem.addListener(SWT.Selection, listener); } - + /* (non-Javadoc) * Fills the menu with perspective items. */ public void fill(Menu menu, int index) { - IFile file = getFileResource(); + final IFile file= getFileResource(); if (file == null) { return; } + IContentType contentType= IDE.getContentType(file); + FileEditorInput editorInput= new FileEditorInput(file); + IEditorDescriptor defaultEditor = registry .findEditor(IDEWorkbenchPlugin.DEFAULT_TEXT_EDITOR_ID); // may be null - IEditorDescriptor preferredEditor = IDE.getDefaultEditor(file); // may be null + final IEditorDescriptor preferredEditor= IDE.getDefaultEditor(file); // may be null - Object[] editors = registry.getEditors(file.getName(), IDE.getContentType(file)); + IEditorDescriptor[] editors= registry.getEditors(file.getName(), contentType); + + editors= IDE.overrideEditorAssociations(editorInput, contentType, editors); + Collections.sort(Arrays.asList(editors), comparer); boolean defaultFound = false; @@ -245,7 +252,7 @@ ArrayList alreadyMapped = new ArrayList(); for (int i = 0; i < editors.length; i++) { - IEditorDescriptor editor = (IEditorDescriptor) editors[i]; + IEditorDescriptor editor= editors[i]; if (!alreadyMapped.contains(editor)) { createMenuItem(menu, editor, preferredEditor); if (defaultEditor != null @@ -277,7 +284,7 @@ if (descriptor != null) { createMenuItem(menu, descriptor, preferredEditor); } - createDefaultMenuItem(menu, file); + createDefaultMenuItem(menu, file, preferredEditor == null); // add Other... menu item createOtherMenuItem(menu); @@ -340,14 +347,15 @@ } /** - * Creates the menu item for clearing the current selection. - * - * @param menu the menu to add the item to - * @param file the file being edited - */ - private void createDefaultMenuItem(Menu menu, final IFile file) { + * Creates the menu item for clearing the current selection. + * + * @param menu the menu to add the item to + * @param file the file being edited + * @param markAsSelected true if the item should marked as selected + */ + private void createDefaultMenuItem(Menu menu, final IFile file, boolean markAsSelected) { final MenuItem menuItem = new MenuItem(menu, SWT.RADIO); - menuItem.setSelection(IDE.getDefaultEditor(file) == null); + menuItem.setSelection(markAsSelected); menuItem.setText(IDEWorkbenchMessages.DefaultEditorDescription_name); Listener listener = new Listener() { diff --git a/bundles/org.eclipse.ui.ide/plugin.properties b/bundles/org.eclipse.ui.ide/plugin.properties index bf9beb0..3bf622b 100644 --- a/bundles/org.eclipse.ui.ide/plugin.properties +++ b/bundles/org.eclipse.ui.ide/plugin.properties @@ -19,6 +19,7 @@ ExtPoint.resourceFilters = Resource Filters ExtPoint.markerSupport = Marker Support ExtPoint.fileSystemSupport = File System Support +ExtPoint.editorAssociationOverride = Editor Association Override KeysPreference.Name = Keys Preferences KeysPreference.Description = Preferences related to keys, accelerator key bindings, key configurations and commands. diff --git a/bundles/org.eclipse.ui.ide/plugin.xml b/bundles/org.eclipse.ui.ide/plugin.xml index ff6b24a..0fc43ac 100644 --- a/bundles/org.eclipse.ui.ide/plugin.xml +++ b/bundles/org.eclipse.ui.ide/plugin.xml @@ -11,6 +11,7 @@ + @@ -2318,5 +2319,6 @@ class="org.eclipse.ui.internal.about.AboutFeaturesPage" id="20.FeaturesPage"> - + + diff --git a/bundles/org.eclipse.ui.ide/schema/editorAssociationOverride.exsd b/bundles/org.eclipse.ui.ide/schema/editorAssociationOverride.exsd new file mode 100644 index 0000000..c30417b --- /dev/null +++ b/bundles/org.eclipse.ui.ide/schema/editorAssociationOverride.exsd @@ -0,0 +1,125 @@ + + + + + + + + + Allows to override editor associations for the IDE to resolve conflicting contributions. +<p> +There are many ways to find editors for a given input and to open an editor. This extension point will only for work those cases where the request was done via <code>org.eclipse.ui.ide.IDE</code> or where the client code explicitly honors this extension point by calling one of the override methods in <code>org.eclipse.ui.ide.IDE</code>. Main intent is to allow intercepting how editors are opened via the IDE UI like <b>Open</b>, <b>Open With</b> and <b>Open Resource</b>. +</p> + +<p> +<strong>Note:</strong> This extension point should only be used in cases where a product gets assembled with conflicting editor contribtions and where there is no other way to resolve those conflicts. +</p> + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + a unique id that will be used to identify this editor association override + + + + + + + the fully qualified class name implementing the interface <code>org.eclipse.ui.ide.IEditorAssociationOverride</code> + + + + + + + + + + + + + + + 3.8 + + + + + + + + + <pre> + <extension + point="org.eclipse.ui.ide.editorAssociationOverride"> + <editorAssociationOverride + id="exampleOverride" + class="example.ExampleOverride"> + </editorAssociationOverride> + </extension> +</pre> + + + + + + + + + See the <code>org.eclipse.ui.ide.IEditorAssociationOverride</code> interface. + + + + + + + + + + Copyright (c) 2011 IBM Corporation and others.<br> +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 <a href="http://www.eclipse.org/legal/epl-v10.html">http://www.eclipse.org/legal/epl-v10.html</a> + + + + diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java index c97635f..20fda6d 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IDE.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2003, 2010 IBM Corporation and others. + * Copyright (c) 2003, 2011 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 @@ -73,6 +73,7 @@ import org.eclipse.ui.PartInitException; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.Saveable; +import org.eclipse.ui.internal.ide.EditorAssociationOverrideDescriptor; import org.eclipse.ui.internal.ide.IDEWorkbenchMessages; import org.eclipse.ui.internal.ide.IDEWorkbenchPlugin; import org.eclipse.ui.internal.ide.model.StandardPropertiesAdapterFactory; @@ -143,6 +144,9 @@ * lazily initialized on fist access. */ private static MarkerHelpRegistry markerHelpRegistry = null; + + private static IEditorAssociationOverride[] editorAssociationOverrides; + /** * Standard shared images defined by the IDE. These are over and above the @@ -648,7 +652,9 @@ // open the editor on the file IEditorDescriptor editorDesc = getEditorDescriptor(input, determineContentType); - return page.openEditor(new FileEditorInput(input), editorDesc.getId(), + FileEditorInput editorInput= new FileEditorInput(input); + + return page.openEditor(editorInput, editorDesc.getId(), activate); } @@ -883,7 +889,79 @@ IEditorRegistry editorReg= PlatformUI.getWorkbench().getEditorRegistry(); - return getEditorDescriptor(name, editorReg, editorReg.getDefaultEditor(name, contentType)).getId(); + IEditorDescriptor defaultEditor= editorReg.getDefaultEditor(name, contentType); + defaultEditor= overrideDefaultEditorAssociation(new FileStoreEditorInput(fileStore), contentType, defaultEditor); + return getEditorDescriptor(name, editorReg, defaultEditor).getId(); + } + + /** + * Applies the org.eclipse.ui.ide.editorAssociationOverride extensions to the given + * input. + *

+ * Note: It is recommended to get the descriptor for the default editor by + * calling {@link #getDefaultEditor(IFile, boolean)}. This method here should only be used if + * this is not possible for whatever reason. + *

+ * + * @param editorInput the editor input for the editor + * @param contentType the content type of the input or null if not available + * @param editorDescriptor the current association for the given input or null if + * none + * @return the editor descriptor to be used for the given input or null if none. + * Can be editorDescriptor. + * @see IEditorAssociationOverride#overrideDefaultEditor(IEditorInput, IContentType, + * IEditorDescriptor) + * @since 3.8 + */ + public static IEditorDescriptor overrideDefaultEditorAssociation(IEditorInput editorInput, IContentType contentType, IEditorDescriptor editorDescriptor) { + IEditorAssociationOverride[] overrides= getEditorAssociationOverrides(); + for (int i= 0; i < overrides.length; i++) { + editorDescriptor= overrides[i].overrideDefaultEditor(editorInput, contentType, editorDescriptor); + } + return editorDescriptor; + } + + /** + * Applies the org.eclipse.ui.ide.editorAssociationOverride extensions to the given + * input. + * + * @param fileName the name of the file for which to choose the editor + * @param contentType the content type of the input or null if not available + * @param editorDescriptor the current association for the given input or null if + * none + * @return the editor descriptor to be used for the given input or null if none. + * Can be editorDescriptor. + * @see IEditorAssociationOverride#overrideDefaultEditor(String, IContentType, + * IEditorDescriptor) + * @since 3.8 + */ + private static IEditorDescriptor overrideDefaultEditorAssociation(String fileName, IContentType contentType, IEditorDescriptor editorDescriptor) { + IEditorAssociationOverride[] overrides= getEditorAssociationOverrides(); + for (int i= 0; i < overrides.length; i++) { + editorDescriptor= overrides[i].overrideDefaultEditor(fileName, contentType, editorDescriptor); + } + return editorDescriptor; + } + + /** + * Applies the org.eclipse.ui.ide.editorAssociationOverride extensions to the given + * input. + * + * @param editorInput the editor input for the editor + * @param contentType the content type of the input or null if not available + * @param editorDescriptors the current association for the given input + * @return the editor descriptors to be used for the given input - can be + * editorDescriptors. The order is not relevant. + * @see IEditorAssociationOverride#overrideEditors(IEditorInput, IContentType, + * IEditorDescriptor[]) + * @since 3.8 + */ + public static IEditorDescriptor[] overrideEditorAssociations(IEditorInput editorInput, IContentType contentType, IEditorDescriptor[] editorDescriptors) { + IEditorAssociationOverride[] overrides= getEditorAssociationOverrides(); + for (int i= 0; i < overrides.length; i++) { + editorDescriptors= overrides[i].overrideEditors(editorInput, contentType, editorDescriptors); + } + return editorDescriptors; } /** @@ -963,8 +1041,9 @@ IEditorRegistry editorReg = PlatformUI.getWorkbench() .getEditorRegistry(); - return getEditorDescriptor(name, editorReg, editorReg.getDefaultEditor( - name, contentType)); + IEditorDescriptor defaultEditor= editorReg.getDefaultEditor(name, contentType); + overrideDefaultEditorAssociation(name, contentType, defaultEditor); + return getEditorDescriptor(name, editorReg, defaultEditor); } /** @@ -1212,6 +1291,7 @@ if (contentTypes != null) { for(int i = 0 ; i < contentTypes.length; i++) { IEditorDescriptor editorDesc = editorReg.getDefaultEditor(name, contentTypes[i]); + editorDesc= overrideDefaultEditorAssociation(input, contentTypes[i], editorDesc); if ((editorDesc != null) && (editorDesc.isInternal())) return page.openEditor(input, editorDesc.getId()); } @@ -1220,6 +1300,7 @@ // no content types are available, use file name associations IEditorDescriptor[] editors = editorReg.getEditors(name); if (editors != null) { + editors= overrideEditorAssociations(input, null, editors); for(int i = 0 ; i < editors.length; i++) { if ((editors[i] != null) && (editors[i].isInternal())) return page.openEditor(input, editors[i].getId()); @@ -1296,21 +1377,17 @@ } /** - * Returns the default editor for a given file. This method will attempt to - * resolve the editor based on content-type bindings as well as traditional - * name/extension bindings. + * Returns the default editor for a given file. This method will attempt to resolve the editor + * based on content-type bindings as well as traditional name/extension bindings. *

- * A default editor id may be registered for a specific file using - * setDefaultEditor. If the given file has a registered - * default editor id the default editor will derived from it. If not, the - * default editor is determined by taking the file name for the file and + * A default editor id may be registered for a specific file using setDefaultEditor + * . If the given file has a registered default editor id the default editor will derived from + * it. If not, the default editor is determined by taking the file name for the file and * obtaining the default editor for that name. *

* - * @param file - * the file - * @return the descriptor of the default editor, or null if - * not found + * @param file the file + * @return the descriptor of the default editor, or null if not found */ public static IEditorDescriptor getDefaultEditor(IFile file) { return getDefaultEditor(file, true); @@ -1342,34 +1419,35 @@ // Try file specific editor. IEditorRegistry editorReg = PlatformUI.getWorkbench() .getEditorRegistry(); + + IContentType contentType= null; + if (determineContentType) { + contentType= getContentType(file); + } + try { String editorID = file.getPersistentProperty(EDITOR_KEY); if (editorID != null) { IEditorDescriptor desc = editorReg.findEditor(editorID); if (desc != null) { - return desc; + return overrideDefaultEditorAssociation(new FileEditorInput(file), contentType, desc); } } } catch (CoreException e) { // do nothing } - IContentType contentType = null; - if (determineContentType) { - contentType = getContentType(file); - } // Try lookup with filename - return editorReg.getDefaultEditor(file.getName(), contentType); + IEditorDescriptor desc= editorReg.getDefaultEditor(file.getName(), contentType); + return overrideDefaultEditorAssociation(new FileEditorInput(file), contentType, desc); } /** - * Extracts and returns the IResources in the given - * selection or the resource objects they adapts to. + * Extracts and returns the IResources in the given selection or the resource + * objects they adapts to. * - * @param originalSelection - * the original selection, possibly empty - * @return list of resources (element type: IResource), - * possibly empty + * @param originalSelection the original selection, possibly empty + * @return list of resources (element type: IResource), possibly empty */ public static List computeSelectedResources( IStructuredSelection originalSelection) { @@ -1644,5 +1722,22 @@ } return page.openEditors(editorInputs, editorDescriptions, IWorkbenchPage.MATCH_INPUT); } - + + private static synchronized IEditorAssociationOverride[] getEditorAssociationOverrides() { + if (editorAssociationOverrides == null) { + EditorAssociationOverrideDescriptor[] descriptors= EditorAssociationOverrideDescriptor.getContributedEditorAssociationOverrides(); + ArrayList overrides= new ArrayList(descriptors.length); + for (int i= 0; i < descriptors.length; i++) { + try { + IEditorAssociationOverride override= descriptors[i].createOverride(); + overrides.add(override); + } catch (CoreException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + editorAssociationOverrides= (IEditorAssociationOverride[])overrides.toArray(new IEditorAssociationOverride[overrides.size()]); + } + return editorAssociationOverrides; + } } diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IEditorAssociationOverride.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IEditorAssociationOverride.java new file mode 100644 index 0000000..9c3b1b1 --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/ide/IEditorAssociationOverride.java @@ -0,0 +1,74 @@ +/******************************************************************************* + * Copyright (c) 2011 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + ******************************************************************************/ +package org.eclipse.ui.ide; + +import org.eclipse.core.runtime.content.IContentType; +import org.eclipse.ui.IEditorDescriptor; +import org.eclipse.ui.IEditorInput; + + +/** + * Allows to override editor associations for the IDE. + *

+ * This interface is implemented by org.eclipse.ui.ide.editorAssociationOverride + * extensions. + *

+ *

+ * Clients may implement this interface. + *

+ * + * @since 3.8 + */ +public interface IEditorAssociationOverride { + + /** + * Allows to override the given editor descriptors for the given input with a different ones. + * + * @param editorInput the editor input for the editor + * @param contentType the content type of the input or null if not available + * @param editorDescriptors the current association for the given input + * @return the editor descriptors to be used for the given input - can be + * editorDescriptors. The order is not relevant. + */ + IEditorDescriptor[] overrideEditors(IEditorInput editorInput, IContentType contentType, IEditorDescriptor[] editorDescriptors); + + /** + * Allows to override the given editor descriptor for the given input with a different one. + * Normally, this is used to override the default editor for the given input. + *

+ * Though possible, it is advised not to override and editor that has been explicitly chosen by + * the user for the given input. This is the case when + * IFile#getPersistentProperty(IDE.EDITOR_KEY) != null. + *

+ * + * @param editorInput the editor input for the editor + * @param contentType the content type of the input or null if not available + * @param editorDescriptor the current association for the given input or null if + * none + * @return the editor descriptor to be used for the given input or null if none. + * Can be editorDescriptor. + */ + IEditorDescriptor overrideDefaultEditor(IEditorInput editorInput, IContentType contentType, IEditorDescriptor editorDescriptor); + + /** + * Allows to override the given editor descriptor for the given input with a different one. + * Normally, this is used to override the default editor for the given input. + * + * @param fileName the name of the file for which to choose the editor + * @param contentType the content type of the input or null if not available + * @param editorDescriptor the current association for the given input or null if + * none + * @return the editor descriptor to be used for the given input or null if none. + * Can be editorDescriptor. + */ + IEditorDescriptor overrideDefaultEditor(String fileName, IContentType contentType, IEditorDescriptor editorDescriptor); + +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/EditorAssociationOverrideDescriptor.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/EditorAssociationOverrideDescriptor.java new file mode 100644 index 0000000..1b56af7 --- /dev/null +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/EditorAssociationOverrideDescriptor.java @@ -0,0 +1,163 @@ +/******************************************************************************* + * Copyright (c) 2011 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 + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.ui.internal.ide; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.core.runtime.Assert; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.core.runtime.IConfigurationElement; +import org.eclipse.core.runtime.IExtensionRegistry; +import org.eclipse.core.runtime.ISafeRunnable; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.SafeRunner; +import org.eclipse.core.runtime.Status; +import org.eclipse.jface.util.SafeRunnable; +import org.eclipse.ui.ide.IEditorAssociationOverride; + +import com.ibm.icu.text.MessageFormat; + + +/** + * Describes a contribution to the 'org.eclipse.ui.ide.editorAssociationOverride' extension point. + * + * @since 3.8 + * @noinstantiate This class is not intended to be instantiated by clients. + */ +public final class EditorAssociationOverrideDescriptor { + + private static final String EDITOR_ASSOCIATION_OVERRIDE_EXTENSION_POINT= "org.eclipse.ui.ide.editorAssociationOverride"; //$NON-NLS-1$ + + private static final String EDITOR_ASSOCIATION_OVERRIDE_ELEMENT= "editorAssociationOverride"; //$NON-NLS-1$ + private static final String ID_ATTRIBUTE= "id"; //$NON-NLS-1$ + private static final String NAME_ATTRIBUTE= "name"; //$NON-NLS-1$ + private static final String DESCRIPTION_ATTRIBUTE= "description"; //$NON-NLS-1$ + private static final String CLASS_ATTRIBUTE= "class"; //$NON-NLS-1$ + + private IConfigurationElement fElement; + + + /** + * Returns descriptors for all editor association override extensions. + * + * @return an array with the contributed editor association overrides + */ + public static EditorAssociationOverrideDescriptor[] getContributedEditorAssociationOverrides() { + IExtensionRegistry registry= Platform.getExtensionRegistry(); + IConfigurationElement[] elements= registry.getConfigurationElementsFor(EDITOR_ASSOCIATION_OVERRIDE_EXTENSION_POINT); + EditorAssociationOverrideDescriptor[] editorAssociationOverrideDescs= createDescriptors(elements); + return editorAssociationOverrideDescs; + } + + /** + * Creates a new descriptor from the given configuration element. + * + * @param element the configuration element + */ + private EditorAssociationOverrideDescriptor(IConfigurationElement element) { + Assert.isNotNull(element); + fElement= element; + } + + /** + * Creates a new {@link IEditorAssociationOverride}. + * + * @return the editor association override or null if the plug-in isn't loaded yet + * @throws CoreException if a failure occurred during creation + */ + public IEditorAssociationOverride createOverride() throws CoreException { + final Throwable[] exception= new Throwable[1]; + final IEditorAssociationOverride[] result= new IEditorAssociationOverride[1]; + String message= MessageFormat.format(IDEWorkbenchMessages.editorAssociationOverride_error_couldNotCreate_message, new String[] { getId(), fElement.getContributor().getName() }); + ISafeRunnable code= new SafeRunnable(message) { + /* + * @see org.eclipse.core.runtime.ISafeRunnable#run() + */ + public void run() throws Exception { +// String pluginId = fElement.getContributor().getName(); + result[0]= (IEditorAssociationOverride)fElement.createExecutableExtension(CLASS_ATTRIBUTE); + } + /* + * @see org.eclipse.jface.util.SafeRunnable#handleException(java.lang.Throwable) + */ + public void handleException(Throwable ex) { + super.handleException(ex); + exception[0]= ex; + } + + }; + + SafeRunner.run(code); + + if (exception[0] == null) + return result[0]; + throw new CoreException(new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, IStatus.OK, message, exception[0])); + + } + + //---- XML Attribute accessors --------------------------------------------- + + /** + * Returns the editor association override's id. + * + * @return the editor association override's id + */ + public String getId() { + return fElement.getAttribute(ID_ATTRIBUTE); + } + + /** + * Returns the editor association override's name. + * + * @return the editor association override's name + */ + public String getName() { + return fElement.getAttribute(NAME_ATTRIBUTE); + } + + /** + * Returns the editor association override's description. + * + * @return the editor association override's description or null if not provided + */ + public String getDescription() { + return fElement.getAttribute(DESCRIPTION_ATTRIBUTE); + } + + public boolean equals(Object obj) { + if (obj == null || !obj.getClass().equals(this.getClass()) || getId() == null) + return false; + return getId().equals(((EditorAssociationOverrideDescriptor)obj).getId()); + } + + public int hashCode() { + return getId().hashCode(); + } + + private static EditorAssociationOverrideDescriptor[] createDescriptors(IConfigurationElement[] elements) { + List result= new ArrayList(elements.length); + for (int i= 0; i < elements.length; i++) { + IConfigurationElement element= elements[i]; + if (EDITOR_ASSOCIATION_OVERRIDE_ELEMENT.equals(element.getName())) { + EditorAssociationOverrideDescriptor desc= new EditorAssociationOverrideDescriptor(element); + result.add(desc); + } else { + String message= MessageFormat.format(IDEWorkbenchMessages.editorAssociationOverride_error_invalidElementName_message, + new String[] { element.getContributor().getName(), element.getName() }); + IDEWorkbenchPlugin.getDefault().getLog().log(new Status(IStatus.ERROR, IDEWorkbenchPlugin.IDE_WORKBENCH, IStatus.OK, message, null)); + } + } + return (EditorAssociationOverrideDescriptor[])result.toArray(new EditorAssociationOverrideDescriptor[result.size()]); + } + +} diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java index ac7ddb4..0ae0721 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchMessages.java @@ -990,6 +990,10 @@ public static String OpenDelayedFileAction_message_fileNotFound; public static String OpenDelayedFileAction_message_noWindow; + public static String editorAssociationOverride_error_couldNotCreate_message; + public static String editorAssociationOverride_error_invalidElementName_message; + public static String editorAssociationOverride_error_invalidExtension_message; + static { // load message values from bundle file NLS.initializeMessages(BUNDLE_NAME, IDEWorkbenchMessages.class); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties index b1aec37..13d2096 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/messages.properties @@ -1002,3 +1002,6 @@ OpenDelayedFileAction_message_fileNotFound= The file ''{0}'' could not be found. OpenDelayedFileAction_message_noWindow= The file ''{0}'' could not be opened.\nPlease make sure there is at least one open perspective. +editorAssociationOverride_error_couldNotCreate_message=The ''{0}'' extension from plug-in ''{1}'' to the ''org.eclipse.ui.ide.editorAssociationOverride'' extension point failed to load the editor association override class. +editorAssociationOverride_error_invalidElementName_message=An extension from plug-in ''{0}'' to the ''org.eclipse.ui.ide.editorAssociationOverride'' extension point was ignored because it contains the following invalid element: ''{1}''. +editorAssociationOverride_error_invalidExtension_message=The ''{0}'' extension from plug-in ''{1}'' to the ''org.eclipse.ui.ide.editorAssociationOverride'' extension point will be ignored because it contains invalid attributes.