diff options
| author | Mickael Istria | 2016-03-03 14:05:57 +0000 |
|---|---|---|
| committer | Dani Megert | 2016-04-15 15:31:37 +0000 |
| commit | 7a96414a097129f863ff053184ab33a679467890 (patch) | |
| tree | 698315544c1847641f08a4888f98a2514c54f959 | |
| parent | 162673b8ad2994a646864ac334dbf706b6bdea9e (diff) | |
| download | eclipse.platform.ui-7a96414a097129f863ff053184ab33a679467890.tar.gz eclipse.platform.ui-7a96414a097129f863ff053184ab33a679467890.tar.xz eclipse.platform.ui-7a96414a097129f863ff053184ab33a679467890.zip | |
Bug 488289 - UnassociatedEditorStrategyRegistry should not be static
Change-Id: I89b8b29fedd9e65563c67d5ccd65f49d1704ad17
Signed-off-by: Mickael Istria <mistria@redhat.com>
4 files changed, 32 insertions, 12 deletions
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 49363cd8365..1a3928ca9bd 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 @@ -871,7 +871,7 @@ public final class IDE { defaultEditor); return getEditorDescriptor(name, editorReg, defaultEditor, allowInteractive).getId(); } - + /** * Applies the <code>org.eclipse.ui.ide.editorAssociationOverride</code> extensions to the given * input. @@ -1177,7 +1177,7 @@ public final class IDE { return editorDesc; } - + /** * Get the editor descriptor for a given name using the editorDescriptor * passed in as a default as a starting point. @@ -1245,8 +1245,10 @@ public final class IDE { String preferedStrategy = IDEWorkbenchPlugin.getDefault().getPreferenceStore() .getString(UNASSOCIATED_EDITOR_STRATEGY_PREFERENCE_KEY); IUnassociatedEditorStrategy res = null; - if (allowInteractive || !UnassociatedEditorStrategyRegistry.isInteractive(preferedStrategy)) { - res = UnassociatedEditorStrategyRegistry.getStrategy(preferedStrategy); + UnassociatedEditorStrategyRegistry registry = IDEWorkbenchPlugin.getDefault() + .getUnassociatedEditorStrategyRegistry(); + if (allowInteractive || !registry.isInteractive(preferedStrategy)) { + res = registry.getStrategy(preferedStrategy); } if (res == null) { res = new SystemEditorOrTextEditorStrategy(); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ExtendedFileEditorsPreferencePage.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ExtendedFileEditorsPreferencePage.java index 48e229fd780..f77ead7232f 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ExtendedFileEditorsPreferencePage.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/ExtendedFileEditorsPreferencePage.java @@ -46,6 +46,8 @@ public class ExtendedFileEditorsPreferencePage extends FileEditorsPreferencePage protected Composite createContents(Composite parent) { Composite res = (Composite)super.createContents(parent); + final UnassociatedEditorStrategyRegistry registry = IDEWorkbenchPlugin.getDefault() + .getUnassociatedEditorStrategyRegistry(); Composite defaultStrategyComposite = new Composite(res, SWT.NONE); defaultStrategyComposite.setLayout(new GridLayout(2, false)); GridData layoutData = new GridData(SWT.FILL, SWT.CENTER, true, false, 2, 1); @@ -60,7 +62,7 @@ public class ExtendedFileEditorsPreferencePage extends FileEditorsPreferencePage @Override public String getText(Object o) { String id = (String) o; - String label = UnassociatedEditorStrategyRegistry.getLabel(id); + String label = registry.getLabel(id); if (label != null) { return label; } @@ -69,7 +71,7 @@ public class ExtendedFileEditorsPreferencePage extends FileEditorsPreferencePage } }); viewer.setContentProvider(new ArrayContentProvider()); - viewer.setInput(UnassociatedEditorStrategyRegistry.retrieveAllStrategies()); + viewer.setInput(registry.retrieveAllStrategies()); this.idePreferenceStore = IDEWorkbenchPlugin.getDefault().getPreferenceStore(); viewer.setSelection( new StructuredSelection(this.idePreferenceStore.getString(IDE.UNASSOCIATED_EDITOR_STRATEGY_PREFERENCE_KEY))); diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchPlugin.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchPlugin.java index edb9dfa54f7..f2a94ab8b88 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchPlugin.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/IDEWorkbenchPlugin.java @@ -92,6 +92,11 @@ public class IDEWorkbenchPlugin extends AbstractUIPlugin { */ private MarkerImageProviderRegistry markerImageProviderRegistry = null; + /** + * Unassociated file/editor strategy registry; lazily initialized + */ + private UnassociatedEditorStrategyRegistry unassociatedEditorStrategyRegistry = null; + private ResourceManager resourceManager; /** @@ -262,6 +267,17 @@ public class IDEWorkbenchPlugin extends AbstractUIPlugin { return markerImageProviderRegistry; } + /** + * Returns the unassociated file/editor strategy registry for the workbench. + * + * @return the unassociated file/editor strategy registry + */ + public synchronized UnassociatedEditorStrategyRegistry getUnassociatedEditorStrategyRegistry() { + if (unassociatedEditorStrategyRegistry == null) { + unassociatedEditorStrategyRegistry = new UnassociatedEditorStrategyRegistry(); + } + return unassociatedEditorStrategyRegistry; + } /** * Returns the about information of all known features, diff --git a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/UnassociatedEditorStrategyRegistry.java b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/UnassociatedEditorStrategyRegistry.java index 64dd8a89d2e..e0341e1f046 100644 --- a/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/UnassociatedEditorStrategyRegistry.java +++ b/bundles/org.eclipse.ui.ide/src/org/eclipse/ui/internal/ide/UnassociatedEditorStrategyRegistry.java @@ -37,7 +37,7 @@ public class UnassociatedEditorStrategyRegistry { * @return an instance of the strategy, or {@code null} if no strategy is * found for this id */ - public static IUnassociatedEditorStrategy getStrategy(String strategyId) { + public IUnassociatedEditorStrategy getStrategy(String strategyId) { if (strategyId == null) { return null; } @@ -58,7 +58,7 @@ public class UnassociatedEditorStrategyRegistry { return null; } - private static String readAttribute(IConfigurationElement extension, String attribute) { + private String readAttribute(IConfigurationElement extension, String attribute) { String res = extension.getAttribute(attribute); if (res == null) { IDEWorkbenchPlugin.log("Missing attribute '" + attribute + "' for extension to " + EXTENSION_POINT_ID //$NON-NLS-1$ //$NON-NLS-2$ @@ -73,7 +73,7 @@ public class UnassociatedEditorStrategyRegistry { * @return not modifiable set with all known strategy id's in their * definition order */ - public static Set<String> retrieveAllStrategies() { + public Set<String> retrieveAllStrategies() { populateIdsToLabel(); return Collections.unmodifiableSet(idsToLabel.keySet()); } @@ -84,14 +84,14 @@ public class UnassociatedEditorStrategyRegistry { * @return the label for the supplied strategy id, or {@code null} for * unknown id. */ - public static String getLabel(String id) { + public String getLabel(String id) { if (idsToLabel == null || !idsToLabel.containsKey(id)) { populateIdsToLabel(); } return idsToLabel.get(id); } - private static void populateIdsToLabel() { + private void populateIdsToLabel() { Map<String, String> res = new LinkedHashMap<>(); IExtensionRegistry extRegistry = Platform.getExtensionRegistry(); IConfigurationElement[] extensions = extRegistry.getConfigurationElementsFor(EXTENSION_POINT_ID); @@ -112,7 +112,7 @@ public class UnassociatedEditorStrategyRegistry { * @return Whether the specified strategy is interactive, or false is * strategy is unknown */ - public static boolean isInteractive(String strategyId) { + public boolean isInteractive(String strategyId) { if (strategyId == null) { return false; } |
