diff options
author | Laurent Delaigue | 2017-02-01 15:03:04 +0000 |
---|---|---|
committer | Laurent Delaigue | 2017-02-13 09:42:49 +0000 |
commit | 150990a30c70cded8f9668f92ce89a604a4328f6 (patch) | |
tree | 02ec8934e63e258002b06b6d5a629ad49dd5b509 | |
parent | e8071982936d413c1f5a408bff7912b46cc203f4 (diff) | |
download | org.eclipse.emf.compare-150990a30c70cded8f9668f92ce89a604a4328f6.tar.gz org.eclipse.emf.compare-150990a30c70cded8f9668f92ce89a604a4328f6.tar.xz org.eclipse.emf.compare-150990a30c70cded8f9668f92ce89a604a4328f6.zip |
[496582] Consider preferences scope hierarchy
Make sure we use either the platform's IPreferencesService or the
relevant IPreferenceStore when reading and writing preferences
everywhere in EMFCompare.
Bug: 496582
Change-Id: I2cbdf6f9356eafba867f0473f680429d0ae6cd35
Also-by: Mathias Schaefer <mschaefer@eclipsesource.com>
Also-by: Philip Langer <planger@eclipsesource.com>
Signed-off-by: Laurent Delaigue <laurent.delaigue@obeo.fr>
34 files changed, 411 insertions, 594 deletions
diff --git a/plugins/org.eclipse.emf.compare.egit/src/org/eclipse/emf/compare/egit/internal/match/EGitMatchEngineFactory.java b/plugins/org.eclipse.emf.compare.egit/src/org/eclipse/emf/compare/egit/internal/match/EGitMatchEngineFactory.java index 25e6a2a43..ea07a3093 100644 --- a/plugins/org.eclipse.emf.compare.egit/src/org/eclipse/emf/compare/egit/internal/match/EGitMatchEngineFactory.java +++ b/plugins/org.eclipse.emf.compare.egit/src/org/eclipse/emf/compare/egit/internal/match/EGitMatchEngineFactory.java @@ -66,7 +66,7 @@ public class EGitMatchEngineFactory extends DefaultRCPMatchEngineFactory { */ @Override public IMatchEngine getMatchEngine() { - final UseIdentifiers useUdentifier = getUseIdentifierValue(getConfiguration()); + final UseIdentifiers useUdentifier = getUseIdentifierValue(); final Collection<IResourceMatchingStrategy> strategies = Sets.newLinkedHashSet(); strategies.add(new LocationMatchingStrategy()); return DefaultMatchEngine.create(useUdentifier, diff --git a/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/AbstractCompareStatement.java b/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/AbstractCompareStatement.java index 005ba218c..d019bf7b4 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/AbstractCompareStatement.java +++ b/plugins/org.eclipse.emf.compare.ide.ui.tests.framework/src/org/eclipse/emf/compare/ide/ui/tests/framework/AbstractCompareStatement.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2016 Obeo. + * Copyright (c) 2016 Obeo 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 @@ -7,10 +7,10 @@ * * Contributors: * Obeo - initial API and implementation + * Mathias Schaefer - preferences refactoring *******************************************************************************/ package org.eclipse.emf.compare.ide.ui.tests.framework; -import java.util.ArrayList; import java.util.Collection; import java.util.Collections; import java.util.List; @@ -20,12 +20,13 @@ import org.eclipse.core.runtime.IExtension; import org.eclipse.core.runtime.IExtensionPoint; import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.ide.ui.internal.EMFCompareIDEUIPlugin; import org.eclipse.emf.compare.ide.ui.internal.preferences.EMFCompareUIPreferences; import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; import org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePreferences; import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.junit.runners.model.FrameworkMethod; import org.junit.runners.model.Statement; @@ -65,6 +66,24 @@ public abstract class AbstractCompareStatement extends Statement { private static final String CONFLICT_EXTENSION_POINT_ID = EMFCompareRCPPlugin.PLUGIN_ID + ID_SEPARATOR + EMFCompareRCPPlugin.CONFLICT_DETECTOR_PPID; + /** The default disabled match engines. */ + private static final List<String> DEFAULT_DISABLED_MATCH_ENGINES = Collections.emptyList(); + + /** The default diff engine. */ + private static final String DEFAULT_DIFF_ENGINE = "org.eclipse.emf.compare.rcp.default.diffEngine"; //$NON-NLS-1$ + + /** The default eq engine. */ + private static final String DEFAULT_EQ_ENGINE = "org.eclipse.emf.compare.rcp.default.equiEngine"; //$NON-NLS-1$ + + /** The default req engine. */ + private static final String DEFAULT_REQ_ENGINE = "org.eclipse.emf.compare.rcp.default.reqEngine"; //$NON-NLS-1$ + + /** The default conflict detector. */ + private static final String DEFAULT_CONFLICT_DETECTOR = "org.eclipse.emf.compare.rcp.fast.conflictDetector"; //$NON-NLS-1$ + + /** The default disabled post-processors. */ + private static final List<String> DEFAULT_DISABLED_POST_PROCESSORS = Collections.emptyList(); + /** The test class. */ protected final Object testObject; @@ -72,8 +91,8 @@ public abstract class AbstractCompareStatement extends Statement { protected final FrameworkMethod test; /** The EMFCompare preferences. */ - private final IEclipsePreferences emfComparePreferences = EMFCompareRCPPlugin.getDefault() - .getEMFComparePreferences(); + private final IPreferenceStore rcpPreferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, + EMFCompareRCPPlugin.PLUGIN_ID); /** The EMFCompare UI preferences. */ private final IPreferenceStore uiPreferenceStore = EMFCompareIDEUIPlugin.getDefault() @@ -103,24 +122,6 @@ public abstract class AbstractCompareStatement extends Statement { /** The default resolution strategy. */ private String defaultResolutionStrategy = "WORKSPACE"; //$NON-NLS-1$ - /** The default disabled match engines. */ - private List<String> defaultDisabledMatchEngines = new ArrayList<String>(); - - /** The default diff engine. */ - private String defaultDiffEngine = "org.eclipse.emf.compare.rcp.default.diffEngine"; //$NON-NLS-1$ - - /** The default eq engine. */ - private String defaultEqEngine = "org.eclipse.emf.compare.rcp.default.equiEngine"; //$NON-NLS-1$ - - /** The default req engine. */ - private String defaultReqEngine = "org.eclipse.emf.compare.rcp.default.reqEngine"; //$NON-NLS-1$ - - /** The default conflict detector. */ - private String defaultConflictDetector = "org.eclipse.emf.compare.rcp.fast.conflictDetector"; //$NON-NLS-1$ - - /** The default disabled post-processors. */ - private List<String> defaultDisabledPostProcessors = new ArrayList<String>(); - /** * Constructor for the classic (no Git) comparison statement. * @@ -144,6 +145,7 @@ public abstract class AbstractCompareStatement extends Statement { this.reqEngine = configuration.getReqEngine(); this.conflictDetector = configuration.getConflictDetector(); this.disabledPostProcessors = configuration.getDisabledPostProcessors(); + setEMFComparePreferencesDefaults(); } /** @@ -164,19 +166,32 @@ public abstract class AbstractCompareStatement extends Statement { } /** - * Restore preferences as they were before the test. + * Set the default values to use for all test-relevant preference settings. */ - protected void restoreEMFComparePreferences() { - uiPreferenceStore.setValue(EMFCompareUIPreferences.RESOLUTION_SCOPE_PREFERENCE, + private void setEMFComparePreferencesDefaults() { + uiPreferenceStore.setDefault(EMFCompareUIPreferences.RESOLUTION_SCOPE_PREFERENCE, defaultResolutionStrategy); - emfComparePreferences.put(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, - join(defaultDisabledMatchEngines, PREFERENCES_SEPARATOR)); - emfComparePreferences.put(EMFComparePreferences.DIFF_ENGINES, defaultDiffEngine); - emfComparePreferences.put(EMFComparePreferences.EQUI_ENGINES, defaultEqEngine); - emfComparePreferences.put(EMFComparePreferences.REQ_ENGINES, defaultReqEngine); - emfComparePreferences.put(EMFComparePreferences.CONFLICTS_DETECTOR, defaultConflictDetector); - emfComparePreferences.put(EMFComparePreferences.DISABLED_POST_PROCESSOR, - join(defaultDisabledPostProcessors, PREFERENCES_SEPARATOR)); + rcpPreferenceStore.setDefault(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, + join(DEFAULT_DISABLED_MATCH_ENGINES, PREFERENCES_SEPARATOR)); + rcpPreferenceStore.setDefault(EMFComparePreferences.DIFF_ENGINES, DEFAULT_DIFF_ENGINE); + rcpPreferenceStore.setDefault(EMFComparePreferences.EQUI_ENGINES, DEFAULT_EQ_ENGINE); + rcpPreferenceStore.setDefault(EMFComparePreferences.REQ_ENGINES, DEFAULT_REQ_ENGINE); + rcpPreferenceStore.setDefault(EMFComparePreferences.CONFLICTS_DETECTOR, DEFAULT_CONFLICT_DETECTOR); + rcpPreferenceStore.setDefault(EMFComparePreferences.DISABLED_POST_PROCESSOR, + join(DEFAULT_DISABLED_POST_PROCESSORS, PREFERENCES_SEPARATOR)); + } + + /** + * Restore preferences as if they were unset by the user. + */ + protected void restoreEMFComparePreferences() { + uiPreferenceStore.setToDefault(EMFCompareUIPreferences.RESOLUTION_SCOPE_PREFERENCE); + rcpPreferenceStore.setToDefault(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES); + rcpPreferenceStore.setToDefault(EMFComparePreferences.DIFF_ENGINES); + rcpPreferenceStore.setToDefault(EMFComparePreferences.EQUI_ENGINES); + rcpPreferenceStore.setToDefault(EMFComparePreferences.REQ_ENGINES); + rcpPreferenceStore.setToDefault(EMFComparePreferences.CONFLICTS_DETECTOR); + rcpPreferenceStore.setToDefault(EMFComparePreferences.DISABLED_POST_PROCESSOR); } /** @@ -206,19 +221,11 @@ public abstract class AbstractCompareStatement extends Statement { * Set the match engine preference. */ private void setMatchPreference() { - String disabMatchEngine = emfComparePreferences.get( - EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, - join(defaultDisabledMatchEngines, PREFERENCES_SEPARATOR)); - defaultDisabledMatchEngines.clear(); - for (String matchEngine : disabMatchEngine.split(PREFERENCES_SEPARATOR)) { - defaultDisabledMatchEngines.add(matchEngine); - } - List<String> matchEngineNames = Collections.emptyList(); for (Class<?> matchEngine : disabledMatchEngines) { matchEngineNames.add(matchEngine.getCanonicalName()); } - emfComparePreferences.put(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, + rcpPreferenceStore.setValue(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, join(matchEngineNames, PREFERENCES_SEPARATOR)); } @@ -229,7 +236,7 @@ public abstract class AbstractCompareStatement extends Statement { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(DIFF_EXTENSION_POINT_ID); IExtension[] extensions = extensionPoint.getExtensions(); - String diffEngineId = defaultDiffEngine; + String diffEngineId = null; for (IExtension iExtension : extensions) { for (IConfigurationElement iConfig : iExtension.getConfigurationElements()) { if (iConfig.getAttribute(EXTENSION_POINT_CLASS_SELECTOR) @@ -239,9 +246,9 @@ public abstract class AbstractCompareStatement extends Statement { } } } - - defaultDiffEngine = emfComparePreferences.get(EMFComparePreferences.DIFF_ENGINES, defaultDiffEngine); - emfComparePreferences.put(EMFComparePreferences.DIFF_ENGINES, diffEngineId); + if (diffEngineId != null) { + rcpPreferenceStore.setValue(EMFComparePreferences.DIFF_ENGINES, diffEngineId); + } } /** @@ -251,7 +258,7 @@ public abstract class AbstractCompareStatement extends Statement { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(EQ_EXTENSION_POINT_ID); IExtension[] extensions = extensionPoint.getExtensions(); - String eqEngineId = defaultEqEngine; + String eqEngineId = null; for (IExtension iExtension : extensions) { for (IConfigurationElement iConfig : iExtension.getConfigurationElements()) { if (iConfig.getAttribute(EXTENSION_POINT_CLASS_SELECTOR) @@ -261,9 +268,9 @@ public abstract class AbstractCompareStatement extends Statement { } } } - - defaultEqEngine = emfComparePreferences.get(EMFComparePreferences.EQUI_ENGINES, defaultEqEngine); - emfComparePreferences.put(EMFComparePreferences.EQUI_ENGINES, eqEngineId); + if (eqEngineId != null) { + rcpPreferenceStore.setValue(EMFComparePreferences.EQUI_ENGINES, eqEngineId); + } } /** @@ -273,7 +280,7 @@ public abstract class AbstractCompareStatement extends Statement { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(REQ_EXTENSION_POINT_ID); IExtension[] extensions = extensionPoint.getExtensions(); - String reqEngineId = defaultReqEngine; + String reqEngineId = null; for (IExtension iExtension : extensions) { for (IConfigurationElement iConfig : iExtension.getConfigurationElements()) { if (iConfig.getAttribute(EXTENSION_POINT_CLASS_SELECTOR) @@ -283,9 +290,9 @@ public abstract class AbstractCompareStatement extends Statement { } } } - - defaultReqEngine = emfComparePreferences.get(EMFComparePreferences.REQ_ENGINES, defaultReqEngine); - emfComparePreferences.put(EMFComparePreferences.REQ_ENGINES, reqEngineId); + if (reqEngineId != null) { + rcpPreferenceStore.setValue(EMFComparePreferences.REQ_ENGINES, reqEngineId); + } } /** @@ -295,7 +302,7 @@ public abstract class AbstractCompareStatement extends Statement { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = extensionRegistry.getExtensionPoint(CONFLICT_EXTENSION_POINT_ID); IExtension[] extensions = extensionPoint.getExtensions(); - String conflictDetectorId = defaultConflictDetector; + String conflictDetectorId = null; for (IExtension iExtension : extensions) { for (IConfigurationElement iConfig : iExtension.getConfigurationElements()) { if (iConfig.getAttribute(EXTENSION_POINT_CLASS_SELECTOR) @@ -305,28 +312,20 @@ public abstract class AbstractCompareStatement extends Statement { } } } - - defaultConflictDetector = emfComparePreferences.get(EMFComparePreferences.CONFLICTS_DETECTOR, - defaultConflictDetector); - emfComparePreferences.put(EMFComparePreferences.CONFLICTS_DETECTOR, conflictDetectorId); + if (conflictDetectorId != null) { + rcpPreferenceStore.setValue(EMFComparePreferences.CONFLICTS_DETECTOR, conflictDetectorId); + } } /** * Set the post-processors preference. */ private void setPostProcessorPreference() { - String disabPostProcessors = emfComparePreferences.get(EMFComparePreferences.DISABLED_POST_PROCESSOR, - join(defaultDisabledPostProcessors, PREFERENCES_SEPARATOR)); - defaultDisabledPostProcessors.clear(); - for (String postProcessor : disabPostProcessors.split(PREFERENCES_SEPARATOR)) { - defaultDisabledPostProcessors.add(postProcessor); - } - List<String> postProcessorNames = Collections.emptyList(); for (Class<?> postProcessor : disabledPostProcessors) { postProcessorNames.add(postProcessor.getCanonicalName()); } - emfComparePreferences.put(EMFComparePreferences.DISABLED_POST_PROCESSOR, + rcpPreferenceStore.setValue(EMFComparePreferences.DISABLED_POST_PROCESSOR, join(postProcessorNames, PREFERENCES_SEPARATOR)); } diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/AbstractCompareHandler.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/AbstractCompareHandler.java index a82d4a3f2..5d3e0aedf 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/AbstractCompareHandler.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/AbstractCompareHandler.java @@ -17,7 +17,6 @@ import java.util.Iterator; import org.eclipse.compare.CompareConfiguration; import org.eclipse.compare.CompareEditorInput; import org.eclipse.core.commands.AbstractHandler; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.emf.common.command.CommandStack; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notifier; @@ -58,12 +57,6 @@ public abstract class AbstractCompareHandler extends AbstractHandler { protected static CompareEditorInput createCompareEditorInput(IWorkbenchPart part, AdapterFactory adapterFactory, Notifier left, Notifier right, Notifier origin) { - return createCompareEditorInput(part, adapterFactory, left, right, origin, null); - } - - protected static CompareEditorInput createCompareEditorInput(IWorkbenchPart part, - AdapterFactory adapterFactory, Notifier left, Notifier right, Notifier origin, - IEclipsePreferences enginePreferences) { CompareEditorInput input = null; final ICompareEditingDomain editingDomain = createEMFCompareEditingDomain(part, left, right, origin); @@ -76,20 +69,8 @@ public abstract class AbstractCompareHandler extends AbstractHandler { matchEngineFactoryRegistry.add(eObjectMatchEngineFactory); final Builder builder = EMFCompare.builder(); - final IEclipsePreferences preferences; - if (enginePreferences == null) { - preferences = EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(); - } else { - preferences = enginePreferences; - } - if (preferences != null) { - EMFCompareBuilderConfigurator engineProvider = new EMFCompareBuilderConfigurator(preferences, - matchEngineFactoryRegistry, EMFCompareRCPPlugin.getDefault().getPostProcessorRegistry()); - engineProvider.configure(builder); - } else { - builder.setMatchEngineFactoryRegistry(matchEngineFactoryRegistry) - .setPostProcessorRegistry(EMFCompareRCPPlugin.getDefault().getPostProcessorRegistry()); - } + EMFCompareBuilderConfigurator engineProvider = EMFCompareBuilderConfigurator.createDefault(); + engineProvider.configure(builder); EMFCompare comparator = builder.build(); IComparisonScope scope = new DefaultComparisonScope(left, right, origin); diff --git a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/EMFComparisonSourceActionHandler.java b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/EMFComparisonSourceActionHandler.java index ebc350122..802917678 100644 --- a/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/EMFComparisonSourceActionHandler.java +++ b/plugins/org.eclipse.emf.compare.ide.ui/src/org/eclipse/emf/compare/ide/ui/internal/handler/EMFComparisonSourceActionHandler.java @@ -28,7 +28,6 @@ import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.IAdapterManager; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Platform; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.emf.common.command.CommandStack; import org.eclipse.emf.common.notify.AdapterFactory; import org.eclipse.emf.common.notify.Notifier; @@ -183,16 +182,8 @@ public class EMFComparisonSourceActionHandler extends AbstractHandler { final EMFCompareConfiguration configuration = new EMFCompareConfiguration(new CompareConfiguration()); final Builder builder = EMFCompare.builder(); - final IEclipsePreferences preferences = EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(); - final EMFCompareBuilderConfigurator engineProvider; - if (preferences != null) { - engineProvider = new EMFCompareBuilderConfigurator(preferences, - EMFCompareRCPPlugin.getDefault().getMatchEngineFactoryRegistry(), - EMFCompareRCPPlugin.getDefault().getPostProcessorRegistry()); - } else { - engineProvider = EMFCompareBuilderConfigurator.createDefault(); - } + final EMFCompareBuilderConfigurator engineProvider = EMFCompareBuilderConfigurator.createDefault(); engineProvider.configure(builder); final EMFCompare comparator = builder.build(); diff --git a/plugins/org.eclipse.emf.compare.rcp.tests/src/org/eclipse/emf/compare/rcp/tests/MatchEngineFactoryRegistryWrapperTest.java b/plugins/org.eclipse.emf.compare.rcp.tests/src/org/eclipse/emf/compare/rcp/tests/MatchEngineFactoryRegistryWrapperTest.java index 4bbff66ef..50fae0d0c 100644 --- a/plugins/org.eclipse.emf.compare.rcp.tests/src/org/eclipse/emf/compare/rcp/tests/MatchEngineFactoryRegistryWrapperTest.java +++ b/plugins/org.eclipse.emf.compare.rcp.tests/src/org/eclipse/emf/compare/rcp/tests/MatchEngineFactoryRegistryWrapperTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2015 Obeo. + * Copyright (c) 2014, 2016 Obeo 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 @@ -7,6 +7,7 @@ * * Contributors: * Obeo - initial API and implementation + * Mathias Schaefer - preferences refactoring *******************************************************************************/ package org.eclipse.emf.compare.rcp.tests; @@ -16,19 +17,16 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; - import java.io.IOException; import java.util.Collection; import java.util.Collections; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.EMFCompare; import org.eclipse.emf.compare.match.IMatchEngine; import org.eclipse.emf.compare.match.IMatchEngine.Factory; import org.eclipse.emf.compare.match.impl.MatchEngineFactoryImpl; +import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; import org.eclipse.emf.compare.rcp.internal.extension.IItemDescriptor; import org.eclipse.emf.compare.rcp.internal.extension.impl.ItemRegistry; import org.eclipse.emf.compare.rcp.internal.extension.impl.ItemUtil; @@ -42,6 +40,9 @@ import org.junit.Before; import org.junit.Test; import org.osgi.service.prefs.BackingStoreException; +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; + /** * Test class for {@link MatchEngineFactoryRegistryWrapper}. * @@ -52,8 +53,6 @@ public class MatchEngineFactoryRegistryWrapperTest { private MatchEngineFactoryRegistryWrapper registryWrapper; - private IEclipsePreferences preferences; - /** * Creates a comparison scope from Ecore model. * @@ -65,21 +64,15 @@ public class MatchEngineFactoryRegistryWrapperTest { return new DefaultComparisonScope(ecoreData.getLeft(), ecoreData.getRight(), ecoreData.getOrigin()); } - // For Helios compatibility. - @SuppressWarnings("deprecation") @Before public void setUp() throws BackingStoreException { - ItemRegistry<Factory> registry = new ItemRegistry<IMatchEngine.Factory>(); - // Mock preference node. - preferences = new InstanceScope() - .getNode("org.eclipse.emf.compare.tests.rcp.MatchEngineFactoryRegistryWrapperTest"); - preferences.clear(); - registryWrapper = new MatchEngineFactoryRegistryWrapper(registry, preferences); + ItemRegistry<Factory> registry = new ItemRegistry<>(); + registryWrapper = new MatchEngineFactoryRegistryWrapper(registry); } @After public void tearDown() throws BackingStoreException { - preferences.clear(); + InstanceScope.INSTANCE.getNode(EMFCompareRCPPlugin.PLUGIN_ID).clear(); } /** @@ -274,12 +267,12 @@ public class MatchEngineFactoryRegistryWrapperTest { IComparisonScope scope = createComparisonScope(); assertSame(registryWrapper.getHighestRankingMatchEngineFactory(scope), factory3); - disableEngine(preferences, EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, + disableEngine(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, Collections.singleton(factory3.getClass().getName())); assertSame(registryWrapper.getHighestRankingMatchEngineFactory(scope), factory2); assertTrue(!registryWrapper.getMatchEngineFactories(scope).contains(factory3)); - disableEngine(preferences, EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, + disableEngine(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, Lists.newArrayList(factory3.getClass().getName(), factory2.getClass().getName())); assertSame(registryWrapper.getHighestRankingMatchEngineFactory(scope), factory); assertTrue(!registryWrapper.getMatchEngineFactories(scope).contains(factory2)); @@ -319,18 +312,17 @@ public class MatchEngineFactoryRegistryWrapperTest { /** * Disables engine in preferences. * - * @param preference - * {@link IEclipsePreferences} * @param key * @param toDisable - * {@link Collection} of {@link IItemDescriptor} to disable. + * {@link Collection} of {@link IItemDescriptor} to disable, null or empty to enable all + * engines. */ - private void disableEngine(IEclipsePreferences preference, String key, Collection<String> toDisable) { + private void disableEngine(String key, Collection<String> toDisable) { if (toDisable != null && !toDisable.isEmpty()) { String newPreferenceValue = Joiner.on(ItemUtil.PREFERENCE_DELIMITER).join(toDisable); - preference.put(key, newPreferenceValue); + InstanceScope.INSTANCE.getNode(EMFCompareRCPPlugin.PLUGIN_ID).put(key, newPreferenceValue); } else { - preference.remove(key); + InstanceScope.INSTANCE.getNode(EMFCompareRCPPlugin.PLUGIN_ID).remove(key); } } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui.tests/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.compare.rcp.ui.tests/META-INF/MANIFEST.MF index 25f269019..5c0b5b90c 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui.tests/META-INF/MANIFEST.MF +++ b/plugins/org.eclipse.emf.compare.rcp.ui.tests/META-INF/MANIFEST.MF @@ -13,7 +13,8 @@ Require-Bundle: org.eclipse.core.runtime, org.eclipse.emf.compare.rcp;bundle-version="2.1.0", org.eclipse.emf.compare.rcp.ui;bundle-version="3.0.0", org.eclipse.jface, - org.eclipse.emf.compare.ide.ui.tests.framework + org.eclipse.emf.compare.ide.ui.tests.framework, + org.eclipse.ui.workbench Bundle-RequiredExecutionEnvironment: JavaSE-1.7 Bundle-Vendor: %providerName Import-Package: com.google.common.base;version="[11.0.0,16.0.0)", diff --git a/plugins/org.eclipse.emf.compare.rcp.ui.tests/src/org/eclipse/emf/compare/rcp/ui/tests/match/RCPMatchEngineFactoryRegistryTest.java b/plugins/org.eclipse.emf.compare.rcp.ui.tests/src/org/eclipse/emf/compare/rcp/ui/tests/match/RCPMatchEngineFactoryRegistryTest.java index d4d4dc595..4c9368e00 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui.tests/src/org/eclipse/emf/compare/rcp/ui/tests/match/RCPMatchEngineFactoryRegistryTest.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui.tests/src/org/eclipse/emf/compare/rcp/ui/tests/match/RCPMatchEngineFactoryRegistryTest.java @@ -17,14 +17,12 @@ import static org.junit.Assert.assertNull; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; -import com.google.common.base.Joiner; -import com.google.common.collect.Lists; - import java.io.IOException; import java.util.Collection; import java.util.Collections; import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.EMFCompare; import org.eclipse.emf.compare.match.IMatchEngine; import org.eclipse.emf.compare.match.IMatchEngine.Factory; @@ -38,11 +36,15 @@ import org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePreferences; import org.eclipse.emf.compare.rcp.ui.tests.match.data.EcoreInputData; import org.eclipse.emf.compare.scope.DefaultComparisonScope; import org.eclipse.emf.compare.scope.IComparisonScope; +import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.osgi.service.prefs.BackingStoreException; +import com.google.common.base.Joiner; +import com.google.common.collect.Lists; + /** * Test class for {@link MatchEngineFactoryRegistryWrapper}. * @@ -53,7 +55,7 @@ public class RCPMatchEngineFactoryRegistryTest { private IMatchEngine.Factory.Registry registryWrapper; - private IEclipsePreferences preferences; + private ScopedPreferenceStore preferenceStore; /** * Creates a comparison scope from Ecore model. @@ -68,13 +70,15 @@ public class RCPMatchEngineFactoryRegistryTest { @Before public void setUp() throws BackingStoreException { - preferences = EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(); + preferenceStore = new ScopedPreferenceStore(InstanceScope.INSTANCE, EMFCompareRCPPlugin.PLUGIN_ID); registryWrapper = EMFCompareRCPPlugin.getDefault().getMatchEngineFactoryRegistry(); } @After public void tearDown() throws BackingStoreException { - preferences.clear(); + for (IEclipsePreferences prefs : preferenceStore.getPreferenceNodes(false)) { + prefs.clear(); + } } /** @@ -258,12 +262,12 @@ public class RCPMatchEngineFactoryRegistryTest { IComparisonScope scope = createComparisonScope(); assertSame(registryWrapper.getHighestRankingMatchEngineFactory(scope), factory3); - disableEngine(preferences, EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, + disableEngine(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, Collections.singleton(factory3.getClass().getName())); assertSame(registryWrapper.getHighestRankingMatchEngineFactory(scope), factory2); assertTrue(!registryWrapper.getMatchEngineFactories(scope).contains(factory3)); - disableEngine(preferences, EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, + disableEngine(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, Lists.newArrayList(factory3.getClass().getName(), factory2.getClass().getName())); assertSame(registryWrapper.getHighestRankingMatchEngineFactory(scope), factory); assertTrue(!registryWrapper.getMatchEngineFactories(scope).contains(factory2)); @@ -303,18 +307,16 @@ public class RCPMatchEngineFactoryRegistryTest { /** * Disables engine in preferences. * - * @param preference - * {@link IEclipsePreferences} * @param key * @param toDisable * {@link Collection} of {@link IItemDescriptor} to disable. */ - private void disableEngine(IEclipsePreferences preference, String key, Collection<String> toDisable) { + private void disableEngine(String key, Collection<String> toDisable) { if (toDisable != null && !toDisable.isEmpty()) { String newPreferenceValue = Joiner.on(ItemUtil.PREFERENCE_DELIMITER).join(toDisable); - preference.put(key, newPreferenceValue); + preferenceStore.setValue(key, newPreferenceValue); } else { - preference.remove(key); + preferenceStore.setToDefault(key); } } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/EMFCompareRCPUIPlugin.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/EMFCompareRCPUIPlugin.java index 49f3a8c96..bbfef3e6d 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/EMFCompareRCPUIPlugin.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/EMFCompareRCPUIPlugin.java @@ -1,5 +1,5 @@ /****************************************************************************** - * Copyright (c) 2012, 2015 Obeo. + * Copyright (c) 2012, 2016 Obeo 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 @@ -7,6 +7,7 @@ * * Contributors: * Obeo - initial API and implementation + * Mathias Schaefer - preferences refactoring *******************************************************************************/ package org.eclipse.emf.compare.rcp.ui; @@ -19,6 +20,9 @@ import org.eclipse.core.runtime.IExtensionRegistry; import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Status; +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.DefaultScope; +import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; import org.eclipse.emf.compare.rcp.extension.AbstractRegistryEventListener; @@ -42,11 +46,12 @@ import org.eclipse.emf.compare.rcp.ui.internal.structuremergeviewer.groups.impl. import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter; import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.IDifferenceGroupProvider; import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.extender.IDifferenceGroupExtender; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.resource.ImageDescriptor; import org.eclipse.swt.graphics.Image; import org.eclipse.ui.plugin.AbstractUIPlugin; +import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.osgi.framework.BundleContext; -import org.osgi.service.prefs.Preferences; /** * The activator class controls the plug-in life cycle. @@ -118,17 +123,6 @@ public class EMFCompareRCPUIPlugin extends AbstractUIPlugin { private ContentMergeViewerCustomizationRegistry contentMergeViewerCustomizationRegistry; /** - * Instance scope for preferences. - * <p> - * Do not use singleton to respect Helios compatibility - * </p> - * - * @see org.eclipse.core.runtime.preferences.InstanceScope#INSTANCE - */ - @SuppressWarnings("deprecation") - private InstanceScope instanceScope = new InstanceScope(); - - /** * The constructor. */ public EMFCompareRCPUIPlugin() { @@ -147,8 +141,8 @@ public class EMFCompareRCPUIPlugin extends AbstractUIPlugin { IExtensionRegistry extensionRegistry = Platform.getExtensionRegistry(); groupItemRegistry = new ItemRegistry<IDifferenceGroupProvider.Descriptor>(); - DifferenceGroupManager groupManager = new DifferenceGroupManager(getEMFCompareUIPreferences(), - groupItemRegistry); + DifferenceGroupManager groupManager = new DifferenceGroupManager(groupItemRegistry, + getPreferenceStore()); groupProviderRegistry = new DifferenceGroupRegistryImpl(groupManager, groupItemRegistry); groupProviderRegistryListener = new DifferenceGroupProviderExtensionRegistryListener(PLUGIN_ID, GROUP_PROVIDER_PPID, getLog(), groupItemRegistry); @@ -156,7 +150,7 @@ public class EMFCompareRCPUIPlugin extends AbstractUIPlugin { extensionRegistry.addListener(groupProviderRegistryListener, PLUGIN_ID + "." + GROUP_PROVIDER_PPID); //$NON-NLS-1$ groupProviderRegistryListener.readRegistry(extensionRegistry); - filterManager = new DifferenceFilterManager(getEMFCompareUIPreferences()); + filterManager = new DifferenceFilterManager(getPreferenceStore()); filterRegistry = new DifferenceFilterRegistryImpl(filterManager); filterRegistryListener = new DifferenceFilterExtensionRegistryListener(PLUGIN_ID, FILTER_PROVIDER_PPID, getLog(), filterManager); @@ -384,9 +378,13 @@ public class EMFCompareRCPUIPlugin extends AbstractUIPlugin { } /** - * @return the preferences related to EMF Compare RCP UI plugin. + * Provide this plug-in's preference store, which searches values in {@link InstanceScope}, then + * {@link ConfigurationScope}, and then {@link DefaultScope}. */ - public Preferences getEMFCompareUIPreferences() { - return instanceScope.getNode(PLUGIN_ID); + @Override + public IPreferenceStore getPreferenceStore() { + ScopedPreferenceStore store = (ScopedPreferenceStore)super.getPreferenceStore(); + store.setSearchContexts(new IScopeContext[] {InstanceScope.INSTANCE, ConfigurationScope.INSTANCE }); + return store; } } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/AbstractConfigurationUI.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/AbstractConfigurationUI.java index 159e7058a..f08b0eb26 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/AbstractConfigurationUI.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/AbstractConfigurationUI.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Obeo. + * Copyright (c) 2014, 2017 Obeo. * 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 @@ -10,6 +10,9 @@ *******************************************************************************/ package org.eclipse.emf.compare.rcp.ui.internal.configuration.ui; +import static com.google.common.base.Preconditions.checkNotNull; + +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.widgets.Composite; import org.osgi.service.prefs.Preferences; @@ -20,9 +23,8 @@ import org.osgi.service.prefs.Preferences; * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a> */ public abstract class AbstractConfigurationUI extends Composite { - - /** {@link Preferences} holding the configuration. */ - private final Preferences pref; + /** The preference store. */ + private final IPreferenceStore store; /** * Constructor. @@ -31,22 +33,12 @@ public abstract class AbstractConfigurationUI extends Composite { * Parent {@link Composite}. * @param style * Style of this {@link Composite} - * @param pref - * {@link Preferences} holding the configuration reprenseted by this composite. + * @param store + * The {@link IPreferenceStore} to use for preferences, cannot be <code>null</code> */ - public AbstractConfigurationUI(Composite parent, int style, Preferences pref) { + public AbstractConfigurationUI(Composite parent, int style, IPreferenceStore store) { super(parent, style); - this.pref = pref; - - } - - /** - * {@link AbstractConfigurationUI#pref} - * - * @return - */ - protected Preferences getPreference() { - return pref; + this.store = checkNotNull(store); } /** @@ -65,4 +57,13 @@ public abstract class AbstractConfigurationUI extends Composite { */ public abstract void resetDefault(); + /** + * Get the preference store used by this object. + * + * @return The preference store used by this object. + */ + protected IPreferenceStore getPreferenceStore() { + return store; + } + } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/IConfigurationUIFactory.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/IConfigurationUIFactory.java index 71c61d1a7..3f0070681 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/IConfigurationUIFactory.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/IConfigurationUIFactory.java @@ -10,8 +10,8 @@ *******************************************************************************/ package org.eclipse.emf.compare.rcp.ui.internal.configuration.ui; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.widgets.Composite; -import org.osgi.service.prefs.Preferences; /** * Factory for {@link AbstractConfigurationUI}. @@ -27,10 +27,10 @@ public interface IConfigurationUIFactory { * Parent composite. * @param style * Style of the new {@link AbstractConfigurationUI} - * @param pref - * {@link Preferences} to store configuration. + * @param store + * {@link IPreferenceStore} to store configuration. * @return Configuration UI */ - AbstractConfigurationUI createUI(Composite parent, int style, Preferences pref); + AbstractConfigurationUI createUI(Composite parent, int style, IPreferenceStore store); } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/match/DefaultMatchEngineConfiguatorUIFactory.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/match/DefaultMatchEngineConfiguatorUIFactory.java index dc3edf4dd..66898f343 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/match/DefaultMatchEngineConfiguatorUIFactory.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/match/DefaultMatchEngineConfiguatorUIFactory.java @@ -13,8 +13,8 @@ package org.eclipse.emf.compare.rcp.ui.internal.configuration.ui.match; import org.eclipse.emf.compare.rcp.internal.match.DefaultRCPMatchEngineFactory; import org.eclipse.emf.compare.rcp.ui.internal.configuration.ui.AbstractConfigurationUI; import org.eclipse.emf.compare.rcp.ui.internal.configuration.ui.IConfigurationUIFactory; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.widgets.Composite; -import org.osgi.service.prefs.Preferences; /** * IConfiguratorUIFactory for {@link DefaultRCPMatchEngineFactory} @@ -23,12 +23,9 @@ import org.osgi.service.prefs.Preferences; */ public class DefaultMatchEngineConfiguatorUIFactory implements IConfigurationUIFactory { - /** - * {@inheritDoc} - */ - public AbstractConfigurationUI createUI(Composite parent, int style, Preferences pref) { + public AbstractConfigurationUI createUI(Composite parent, int style, IPreferenceStore store) { DefaultMatchEngineConfiguratorUI composite = new DefaultMatchEngineConfiguratorUI(parent, style, - pref); + store); composite.createContent(); return composite; } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/match/DefaultMatchEngineConfiguratorUI.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/match/DefaultMatchEngineConfiguratorUI.java index e5f4c480c..6c7683ea9 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/match/DefaultMatchEngineConfiguratorUI.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/configuration/ui/match/DefaultMatchEngineConfiguratorUI.java @@ -21,13 +21,13 @@ import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareRCPUIMessages; import org.eclipse.emf.compare.rcp.ui.internal.configuration.ui.AbstractConfigurationUI; import org.eclipse.emf.compare.utils.UseIdentifiers; import org.eclipse.jface.databinding.swt.SWTObservables; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.GridData; import org.eclipse.swt.layout.GridLayout; import org.eclipse.swt.widgets.Button; import org.eclipse.swt.widgets.Composite; import org.eclipse.swt.widgets.Label; -import org.osgi.service.prefs.Preferences; /** * {@link AbstractConfigurationUI} for {@link DefaultRCPMatchEngineFactory}. @@ -49,8 +49,8 @@ public class DefaultMatchEngineConfiguratorUI extends AbstractConfigurationUI { private DataHolder dataHolder; - public DefaultMatchEngineConfiguratorUI(Composite parent, int style, Preferences pref) { - super(parent, style, pref); + public DefaultMatchEngineConfiguratorUI(Composite parent, int style, IPreferenceStore store) { + super(parent, style, store); } @Override @@ -80,7 +80,7 @@ public class DefaultMatchEngineConfiguratorUI extends AbstractConfigurationUI { neverButton .setText(EMFCompareRCPUIMessages.getString("DefaultMatchEngineConfiguratorUI.never.label")); //$NON-NLS-1$ - UseIdentifiers defaultValue = DefaultRCPMatchEngineFactory.getUseIdentifierValue(getPreference()); + UseIdentifiers defaultValue = DefaultRCPMatchEngineFactory.getUseIdentifierValue(); dataHolder = new DataHolder(defaultValue); bindData(); @@ -109,9 +109,9 @@ public class DefaultMatchEngineConfiguratorUI extends AbstractConfigurationUI { public void storeConfiguration() { UseIdentifiers value = dataHolder.getValue(); if (value != DefaultRCPMatchEngineFactory.DEFAULT_USE_IDENTIFIER_ATRIBUTE) { - getPreference().put(DefaultRCPMatchEngineFactory.USE_IDENTIFIER_ATTR, value.toString()); + getPreferenceStore().setValue(DefaultRCPMatchEngineFactory.USE_IDENTIFIER_ATTR, value.toString()); } else { - getPreference().remove(DefaultRCPMatchEngineFactory.USE_IDENTIFIER_ATTR); + getPreferenceStore().setToDefault(DefaultRCPMatchEngineFactory.USE_IDENTIFIER_ATTR); } } @@ -135,7 +135,7 @@ public class DefaultMatchEngineConfiguratorUI extends AbstractConfigurationUI { } dataHolder.setValue(DefaultRCPMatchEngineFactory.DEFAULT_USE_IDENTIFIER_ATRIBUTE); try { - getPreference().remove(DefaultRCPMatchEngineFactory.USE_IDENTIFIER_ATTR); + getPreferenceStore().setToDefault(DefaultRCPMatchEngineFactory.USE_IDENTIFIER_ATTR); } catch (IllegalStateException e) { Throwables.propagate(e); } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/AdapterFactoriesPreferencePage.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/AdapterFactoriesPreferencePage.java index fee8a93ce..fcb60c2df 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/AdapterFactoriesPreferencePage.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/AdapterFactoriesPreferencePage.java @@ -23,6 +23,8 @@ import java.util.Collections; import java.util.Comparator; import java.util.List; +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.internal.adapterfactory.RankedAdapterFactoryDescriptor; import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; @@ -69,10 +71,9 @@ public class AdapterFactoriesPreferencePage extends PreferencePage implements IW private CheckboxTableViewer adapterFactoryDescriptorViewer; public void init(IWorkbench workbench) { - // Do not use InstanceScope.Instance to be compatible with Helios. - @SuppressWarnings("deprecation") - ScopedPreferenceStore store = new ScopedPreferenceStore(new InstanceScope(), + ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, EMFCompareRCPPlugin.PLUGIN_ID); + store.setSearchContexts(new IScopeContext[] {InstanceScope.INSTANCE, ConfigurationScope.INSTANCE }); setPreferenceStore(store); } @@ -109,8 +110,7 @@ public class AdapterFactoriesPreferencePage extends PreferencePage implements IW adapterFactoryDescriptorViewer.setSelection(new StructuredSelection(descriptors.get(0)), true); } - List<String> disabledDescriptors = EMFComparePreferences.getDisabledAdapterFacotryDescriptorIds( - EMFCompareRCPPlugin.getDefault().getEMFComparePreferences()); + List<String> disabledDescriptors = EMFComparePreferences.getDisabledAdapterFactoryDescriptorIds(); initViewer(disabledDescriptors); } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/EditorPreferencePage.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/EditorPreferencePage.java index fa95fc859..61341f0d4 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/EditorPreferencePage.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/EditorPreferencePage.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014 Obeo. + * Copyright (c) 2014, 2016 Obeo 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 @@ -7,9 +7,11 @@ * * Contributors: * Obeo - initial API and implementation + * Mathias Schaefer - preferences refactoring *******************************************************************************/ package org.eclipse.emf.compare.rcp.ui.internal.preferences; +import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin; import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareRCPUIMessages; import org.eclipse.emf.compare.rcp.ui.internal.mergeviewer.CompareColorImpl; import org.eclipse.jface.layout.GridLayoutFactory; @@ -43,7 +45,7 @@ public class EditorPreferencePage extends PreferencePage implements IWorkbenchPr } public void init(IWorkbench workbench) { - + setPreferenceStore(EMFCompareRCPUIPlugin.getDefault().getPreferenceStore()); } @Override diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/EnginesPreferencePage.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/EnginesPreferencePage.java index dce91d0b4..e7e220e74 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/EnginesPreferencePage.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/EnginesPreferencePage.java @@ -22,7 +22,8 @@ import java.util.Map.Entry; import java.util.Set; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.conflict.IConflictDetector; import org.eclipse.emf.compare.diff.IDiffEngine; @@ -43,8 +44,12 @@ import org.eclipse.emf.compare.rcp.ui.internal.configuration.ui.IConfigurationUI import org.eclipse.emf.compare.rcp.ui.internal.preferences.impl.InteractiveUIContent; import org.eclipse.emf.compare.rcp.ui.internal.preferences.impl.InteractiveUIContent.InteractiveUIBuilder; import org.eclipse.emf.compare.req.IReqEngine; +import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.preference.PreferencePage; import org.eclipse.jface.resource.ImageDescriptor; +import org.eclipse.jface.viewers.CheckStateChangedEvent; +import org.eclipse.jface.viewers.CheckboxTableViewer; +import org.eclipse.jface.viewers.ICheckStateListener; import org.eclipse.swt.SWT; import org.eclipse.swt.layout.FillLayout; import org.eclipse.swt.layout.GridData; @@ -57,8 +62,6 @@ import org.eclipse.swt.widgets.TabItem; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; import org.eclipse.ui.preferences.ScopedPreferenceStore; -import org.osgi.service.prefs.BackingStoreException; -import org.osgi.service.prefs.Preferences; /** * Preference page for engines preferences @@ -98,10 +101,9 @@ public class EnginesPreferencePage extends PreferencePage implements IWorkbenchP } public void init(IWorkbench workbench) { - // Do not use InstanceScope.Instance to be compatible with Helios. - @SuppressWarnings("deprecation") - ScopedPreferenceStore store = new ScopedPreferenceStore(new InstanceScope(), + ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, EMFCompareRCPPlugin.PLUGIN_ID); + store.setSearchContexts(new IScopeContext[] {InstanceScope.INSTANCE, ConfigurationScope.INSTANCE }); setPreferenceStore(store); } @@ -133,8 +135,6 @@ public class EnginesPreferencePage extends PreferencePage implements IWorkbenchP * Registry holding engines. * @param enginePreferenceKey * Preference key use to store preferences - * @param pref - * {@link IEclipsePreferences} holding preferences. * @param tabComposite * Holding composite. * @param dataHolder @@ -144,10 +144,8 @@ public class EnginesPreferencePage extends PreferencePage implements IWorkbenchP * @return {@link InteractiveUIContent} for a specific type of engine. */ private <T> InteractiveUIContent createEngineUIBuilder(IItemRegistry<T> registry, - String enginePreferenceKey, IEclipsePreferences pref, Composite tabComposite, - DataHolder<T> dataHolder) { - IItemDescriptor<T> defaultEngine = ItemUtil.getDefaultItemDescriptor(registry, enginePreferenceKey, - pref); + String enginePreferenceKey, Composite tabComposite, DataHolder<T> dataHolder) { + IItemDescriptor<T> defaultEngine = ItemUtil.getDefaultItemDescriptor(registry, enginePreferenceKey); InteractiveUIBuilder<T> uiBuilder = new InteractiveUIBuilder<T>(tabComposite, registry); uiBuilder.setSimple(true).setDefaultCheck(Collections.singleton(defaultEngine)) .setDefaultSelection(defaultEngine).setHoldingData(dataHolder); @@ -162,15 +160,14 @@ public class EnginesPreferencePage extends PreferencePage implements IWorkbenchP private void createConflictDetectorTab(TabFolder tabFolder) { IItemRegistry<IConflictDetector> conflictDetectorDescriptorRegistry = EMFCompareRCPPlugin.getDefault() .getConflictDetectorDescriptorRegistry(); + // Create tab structure Composite tabComposite = createTabSkeleton(tabFolder, EMFCompareRCPUIMessages.getString("EnginesPreferencePage.conflictDetector.tab.label"), //$NON-NLS-1$ EMFCompareRCPUIMessages.getString("EnginesPreferencePage.conflictDetectorIntro.text"));//$NON-NLS-1$ InteractiveUIContent interactiveContent = createEngineUIBuilder(conflictDetectorDescriptorRegistry, - EMFComparePreferences.CONFLICTS_DETECTOR, - EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(), tabComposite, - conflictsDetectorData); + EMFComparePreferences.CONFLICTS_DETECTOR, tabComposite, conflictsDetectorData); // Save for reset default interactiveUis.put(EMFComparePreferences.CONFLICTS_DETECTOR, interactiveContent); @@ -190,8 +187,7 @@ public class EnginesPreferencePage extends PreferencePage implements IWorkbenchP EMFCompareRCPUIMessages.getString("EnginesPreferencePage.reqEngineIntro.text")); //$NON-NLS-1$ InteractiveUIContent interactiveContent = createEngineUIBuilder(reqEngineDescriptorRegistry, - EMFComparePreferences.REQ_ENGINES, - EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(), tabComposite, reqEngineData); + EMFComparePreferences.REQ_ENGINES, tabComposite, reqEngineData); // Save for reset default interactiveUis.put(EMFComparePreferences.REQ_ENGINES, interactiveContent); @@ -211,8 +207,7 @@ public class EnginesPreferencePage extends PreferencePage implements IWorkbenchP EMFCompareRCPUIMessages.getString("EnginesPreferencePage.equiEngineIntro.text")); //$NON-NLS-1$ InteractiveUIContent interactiveContent = createEngineUIBuilder(equiEngineDescriptorRegistry, - EMFComparePreferences.EQUI_ENGINES, - EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(), tabComposite, equiEngineData); + EMFComparePreferences.EQUI_ENGINES, tabComposite, equiEngineData); // Save for reset default interactiveUis.put(EMFComparePreferences.EQUI_ENGINES, interactiveContent); @@ -232,8 +227,7 @@ public class EnginesPreferencePage extends PreferencePage implements IWorkbenchP EMFCompareRCPUIMessages.getString("EnginesPreferencePage.diffEngineIntro.text")); //$NON-NLS-1$ InteractiveUIContent interactiveContent = createEngineUIBuilder(diffEngineDescriptorRegistry, - EMFComparePreferences.DIFF_ENGINES, - EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(), tabComposite, diffEngineData); + EMFComparePreferences.DIFF_ENGINES, tabComposite, diffEngineData); // Save for reset default interactiveUis.put(EMFComparePreferences.DIFF_ENGINES, interactiveContent); @@ -258,17 +252,36 @@ public class EnginesPreferencePage extends PreferencePage implements IWorkbenchP .getMatchEngineConfiguratorRegistry(); String matchEnginePreferenceKey = EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES; - Set<IItemDescriptor<Factory>> activeItems = ItemUtil - .getActiveItems(matchEngineFactoryDescriptorRegistry, matchEnginePreferenceKey); + Set<IItemDescriptor<Factory>> activeItems = ItemUtil.getActiveItems( + matchEngineFactoryDescriptorRegistry, EMFCompareRCPPlugin.PLUGIN_ID, + matchEnginePreferenceKey); InteractiveUIBuilder<IMatchEngine.Factory> builder = new InteractiveUIBuilder<IMatchEngine.Factory>( tabComposite, matchEngineFactoryDescriptorRegistry); builder.setConfiguratorUIRegistry(configuratorUIRegistry).setDefaultCheck(activeItems) - .setConfigurationNodeKey(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES) + .setConfigurationNodeKey(matchEnginePreferenceKey) .setDefaultSelection(defaultMatchEngineDescriptor).setHoldingData(matchEnginesData); - // Save for reset default - interactiveUis.put(matchEnginePreferenceKey, builder.build()); + // Forbid unchecking all match engines + InteractiveUIContent uiContent = builder.build(); + uiContent.getViewer().addCheckStateListener(new ICheckStateListener() { + public void checkStateChanged(CheckStateChangedEvent event) { + Object element = event.getElement(); + if (!event.getChecked()) { + // Prevent from nothing checked + if (((CheckboxTableViewer)event.getSource()).getCheckedElements().length == 0) { + ((CheckboxTableViewer)event.getSource()).setCheckedElements(new Object[] {element }); + MessageDialog.openWarning(getShell(), + EMFCompareRCPUIMessages + .getString("InteractiveUIContent.incorrectSelection.title"), //$NON-NLS-1$ + EMFCompareRCPUIMessages + .getString("InteractiveUIContent.incorrectSelection.message")); //$NON-NLS-1$ + } + } + } + }); + // Save for reset default + interactiveUis.put(matchEnginePreferenceKey, uiContent); } /** @@ -296,34 +309,8 @@ public class EnginesPreferencePage extends PreferencePage implements IWorkbenchP @Override public boolean performOk() { - setEnginesPreferences(); - storeConfigurations(); - - if (TracingConstant.CONFIGURATION_TRACING_ACTIVATED) { - StringBuilder traceMessage = new StringBuilder("Engines preference serialization:\n"); //$NON-NLS-1$ - String prefDelimiter = " :\n"; //$NON-NLS-1$ - String newLine = "\n"; //$NON-NLS-1$ - traceMessage.append(EMFComparePreferences.DIFF_ENGINES).append(prefDelimiter) - .append(getPreferenceStore().getString(EMFComparePreferences.DIFF_ENGINES)) - .append(newLine); - traceMessage.append(EMFComparePreferences.EQUI_ENGINES).append(prefDelimiter) - .append(getPreferenceStore().getString(EMFComparePreferences.EQUI_ENGINES)) - .append(newLine); - traceMessage.append(EMFComparePreferences.REQ_ENGINES).append(prefDelimiter) - .append(getPreferenceStore().getString(EMFComparePreferences.REQ_ENGINES)) - .append(newLine); - traceMessage.append(EMFComparePreferences.CONFLICTS_DETECTOR).append(prefDelimiter) - .append(getPreferenceStore().getString(EMFComparePreferences.CONFLICTS_DETECTOR)) - .append(newLine); - traceMessage.append(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES).append(prefDelimiter) - .append(getPreferenceStore() - .getString(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES)) - .append(newLine); - - EMFCompareRCPPlugin.getDefault().log(IStatus.INFO, traceMessage.toString()); - } return super.performOk(); } @@ -364,37 +351,29 @@ public class EnginesPreferencePage extends PreferencePage implements IWorkbenchP configurator.storeConfiguration(); } } - if (TracingConstant.CONFIGURATION_TRACING_ACTIVATED) { - StringBuilder traceMessage = new StringBuilder("Configuration serialization:\n"); //$NON-NLS-1$ + StringBuilder traceMessage = new StringBuilder("Engines preference serialization:\n"); //$NON-NLS-1$ String prefDelimiter = " :\n"; //$NON-NLS-1$ String newLine = "\n"; //$NON-NLS-1$ - String nodeLabel = "Node "; //$NON-NLS-1$ - String doubleDotLabel = " : "; //$NON-NLS-1$ - String emptyLabel = "EMPTY"; //$NON-NLS-1$ - for (Entry<String, InteractiveUIContent> interactiveContentEntry : interactiveUis.entrySet()) { - String itemTypeId = interactiveContentEntry.getKey(); - for (Entry<String, AbstractConfigurationUI> configuratorEntry : interactiveContentEntry - .getValue().getConfigurators().entrySet()) { - String itemToConfigureId = configuratorEntry.getKey(); - Preferences storeNode = ItemUtil.getConfigurationPreferenceNode(itemTypeId, - itemToConfigureId); - traceMessage.append(nodeLabel).append(storeNode.absolutePath()).append(prefDelimiter); - try { - for (String propertyKey : storeNode.keys()) { - traceMessage.append(propertyKey).append(doubleDotLabel) - .append(storeNode.get(propertyKey, emptyLabel)).append(newLine); - } - } catch (BackingStoreException e) { - e.printStackTrace(); - traceMessage.append("Error in tracing ").append(storeNode.absolutePath()); //$NON-NLS-1$ - } - } - } + traceMessage.append(EMFComparePreferences.DIFF_ENGINES).append(prefDelimiter) + .append(getPreferenceStore().getString(EMFComparePreferences.DIFF_ENGINES)) + .append(newLine); + traceMessage.append(EMFComparePreferences.EQUI_ENGINES).append(prefDelimiter) + .append(getPreferenceStore().getString(EMFComparePreferences.EQUI_ENGINES)) + .append(newLine); + traceMessage.append(EMFComparePreferences.REQ_ENGINES).append(prefDelimiter) + .append(getPreferenceStore().getString(EMFComparePreferences.REQ_ENGINES)) + .append(newLine); + traceMessage.append(EMFComparePreferences.CONFLICTS_DETECTOR).append(prefDelimiter) + .append(getPreferenceStore().getString(EMFComparePreferences.CONFLICTS_DETECTOR)) + .append(newLine); + traceMessage.append(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES).append(prefDelimiter) + .append(getPreferenceStore() + .getString(EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES)) + .append(newLine); EMFCompareRCPPlugin.getDefault().log(IStatus.INFO, traceMessage.toString()); } - } @Override diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/FiltersPreferencePage.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/FiltersPreferencePage.java index c38167856..b94a8d872 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/FiltersPreferencePage.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/FiltersPreferencePage.java @@ -30,7 +30,6 @@ import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.beans.PojoProperties; import org.eclipse.core.databinding.observable.set.IObservableSet; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.rcp.internal.extension.IItemDescriptor; import org.eclipse.emf.compare.rcp.internal.tracer.TracingConstant; import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin; @@ -66,7 +65,6 @@ import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.preferences.ScopedPreferenceStore; /** * Preference page for {@link IDifferenceFilter}. @@ -109,12 +107,7 @@ public class FiltersPreferencePage extends PreferencePage implements IWorkbenchP private String synchronizationBehaviorValue; public void init(IWorkbench workbench) { - // Do not use InstanceScope.Instance to be compatible with Helios. - @SuppressWarnings("deprecation") - ScopedPreferenceStore store = new ScopedPreferenceStore(new InstanceScope(), - EMFCompareRCPUIPlugin.PLUGIN_ID); - setPreferenceStore(store); - + setPreferenceStore(EMFCompareRCPUIPlugin.getDefault().getPreferenceStore()); } @Override diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/GroupsPreferencePage.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/GroupsPreferencePage.java index e4fa48457..408fae996 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/GroupsPreferencePage.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/GroupsPreferencePage.java @@ -21,7 +21,6 @@ import com.google.common.collect.ImmutableList; import java.util.List; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.rcp.internal.extension.IItemDescriptor; import org.eclipse.emf.compare.rcp.internal.tracer.TracingConstant; import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin; @@ -49,7 +48,6 @@ import org.eclipse.swt.widgets.TabFolder; import org.eclipse.swt.widgets.TabItem; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; -import org.eclipse.ui.preferences.ScopedPreferenceStore; /** * Preference page for group providers. @@ -87,8 +85,8 @@ public class GroupsPreferencePage extends PreferencePage implements IWorkbenchPr /** {@link DifferenceGroupManager}. */ private DifferenceGroupManager groupManager = new DifferenceGroupManager( - EMFCompareRCPUIPlugin.getDefault().getEMFCompareUIPreferences(), - EMFCompareRCPUIPlugin.getDefault().getItemDifferenceGroupProviderRegistry()); + EMFCompareRCPUIPlugin.getDefault().getItemDifferenceGroupProviderRegistry(), + EMFCompareRCPUIPlugin.getDefault().getPreferenceStore()); /** * Gets the preference key for synchronization behavior. @@ -105,16 +103,8 @@ public class GroupsPreferencePage extends PreferencePage implements IWorkbenchPr } } - /** - * {@inheritDoc} - */ public void init(IWorkbench workbench) { - // Do not use InstanceScope.Instance to be compatible with Helios. - @SuppressWarnings("deprecation") - ScopedPreferenceStore store = new ScopedPreferenceStore(new InstanceScope(), - EMFCompareRCPUIPlugin.PLUGIN_ID); - setPreferenceStore(store); - + setPreferenceStore(EMFCompareRCPUIPlugin.getDefault().getPreferenceStore()); } @Override diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/LoggingPreferencePage.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/LoggingPreferencePage.java index 33237038b..b9c6d8b50 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/LoggingPreferencePage.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/LoggingPreferencePage.java @@ -8,6 +8,7 @@ * Contributors: * Obeo - initial API and implementation * Simon Delisle - bug 495753 + * Mathias Schaefer - preferences refactoring *******************************************************************************/ package org.eclipse.emf.compare.rcp.ui.internal.preferences; @@ -21,9 +22,14 @@ import static org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePrefere import static org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePreferences.LOG_LEVEL_KEY; import java.io.File; +import java.io.IOException; import java.util.Arrays; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.Platform; +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IPreferencesService; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareRCPUIMessages; import org.eclipse.jface.layout.GridLayoutFactory; @@ -44,6 +50,7 @@ import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPreferencePage; +import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.osgi.service.prefs.BackingStoreException; /** @@ -96,7 +103,10 @@ public class LoggingPreferencePage extends PreferencePage implements IWorkbenchP * {@inheritDoc} */ public void init(IWorkbench workbench) { - // Nothing to do + ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, + EMFCompareRCPPlugin.PLUGIN_ID); + store.setSearchContexts(new IScopeContext[] {InstanceScope.INSTANCE, ConfigurationScope.INSTANCE }); + setPreferenceStore(store); } @Override @@ -153,30 +163,31 @@ public class LoggingPreferencePage extends PreferencePage implements IWorkbenchP return gd; } - protected void savePreferences() throws BackingStoreException { - IEclipsePreferences prefs = EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(); - prefs.put(LOG_FILENAME_KEY, fileField.getText()); + protected void savePreferences() throws BackingStoreException, IOException { + getPreferenceStore().setValue(LOG_FILENAME_KEY, fileField.getText()); String item = levelCombo.getItem(levelCombo.getSelectionIndex()); - prefs.put(LOG_LEVEL_KEY, item); - prefs.put(LOG_BACKUP_COUNT_KEY, maxBackupField.getText()); - prefs.put(LOG_FILE_MAX_SIZE_KEY, maxSizeField.getText()); - prefs.flush(); + getPreferenceStore().setValue(LOG_LEVEL_KEY, item); + getPreferenceStore().setValue(LOG_BACKUP_COUNT_KEY, maxBackupField.getText()); + getPreferenceStore().setValue(LOG_FILE_MAX_SIZE_KEY, maxSizeField.getText()); } protected void resetPreferences() { - IEclipsePreferences prefs = EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(); - prefs.put(LOG_FILENAME_KEY, ""); //$NON-NLS-1$ - prefs.put(LOG_LEVEL_KEY, "OFF"); //$NON-NLS-1$ - prefs.putInt(LOG_BACKUP_COUNT_KEY, LOG_BACKUP_DEFAULT); - prefs.putInt(LOG_FILE_MAX_SIZE_KEY, LOG_FILE_SIZE_DEFAULT); + getPreferenceStore().setToDefault(LOG_FILENAME_KEY); + getPreferenceStore().setToDefault(LOG_LEVEL_KEY); + getPreferenceStore().setToDefault(LOG_BACKUP_COUNT_KEY); + getPreferenceStore().setToDefault(LOG_FILE_MAX_SIZE_KEY); } protected void refreshWidgets() { - IEclipsePreferences prefs = EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(); - String fileName = prefs.get(LOG_FILENAME_KEY, LOG_FILE_DEFAULT); - String level = prefs.get(LOG_LEVEL_KEY, LOG_LEVEL_DEFAULT); - int maxBackupCount = prefs.getInt(LOG_BACKUP_COUNT_KEY, LOG_BACKUP_DEFAULT); - int maxSizeInMB = prefs.getInt(LOG_FILE_MAX_SIZE_KEY, LOG_FILE_SIZE_DEFAULT); + IPreferencesService prefsService = Platform.getPreferencesService(); + String fileName = prefsService.getString(EMFCompareRCPPlugin.PLUGIN_ID, LOG_FILENAME_KEY, + LOG_FILE_DEFAULT, null); + String level = prefsService.getString(EMFCompareRCPPlugin.PLUGIN_ID, LOG_LEVEL_KEY, LOG_LEVEL_DEFAULT, + null); + int maxBackupCount = prefsService.getInt(EMFCompareRCPPlugin.PLUGIN_ID, LOG_BACKUP_COUNT_KEY, + LOG_BACKUP_DEFAULT, null); + int maxSizeInMB = prefsService.getInt(EMFCompareRCPPlugin.PLUGIN_ID, LOG_FILE_MAX_SIZE_KEY, + LOG_FILE_SIZE_DEFAULT, null); levelCombo.select(Arrays.asList(LOG_LEVELS).indexOf(level)); levelCombo.pack(); fileField.setText(fileName); @@ -190,7 +201,7 @@ public class LoggingPreferencePage extends PreferencePage implements IWorkbenchP savePreferences(); refreshWidgets(); return super.performOk(); - } catch (BackingStoreException e) { + } catch (IOException | BackingStoreException e) { return false; } } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/PostProcessorPreferencePage.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/PostProcessorPreferencePage.java index 19ebe1dc5..2a74ea95f 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/PostProcessorPreferencePage.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/PostProcessorPreferencePage.java @@ -19,6 +19,8 @@ import com.google.common.collect.Sets.SetView; import java.util.Set; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IScopeContext; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.postprocessor.IPostProcessor; import org.eclipse.emf.compare.postprocessor.IPostProcessor.Descriptor; @@ -88,10 +90,9 @@ public class PostProcessorPreferencePage extends PreferencePage implements IWork * {@inheritDoc} */ public void init(IWorkbench workbench) { - // Do not use InstanceScope.Instance to be compatible with Helios. - @SuppressWarnings("deprecation") - ScopedPreferenceStore store = new ScopedPreferenceStore(new InstanceScope(), + ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, EMFCompareRCPPlugin.PLUGIN_ID); + store.setSearchContexts(new IScopeContext[] {InstanceScope.INSTANCE, ConfigurationScope.INSTANCE }); setPreferenceStore(store); } @@ -107,7 +108,8 @@ public class PostProcessorPreferencePage extends PreferencePage implements IWork IItemRegistry<IPostProcessor.Descriptor> postProcessorRegistryDescriptor = EMFCompareRCPPlugin .getDefault().getPostProcessorDescriptorRegistry(); Set<IItemDescriptor<Descriptor>> activesPostProcessor = ItemUtil.getActiveItems( - postProcessorRegistryDescriptor, EMFComparePreferences.DISABLED_POST_PROCESSOR); + postProcessorRegistryDescriptor, EMFCompareRCPPlugin.PLUGIN_ID, + EMFComparePreferences.DISABLED_POST_PROCESSOR); InteractiveUIBuilder<Descriptor> postProcessorUIBuilder = new InteractiveUIBuilder<IPostProcessor.Descriptor>( container, postProcessorRegistryDescriptor); Set<IItemDescriptor<Descriptor>> descriptors = Sets diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/impl/InteractiveUIContent.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/impl/InteractiveUIContent.java index dfd4e44f8..d9eb047b9 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/impl/InteractiveUIContent.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/preferences/impl/InteractiveUIContent.java @@ -23,6 +23,10 @@ import java.util.Set; import org.eclipse.core.databinding.DataBindingContext; import org.eclipse.core.databinding.beans.PojoProperties; import org.eclipse.core.databinding.observable.set.IObservableSet; +import org.eclipse.core.runtime.preferences.ConfigurationScope; +import org.eclipse.core.runtime.preferences.IScopeContext; +import org.eclipse.core.runtime.preferences.InstanceScope; +import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; import org.eclipse.emf.compare.rcp.internal.extension.IItemDescriptor; import org.eclipse.emf.compare.rcp.internal.extension.IItemRegistry; import org.eclipse.emf.compare.rcp.internal.extension.impl.ItemUtil; @@ -34,6 +38,7 @@ import org.eclipse.jface.databinding.viewers.IViewerObservableSet; import org.eclipse.jface.databinding.viewers.ViewersObservables; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.jface.layout.GridLayoutFactory; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.jface.viewers.ArrayContentProvider; import org.eclipse.jface.viewers.CheckStateChangedEvent; import org.eclipse.jface.viewers.CheckboxTableViewer; @@ -53,6 +58,7 @@ import org.eclipse.swt.widgets.Display; import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Shell; +import org.eclipse.ui.preferences.ScopedPreferenceStore; import org.osgi.service.prefs.Preferences; /** @@ -157,12 +163,13 @@ public final class InteractiveUIContent { * Id of the item to configure * @param configuratorfactory * Factory for the configuration - * @param pref + * @param store * Preference store that will hold this {@link IConfigurationUIFactory} value. */ - public void addConfigurator(String id, IConfigurationUIFactory configuratorfactory, Preferences pref) { + public void addConfigurator(String id, IConfigurationUIFactory configuratorfactory, + IPreferenceStore store) { AbstractConfigurationUI configurator = configuratorfactory.createUI(configurationComposite, SWT.NONE, - pref); + store); configurators.put(id, configurator); } @@ -241,7 +248,7 @@ public final class InteractiveUIContent { * * @return The viewer. */ - private CheckboxTableViewer getViewer() { + public CheckboxTableViewer getViewer() { return viewer; } @@ -619,8 +626,13 @@ public final class InteractiveUIContent { String itemId = item.getID(); IConfigurationUIFactory configuratorFactory = configurationUIRegistry.get(itemId); if (configuratorFactory != null) { - Preferences pref = ItemUtil.getConfigurationPreferenceNode(configurationNodeKey, itemId); - interactiveUI.addConfigurator(itemId, configuratorFactory, pref); + // Preferences pref = ItemUtil.getConfigurationPreferenceNode(configurationNodeKey, + // itemId); + ScopedPreferenceStore store = new ScopedPreferenceStore(InstanceScope.INSTANCE, + EMFCompareRCPPlugin.PLUGIN_ID); + store.setSearchContexts( + new IScopeContext[] {InstanceScope.INSTANCE, ConfigurationScope.INSTANCE }); + interactiveUI.addConfigurator(itemId, configuratorFactory, store); } } } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/FilterAction.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/FilterAction.java index 1fba012c5..c1a4afe5e 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/FilterAction.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/FilterAction.java @@ -14,7 +14,6 @@ import com.google.common.collect.Sets; import java.util.Set; -import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin; import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareRCPUIMessages; import org.eclipse.emf.compare.rcp.ui.internal.preferences.FiltersPreferencePage; @@ -26,10 +25,9 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.preferences.ScopedPreferenceStore; -import org.osgi.service.prefs.Preferences; /** * These will be the actual actions displayed in the filter menu. Their sole purpose is to provide a Predicate @@ -52,7 +50,7 @@ public class FilterAction extends Action { private final StructureMergeViewerFilter structureMergeViewerFilter; /** Preferences holding the value of the synchronization behavior of filters. */ - private final Preferences preferences; + private final IPreferenceStore preferences; /** {@link DifferenceFilterManager}. */ private final DifferenceFilterManager filterManager; @@ -72,7 +70,7 @@ public class FilterAction extends Action { super(text, IAction.AS_CHECK_BOX); this.structureMergeViewerFilter = structureMergeViewerFilter; this.filter = filter; - this.preferences = EMFCompareRCPUIPlugin.getDefault().getEMFCompareUIPreferences(); + this.preferences = EMFCompareRCPUIPlugin.getDefault().getPreferenceStore(); this.filterManager = EMFCompareRCPUIPlugin.getDefault().getDifferenceFilterManager(); } @@ -96,8 +94,10 @@ public class FilterAction extends Action { * Event. */ private void handleSynchronization(Event event) { - String sync = preferences.get(FiltersPreferencePage.SYNCHRONIZATION_BEHAVIOR, - MessageDialogWithToggle.PROMPT); + String sync = preferences.getString(FiltersPreferencePage.SYNCHRONIZATION_BEHAVIOR); + if ("".equals(sync)) { //$NON-NLS-1$ + sync = MessageDialogWithToggle.PROMPT; + } final Shell shell = event.display.getActiveShell(); if (MessageDialogWithToggle.PROMPT.equals(sync) && shell != null) { shell.getDisplay().asyncExec(new SynchronizationBehaviorRunnable(shell)); @@ -145,9 +145,8 @@ public class FilterAction extends Action { } /** - * {@inheritDoc} Does not use InstanceScope#Instance for compatibility issues with Helios. + * {@inheritDoc} */ - @SuppressWarnings("deprecation") public void run() { MessageDialogWithToggle dialog = new SynchronizerDialog(shell, EMFCompareRCPUIMessages.getString("FilterAction.synchronization.dialog.title"), //$NON-NLS-1$ @@ -155,8 +154,7 @@ public class FilterAction extends Action { FiltersPreferencePage.PAGE_ID); dialog.setPrefKey(FiltersPreferencePage.SYNCHRONIZATION_BEHAVIOR); - dialog.setPrefStore( - new ScopedPreferenceStore(new InstanceScope(), EMFCompareRCPUIPlugin.PLUGIN_ID)); + dialog.setPrefStore(EMFCompareRCPUIPlugin.getDefault().getPreferenceStore()); if (dialog.open() == IDialogConstants.YES_ID) { synchonizeFilters(); } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupAction.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupAction.java index 08e7d0bef..f0929d7f9 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupAction.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupAction.java @@ -14,7 +14,6 @@ import java.util.Iterator; import java.util.List; import org.eclipse.core.runtime.IStatus; -import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.compare.rcp.internal.extension.IItemDescriptor; import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin; import org.eclipse.emf.compare.rcp.ui.internal.EMFCompareRCPUIMessages; @@ -28,10 +27,9 @@ import org.eclipse.jface.action.Action; import org.eclipse.jface.action.IAction; import org.eclipse.jface.dialogs.IDialogConstants; import org.eclipse.jface.dialogs.MessageDialogWithToggle; +import org.eclipse.jface.preference.IPreferenceStore; import org.eclipse.swt.widgets.Event; import org.eclipse.swt.widgets.Shell; -import org.eclipse.ui.preferences.ScopedPreferenceStore; -import org.osgi.service.prefs.Preferences; /** * This action will allow us to group differences by their kind. @@ -56,7 +54,7 @@ public class GroupAction extends Action { private final DifferenceGroupManager groupManager; /** Preferences holding synchronization behavior value. */ - private final Preferences preferences; + private final IPreferenceStore preferences; /** * Instantiates our action given its target grouper. @@ -80,7 +78,7 @@ public class GroupAction extends Action { this.groupManager = groupManager; this.isThreeWay = isThreeWay; this.provider = gp; - this.preferences = EMFCompareRCPUIPlugin.getDefault().getEMFCompareUIPreferences(); + this.preferences = EMFCompareRCPUIPlugin.getDefault().getPreferenceStore(); } @Override @@ -108,9 +106,11 @@ public class GroupAction extends Action { */ private void handleSynchronization(Event event) { final Shell shell = event.display.getActiveShell(); - String preferenceValue = preferences.get( - GroupsPreferencePage.getGroupSynchronizationPreferenceKey(isThreeWay), - MessageDialogWithToggle.PROMPT); + String preferenceValue = preferences + .getString(GroupsPreferencePage.getGroupSynchronizationPreferenceKey(isThreeWay)); + if ("".equals(preferenceValue)) { //$NON-NLS-1$ + preferenceValue = MessageDialogWithToggle.PROMPT; + } if (MessageDialogWithToggle.PROMPT.equals(preferenceValue)) { shell.getDisplay().asyncExec(new SynchronizationRunnable(shell)); } else if (MessageDialogWithToggle.ALWAYS.equals(preferenceValue)) { @@ -173,8 +173,7 @@ public class GroupAction extends Action { GroupsPreferencePage.PAGE_ID); dialog.setPrefKey(GroupsPreferencePage.getGroupSynchronizationPreferenceKey(isThreeWay)); - dialog.setPrefStore( - new ScopedPreferenceStore(new InstanceScope(), EMFCompareRCPUIPlugin.PLUGIN_ID)); + dialog.setPrefStore(EMFCompareRCPUIPlugin.getDefault().getPreferenceStore()); if (dialog.open() == IDialogConstants.YES_ID) { setSelectedGroupAsDefault(); } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupActionMenu.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupActionMenu.java index 34111ac24..edc26e015 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupActionMenu.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/actions/GroupActionMenu.java @@ -72,8 +72,8 @@ public class GroupActionMenu extends Action implements IMenuCreator { public void updateMenu(IComparisonScope scope, Comparison comparison) { menuManager.removeAll(); DifferenceGroupManager groupManager = new DifferenceGroupManager( - EMFCompareRCPUIPlugin.getDefault().getEMFCompareUIPreferences(), - EMFCompareRCPUIPlugin.getDefault().getItemDifferenceGroupProviderRegistry()); + EMFCompareRCPUIPlugin.getDefault().getItemDifferenceGroupProviderRegistry(), + EMFCompareRCPUIPlugin.getDefault().getPreferenceStore()); for (IDifferenceGroupProvider.Descriptor dgp : registry.getGroupProviders(scope, comparison)) { IDifferenceGroupProvider gp = dgp.createGroupProvider(); if (gp != null) { diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/DifferenceFilterManager.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/DifferenceFilterManager.java index 77b104a7c..17aac3e36 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/DifferenceFilterManager.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/filters/impl/DifferenceFilterManager.java @@ -33,7 +33,7 @@ import org.eclipse.emf.compare.rcp.internal.tracer.TracingConstant; import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin; import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDeactivableDiffFilter; import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.filters.IDifferenceFilter; -import org.osgi.service.prefs.Preferences; +import org.eclipse.jface.preference.IPreferenceStore; /** * Manager of filters. @@ -57,8 +57,8 @@ public class DifferenceFilterManager { /** A map that associates the class name to their {@link IDifferenceFilter}s. */ private final Map<String, DifferenceFilterDefaultConfiguration> map; - /** The {@link Preferences} holding the value for filter preferences. */ - private final Preferences preferenceStore; + /** The {@link IPreferenceStore} holding the value for filter preferences. */ + private final IPreferenceStore preferenceStore; /** * Predicate use to transform {@link DifferenceFilterDefaultConfiguration} to {@link IDifferenceFilter}. @@ -77,9 +77,9 @@ public class DifferenceFilterManager { * Constructor. * * @param preferenceStore - * The {@link Preferences} holding the value for filter preferences. + * The {@link IPreferenceStore} holding the value for filter preferences. */ - public DifferenceFilterManager(Preferences preferenceStore) { + public DifferenceFilterManager(IPreferenceStore preferenceStore) { map = Collections.synchronizedMap(new LinkedHashMap<String, DifferenceFilterDefaultConfiguration>()); this.preferenceStore = preferenceStore; } @@ -183,7 +183,7 @@ public class DifferenceFilterManager { StringBuilder builder = new StringBuilder(); // Print each preferences builder.append("Preference ").append(BY_DEFAULT_DISABLED_FILTER).append(":\n"); //$NON-NLS-1$ //$NON-NLS-2$ - String preferenceValue = preferenceStore.get(BY_DEFAULT_DISABLED_FILTER, ""); //$NON-NLS-1$ + String preferenceValue = preferenceStore.getString(BY_DEFAULT_DISABLED_FILTER); String[] groups = preferenceValue.split(ItemUtil.PREFERENCE_DELIMITER); for (int rank = 0; rank < groups.length; rank++) { builder.append(rank).append(". ").append(groups[rank]).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -215,7 +215,7 @@ public class DifferenceFilterManager { StringBuilder builder = new StringBuilder(); // Print each preferences builder.append("Preference ").append(INACTIVE_FILTERS_PREF_KEY).append(":\n"); //$NON-NLS-1$ //$NON-NLS-2$ - String preferenceValue = preferenceStore.get(INACTIVE_FILTERS_PREF_KEY, ""); //$NON-NLS-1$ + String preferenceValue = preferenceStore.getString(INACTIVE_FILTERS_PREF_KEY); String[] groups = preferenceValue.split(ItemUtil.PREFERENCE_DELIMITER); for (int rank = 0; rank < groups.length; rank++) { builder.append(rank).append(". ").append(groups[rank]).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -243,9 +243,9 @@ public class DifferenceFilterManager { * @return A {@link Set} of disabled by default {@link IDifferenceFilter} from preferences. */ private Set<IDifferenceFilter> getDisabledFilters() { - String diffEngineKey = preferenceStore.get(BY_DEFAULT_DISABLED_FILTER, null); + String diffEngineKey = preferenceStore.getString(BY_DEFAULT_DISABLED_FILTER); Set<IDifferenceFilter> result = null; - if (diffEngineKey != null) { + if (diffEngineKey != null && !diffEngineKey.isEmpty()) { String[] diffEngineKeys = diffEngineKey.split(ItemUtil.PREFERENCE_DELIMITER); for (String nonTrimedKey : diffEngineKeys) { String key = nonTrimedKey.trim(); @@ -271,9 +271,9 @@ public class DifferenceFilterManager { * not implement {@link IDeactivableDiffFilter} cannot be deactivated). */ private Set<IDeactivableDiffFilter> getInactiveFilters() { - String diffEngineKey = preferenceStore.get(INACTIVE_FILTERS_PREF_KEY, null); + String diffEngineKey = preferenceStore.getString(INACTIVE_FILTERS_PREF_KEY); Set<IDeactivableDiffFilter> result = null; - if (diffEngineKey != null) { + if (diffEngineKey != null && !diffEngineKey.isEmpty()) { String[] diffEngineKeys = diffEngineKey.split(ItemUtil.PREFERENCE_DELIMITER); for (String nonTrimedKey : diffEngineKeys) { String key = nonTrimedKey.trim(); @@ -306,9 +306,9 @@ public class DifferenceFilterManager { Map<String, IDifferenceFilter> toStore = Maps.filterValues(Maps.transformValues(map, TO_FILTER), Predicates.in(currentValue)); String preferenceValue = Joiner.on(ItemUtil.PREFERENCE_DELIMITER).join(toStore.keySet()); - preferenceStore.put(prefKey, preferenceValue); + preferenceStore.putValue(prefKey, preferenceValue); } else { - preferenceStore.remove(prefKey); + preferenceStore.setToDefault(prefKey); } } diff --git a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/DifferenceGroupManager.java b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/DifferenceGroupManager.java index 45d936a6c..f3a321dd8 100644 --- a/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/DifferenceGroupManager.java +++ b/plugins/org.eclipse.emf.compare.rcp.ui/src/org/eclipse/emf/compare/rcp/ui/internal/structuremergeviewer/groups/impl/DifferenceGroupManager.java @@ -31,7 +31,7 @@ import org.eclipse.emf.compare.rcp.ui.EMFCompareRCPUIPlugin; import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.IDifferenceGroupProvider; import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.IDifferenceGroupProvider.ComparisonType; import org.eclipse.emf.compare.rcp.ui.structuremergeviewer.groups.IDifferenceGroupProvider.Descriptor; -import org.osgi.service.prefs.Preferences; +import org.eclipse.jface.preference.IPreferenceStore; /** * This manager can be used to modify EMF Compare UI behavior regarding groups. @@ -78,25 +78,24 @@ public class DifferenceGroupManager { /** Ordered list of groups for three way comparison. */ private static final String THREE_WAY_GROUP_RANKING = "org.eclipse.emf.compare.rcp.ui.groups.3way.ranking"; //$NON-NLS-1$ - /** Preferences holding preference values. */ - private final Preferences preferences; - /** Registry of {@link IDifferenceGroupProvider.Descriptor}. */ private final IItemRegistry<IDifferenceGroupProvider.Descriptor> registry; + /** The {@link IPreferenceStore} holding the value for group preferences. */ + private final IPreferenceStore preferenceStore; + /** * Constructor. * - * @param preferences - * Preferences holding preference values. * @param registry * Registry of {@link IDifferenceGroupProvider.Descriptor}. + * @param preferenceStore + * The {@link IPreferenceStore} holding the value for group preferences. */ - public DifferenceGroupManager(Preferences preferences, - IItemRegistry<IDifferenceGroupProvider.Descriptor> registry) { - super(); - this.preferences = preferences; + public DifferenceGroupManager(IItemRegistry<IDifferenceGroupProvider.Descriptor> registry, + IPreferenceStore preferenceStore) { this.registry = registry; + this.preferenceStore = preferenceStore; } /** @@ -178,7 +177,7 @@ public class DifferenceGroupManager { private <T> List<IItemDescriptor<T>> getOrderedItems(List<IItemDescriptor<T>> orderedDefaultDescriptor, IItemRegistry<T> descriptorRegistry, String orderedItemPreferenceKey) { List<IItemDescriptor<T>> itemsDescriptor = ItemUtil.getItemsDescriptor(descriptorRegistry, - orderedItemPreferenceKey, preferences); + EMFCompareRCPUIPlugin.PLUGIN_ID, orderedItemPreferenceKey); if (itemsDescriptor == null) { itemsDescriptor = orderedDefaultDescriptor; @@ -218,7 +217,7 @@ public class DifferenceGroupManager { StringBuilder builder = new StringBuilder(); // Print each preferences builder.append("Preference ").append(getGroupPreferenceKey(isThreeWay)).append(":\n"); //$NON-NLS-1$ //$NON-NLS-2$ - String preferenceValue = preferences.get(getGroupPreferenceKey(isThreeWay), ""); //$NON-NLS-1$ + String preferenceValue = preferenceStore.getString(getGroupPreferenceKey(isThreeWay)); String[] groups = preferenceValue.split(ItemUtil.PREFERENCE_DELIMITER); for (int rank = 0; rank < groups.length; rank++) { builder.append(rank).append(". ").append(groups[rank]).append("\n"); //$NON-NLS-1$ //$NON-NLS-2$ @@ -250,9 +249,9 @@ public class DifferenceGroupManager { } }); String preferenceValue = Joiner.on(ItemUtil.PREFERENCE_DELIMITER).join(currentIDs); - preferences.put(preferenceKey, preferenceValue); + preferenceStore.putValue(preferenceKey, preferenceValue); } else { - preferences.remove(preferenceKey); + preferenceStore.setToDefault(preferenceKey); } } diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java index f59a25914..38b7da5e2 100644 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java +++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/EMFCompareRCPPlugin.java @@ -8,6 +8,7 @@ * Contributors: * Obeo - initial API and implementation * Martin Fleck - bug 483798 + * Mathias Schaefer - preferences refactoring *******************************************************************************/ package org.eclipse.emf.compare.rcp; @@ -17,6 +18,7 @@ import static org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePrefere import static org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePreferences.LOG_FILENAME_KEY; import static org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePreferences.LOG_FILE_MAX_SIZE_KEY; import static org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePreferences.LOG_FILE_SIZE_DEFAULT; +import static org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePreferences.LOG_LEVEL_DEFAULT; import static org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePreferences.LOG_LEVEL_KEY; import static org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePreferences.LOG_PATTERN; @@ -42,9 +44,9 @@ import org.eclipse.core.runtime.IStatus; import org.eclipse.core.runtime.Platform; import org.eclipse.core.runtime.Plugin; import org.eclipse.core.runtime.Status; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.core.runtime.preferences.IEclipsePreferences.IPreferenceChangeListener; import org.eclipse.core.runtime.preferences.IEclipsePreferences.PreferenceChangeEvent; +import org.eclipse.core.runtime.preferences.IPreferencesService; import org.eclipse.core.runtime.preferences.InstanceScope; import org.eclipse.emf.common.util.URI; import org.eclipse.emf.compare.conflict.IConflictDetector; @@ -202,24 +204,13 @@ public class EMFCompareRCPPlugin extends Plugin { private WeightProviderDescriptorRegistryListener weightProviderListener; /** Will listen to preference changes and update log4j configuration accordingly. */ - private IPreferenceChangeListener preferenceChangeListener; + private LoggingPreferenceChangeListener preferenceChangeListener; /** * Keep all resources graphs identified by their id. */ private Map<String, IGraphView<URI>> graphsById = new HashMap<String, IGraphView<URI>>(); - /** - * Instance scope for preferences. - * <p> - * Do not use singleton to respect Helios compatibility - * </p> - * - * @see org.eclipse.core.runtime.preferences.InstanceScope#INSTANCE - */ - @SuppressWarnings("deprecation") - private InstanceScope instanceScope = new InstanceScope(); - /* * (non-Javadoc) * @see org.osgi.framework.BundleActivator#start(org.osgi.framework.BundleContext) @@ -285,8 +276,7 @@ public class EMFCompareRCPPlugin extends Plugin { matchEngineFactoryRegistryListener = new MatchEngineFactoryRegistryListener(PLUGIN_ID, MATCH_ENGINE_PPID, getLog(), matchEngineFactoryRegistry); matchEngineFactoryRegistryListener.readRegistry(registry); - matchEngineFactoryRegistryWrapped = new MatchEngineFactoryRegistryWrapper(matchEngineFactoryRegistry, - EMFCompareRCPPlugin.getDefault().getEMFComparePreferences()); + matchEngineFactoryRegistryWrapped = new MatchEngineFactoryRegistryWrapper(matchEngineFactoryRegistry); } /** @@ -411,11 +401,10 @@ public class EMFCompareRCPPlugin extends Plugin { @Override public void stop(BundleContext bundleContext) throws Exception { if (preferenceChangeListener != null) { - getEMFComparePreferences().removePreferenceChangeListener(preferenceChangeListener); + InstanceScope.INSTANCE.getNode(EMFCompareRCPPlugin.PLUGIN_ID) + .removePreferenceChangeListener(preferenceChangeListener); } - EMFCompareRCPPlugin.plugin = null; - final IExtensionRegistry registry = Platform.getExtensionRegistry(); discardConflictDetectorRegistry(registry); @@ -602,7 +591,7 @@ public class EMFCompareRCPPlugin extends Plugin { public RankedAdapterFactoryDescriptor.Registry createFilteredAdapterFactoryRegistry( Map<Object, Object> context) { final List<String> disabledAdapterFactories = EMFComparePreferences - .getDisabledAdapterFacotryDescriptorIds(getEMFComparePreferences()); + .getDisabledAdapterFactoryDescriptorIds(); // Filters disabled adapter factories Multimap<Collection<?>, RankedAdapterFactoryDescriptor> filteredBackingMultimap = ImmutableMultimap .copyOf(Multimaps.filterValues(adapterFactoryRegistryBackingMultimap, @@ -741,39 +730,36 @@ public class EMFCompareRCPPlugin extends Plugin { } /** - * Get the {@link IEclipsePreferences} for this plugin. - * - * @return {@link IEclipsePreferences} - */ - public IEclipsePreferences getEMFComparePreferences() { - return instanceScope.getNode(EMFCompareRCPPlugin.PLUGIN_ID); - } - - /** * Initializes log4j by reading the preferences. */ private void initLogging() { - IEclipsePreferences prefs = getEMFComparePreferences(); - LOGGER.setLevel(Level.toLevel(prefs.get(LOG_LEVEL_KEY, "OFF"))); //$NON-NLS-1$ + LOGGER.setLevel(Level.toLevel(Platform.getPreferencesService() + .getString(EMFCompareRCPPlugin.PLUGIN_ID, LOG_LEVEL_KEY, LOG_LEVEL_DEFAULT, null))); if (!Level.OFF.equals(LOGGER.getLevel())) { RollingFileAppender appender = (RollingFileAppender)LOGGER.getAppender(EMFC_APPENDER_NAME); - String logFileName = prefs.get(LOG_FILENAME_KEY, ""); //$NON-NLS-1$ + String logFileName = Platform.getPreferencesService().getString(EMFCompareRCPPlugin.PLUGIN_ID, + LOG_FILENAME_KEY, "", null); //$NON-NLS-1$ if (logFileName.length() > 0) { if (appender == null) { try { createLogAppender(logFileName); } catch (IOException e) { // Invalidate file name - prefs.put(LOG_FILENAME_KEY, ""); //$NON-NLS-1$ + Platform.getPreferencesService().getString(EMFCompareRCPPlugin.PLUGIN_ID, + LOG_FILENAME_KEY, "", null); //$NON-NLS-1$ } } else { - appender.setMaxBackupIndex(prefs.getInt(LOG_BACKUP_COUNT_KEY, 10)); - appender.setMaximumFileSize((prefs.getInt(LOG_FILE_MAX_SIZE_KEY, 100)) * MEGABYTE); + appender.setMaxBackupIndex(Platform.getPreferencesService().getInt( + EMFCompareRCPPlugin.PLUGIN_ID, LOG_BACKUP_COUNT_KEY, LOG_BACKUP_DEFAULT, null)); + appender.setMaximumFileSize( + (Platform.getPreferencesService().getInt(EMFCompareRCPPlugin.PLUGIN_ID, + LOG_FILE_MAX_SIZE_KEY, LOG_FILE_SIZE_DEFAULT, null)) * MEGABYTE); } } } preferenceChangeListener = new LoggingPreferenceChangeListener(); - prefs.addPreferenceChangeListener(preferenceChangeListener); + InstanceScope.INSTANCE.getNode(EMFCompareRCPPlugin.PLUGIN_ID) + .addPreferenceChangeListener(preferenceChangeListener); } /** @@ -790,10 +776,10 @@ public class EMFCompareRCPPlugin extends Plugin { appender = new RollingFileAppender(new PatternLayout(LOG_PATTERN), newFileName, true); LOGGER.removeAllAppenders(); // We don't want to log elsewhere LOGGER.addAppender(appender); - appender.setMaxBackupIndex( - getEMFComparePreferences().getInt(LOG_BACKUP_COUNT_KEY, LOG_BACKUP_DEFAULT)); - appender.setMaximumFileSize( - (getEMFComparePreferences().getInt(LOG_FILE_MAX_SIZE_KEY, LOG_FILE_SIZE_DEFAULT)) * MEGABYTE); + appender.setMaxBackupIndex(Platform.getPreferencesService().getInt(EMFCompareRCPPlugin.PLUGIN_ID, + LOG_BACKUP_COUNT_KEY, LOG_BACKUP_DEFAULT, null)); + appender.setMaximumFileSize((Platform.getPreferencesService().getInt(EMFCompareRCPPlugin.PLUGIN_ID, + LOG_FILE_MAX_SIZE_KEY, LOG_FILE_SIZE_DEFAULT, null)) * MEGABYTE); } /** @@ -804,16 +790,6 @@ public class EMFCompareRCPPlugin extends Plugin { private static class LoggingPreferenceChangeListener implements IPreferenceChangeListener { /** - * Instance scope for preferences. - * <p> - * Do not use singleton to respect Helios compatibility - * </p> - * - * @see org.eclipse.core.runtime.preferences.InstanceScope#INSTANCE - */ - private InstanceScope instanceScope = new InstanceScope(); - - /** * The path of the logging file. */ private String path; @@ -830,8 +806,9 @@ public class EMFCompareRCPPlugin extends Plugin { * the preference change event. */ public void preferenceChange(PreferenceChangeEvent event) { - IEclipsePreferences prefs = instanceScope.getNode(EMFCompareRCPPlugin.PLUGIN_ID); - path = prefs.get(LOG_FILENAME_KEY, ""); //$NON-NLS-1$ + final IPreferencesService prefs = Platform.getPreferencesService(); + + path = prefs.getString(EMFCompareRCPPlugin.PLUGIN_ID, LOG_FILENAME_KEY, "", null); //$NON-NLS-1$ if (LOG_LEVEL_KEY.equals(event.getKey())) { loggingLevel = Level.toLevel((String)event.getNewValue()); LOGGER.setLevel(loggingLevel); @@ -863,7 +840,8 @@ public class EMFCompareRCPPlugin extends Plugin { try { EMFCompareRCPPlugin.getDefault().createLogAppender(path); } catch (IOException e) { - EMFCompareRCPPlugin.getDefault().getEMFComparePreferences().put(LOG_FILENAME_KEY, ""); //$NON-NLS-1$ + // Force the value to be harmless + InstanceScope.INSTANCE.getNode(EMFCompareRCPPlugin.PLUGIN_ID).put(LOG_FILENAME_KEY, ""); //$NON-NLS-1$ getDefault().log(IStatus.ERROR, EMFCompareRCPMessages.getString("logging.appender.error", path, e.getMessage())); //$NON-NLS-1$ } diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/IConfigurableItem.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/IConfigurableItem.java deleted file mode 100644 index 381c5aeb7..000000000 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/IConfigurableItem.java +++ /dev/null @@ -1,37 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2014 Obeo. - * 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: - * Obeo - initial API and implementation - *******************************************************************************/ -package org.eclipse.emf.compare.rcp.internal.extension; - -import org.osgi.service.prefs.Preferences; - -/** - * Represente an item that can be configured from preferences. - * - * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a> - */ -public interface IConfigurableItem { - - /** - * Get the configuration of the Item. - * - * @return the configuration. - */ - Preferences getConfiguration(); - - /** - * Set the configuration of an Item. - * - * @param config - * Configuration to set. - */ - void setConfiguration(Preferences config); - -} diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/impl/EMFCompareBuilderConfigurator.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/impl/EMFCompareBuilderConfigurator.java index 44bc7dbcb..01f11bcc5 100644 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/impl/EMFCompareBuilderConfigurator.java +++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/impl/EMFCompareBuilderConfigurator.java @@ -10,9 +10,6 @@ *******************************************************************************/ package org.eclipse.emf.compare.rcp.internal.extension.impl; -import com.google.common.base.Preconditions; - -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.emf.compare.EMFCompare.Builder; import org.eclipse.emf.compare.conflict.IConflictDetector; import org.eclipse.emf.compare.diff.IDiffEngine; @@ -31,9 +28,6 @@ import org.eclipse.emf.compare.req.IReqEngine; */ public class EMFCompareBuilderConfigurator implements IEMFCompareBuilderConfigurator { - /** {@link IEclipsePreferences} holding engines information. */ - private final IEclipsePreferences enginePreferences; - /** Match engine factory registry. */ private final IMatchEngine.Factory.Registry matchEngineFactoryRegistry; @@ -43,18 +37,13 @@ public class EMFCompareBuilderConfigurator implements IEMFCompareBuilderConfigur /** * Constructor. * - * @param enginePreferences - * {@link EMFCompareBuilderConfigurator#enginePreferences} * @param matchEngineFactoryRegistry * {@link IMatchEngine.Factory.Registry} that holds Match Engine factories. * @param postProcessorRegistry * {@link IPostProcessor.Descriptor.Registry} that holds post processors. */ - public EMFCompareBuilderConfigurator(IEclipsePreferences enginePreferences, - IMatchEngine.Factory.Registry matchEngineFactoryRegistry, + protected EMFCompareBuilderConfigurator(IMatchEngine.Factory.Registry matchEngineFactoryRegistry, IPostProcessor.Descriptor.Registry<String> postProcessorRegistry) { - Preconditions.checkNotNull(enginePreferences); - this.enginePreferences = enginePreferences; this.matchEngineFactoryRegistry = matchEngineFactoryRegistry; this.postProcessorRegistry = postProcessorRegistry; } @@ -67,7 +56,7 @@ public class EMFCompareBuilderConfigurator implements IEMFCompareBuilderConfigur * @return Default EMFCompareBuilderConfigurator; */ public static EMFCompareBuilderConfigurator createDefault() { - return new EMFCompareBuilderConfigurator(EMFCompareRCPPlugin.getDefault().getEMFComparePreferences(), + return new EMFCompareBuilderConfigurator( EMFCompareRCPPlugin.getDefault().getMatchEngineFactoryRegistry(), EMFCompareRCPPlugin.getDefault().getPostProcessorRegistry()); } @@ -80,7 +69,7 @@ public class EMFCompareBuilderConfigurator implements IEMFCompareBuilderConfigur */ private IDiffEngine getDiffEngine() { return ItemUtil.getItem(EMFCompareRCPPlugin.getDefault().getDiffEngineDescriptorRegistry(), - EMFComparePreferences.DIFF_ENGINES, enginePreferences); + EMFComparePreferences.DIFF_ENGINES); } /** @@ -91,7 +80,7 @@ public class EMFCompareBuilderConfigurator implements IEMFCompareBuilderConfigur */ private IEquiEngine getEquiEngine() { return ItemUtil.getItem(EMFCompareRCPPlugin.getDefault().getEquiEngineDescriptorRegistry(), - EMFComparePreferences.EQUI_ENGINES, enginePreferences); + EMFComparePreferences.EQUI_ENGINES); } /** @@ -102,7 +91,7 @@ public class EMFCompareBuilderConfigurator implements IEMFCompareBuilderConfigur */ private IReqEngine getReqEngine() { return ItemUtil.getItem(EMFCompareRCPPlugin.getDefault().getReqEngineDescriptorRegistry(), - EMFComparePreferences.REQ_ENGINES, enginePreferences); + EMFComparePreferences.REQ_ENGINES); } /** @@ -113,7 +102,7 @@ public class EMFCompareBuilderConfigurator implements IEMFCompareBuilderConfigur */ private IConflictDetector getConflictDetector() { return ItemUtil.getItem(EMFCompareRCPPlugin.getDefault().getConflictDetectorDescriptorRegistry(), - EMFComparePreferences.CONFLICTS_DETECTOR, enginePreferences); + EMFComparePreferences.CONFLICTS_DETECTOR); } /** diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/impl/ItemUtil.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/impl/ItemUtil.java index 4a1e425f6..a65777f24 100644 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/impl/ItemUtil.java +++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/extension/impl/ItemUtil.java @@ -16,11 +16,10 @@ import java.util.ArrayList; import java.util.List; import java.util.Set; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.Platform; import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; import org.eclipse.emf.compare.rcp.internal.extension.IItemDescriptor; import org.eclipse.emf.compare.rcp.internal.extension.IItemRegistry; -import org.osgi.service.prefs.Preferences; /** * Util class for item. @@ -46,15 +45,12 @@ public final class ItemUtil { * The item registry * @param preferenceKey * The preference to retrieve the key. - * @param itemPreferences - * Eclipse preference where are stored the items to use * @param <T> * Type of item * @return an item or null if nothing has been found. */ - public static <T> T getItem(IItemRegistry<T> registry, String preferenceKey, - IEclipsePreferences itemPreferences) { - IItemDescriptor<T> desc = getDefaultItemDescriptor(registry, preferenceKey, itemPreferences); + public static <T> T getItem(IItemRegistry<T> registry, String preferenceKey) { + IItemDescriptor<T> desc = getDefaultItemDescriptor(registry, preferenceKey); if (desc != null) { return desc.getItem(); } @@ -69,15 +65,13 @@ public final class ItemUtil { * {@link IItemRegistry} of the item type * @param preferenceKey * Preference key use to retrieve the item - * @param itemPreferences - * {@link IEclipsePreferences} where are stored the item preferences. * @param <T> * Type of item * @return {@link IItemDescriptor} */ public static <T> IItemDescriptor<T> getDefaultItemDescriptor(IItemRegistry<T> registry, - String preferenceKey, IEclipsePreferences itemPreferences) { - IItemDescriptor<T> result = getItemDescriptorFromPref(registry, itemPreferences, preferenceKey); + String preferenceKey) { + IItemDescriptor<T> result = getItemDescriptorFromPref(registry, preferenceKey); if (result == null) { IItemDescriptor<T> descriptor = registry.getHighestRankingDescriptor(); if (descriptor != null) { @@ -94,20 +88,19 @@ public final class ItemUtil { * Registry for the {@link IItemDescriptor} * @param preferenceKey * Key for this {@link IItemDescriptor} in preferences - * @param itemPreferences - * {@link IEclipsePreferences} where are stored {@link IItemDescriptor} values * @param <T> * Type of {@link IItemDescriptor} * @return {@link IItemDescriptor} or null if nothing in preferences */ private static <T> IItemDescriptor<T> getItemDescriptorFromPref(IItemRegistry<T> registry, - IEclipsePreferences itemPreferences, String preferenceKey) { - String itemKey = itemPreferences.get(preferenceKey, null); + String preferenceKey) { + String itemKey = Platform.getPreferencesService().getString(EMFCompareRCPPlugin.PLUGIN_ID, + preferenceKey, null, null); IItemDescriptor<T> result = null; if (itemKey != null) { - IItemDescriptor<T> descritpor = registry.getItemDescriptor(itemKey); - if (descritpor != null) { - result = descritpor; + IItemDescriptor<T> descriptor = registry.getItemDescriptor(itemKey); + if (descriptor != null) { + result = descriptor; } } return result; @@ -118,28 +111,29 @@ public final class ItemUtil { * * @param registry * Registry for the {@link IItemDescriptor} + * @param qualifier + * the preference qualifier (plug-in ID) * @param preferenceKey * Key for this {@link IItemDescriptor} in preferences - * @param itemPreferences - * {@link Preferences} where are stored {@link IItemDescriptor} values * @param <T> * Type of {@link IItemDescriptor} * @return List of {@link IItemDescriptor} or null if nothing in preferences */ - public static <T> List<IItemDescriptor<T>> getItemsDescriptor(IItemRegistry<T> registry, - String preferenceKey, Preferences itemPreferences) { - String diffEngineKey = itemPreferences.get(preferenceKey, null); + public static <T> List<IItemDescriptor<T>> getItemsDescriptor(IItemRegistry<T> registry, String qualifier, + String preferenceKey) { + String diffEngineKey = Platform.getPreferencesService().getString(qualifier, preferenceKey, null, + null); List<IItemDescriptor<T>> result = null; if (diffEngineKey != null) { String[] diffEngineKeys = diffEngineKey.split(PREFERENCE_DELIMITER); for (String nonTrimedKey : diffEngineKeys) { String key = nonTrimedKey.trim(); - IItemDescriptor<T> descritpor = registry.getItemDescriptor(key); - if (descritpor != null) { + IItemDescriptor<T> descriptor = registry.getItemDescriptor(key); + if (descriptor != null) { if (result == null) { result = new ArrayList<IItemDescriptor<T>>(); } - result.add(descritpor); + result.add(descriptor); } } } @@ -148,19 +142,6 @@ public final class ItemUtil { } /** - * Return the node holding the configuration for an item. - * - * @param type - * Type of item. - * @param itemId - * Id of the item we want to retrieve the configuration for. - * @return The {@link Preferences} holding the configuration. - */ - public static Preferences getConfigurationPreferenceNode(String type, String itemId) { - return EMFCompareRCPPlugin.getDefault().getEMFComparePreferences().node(type).node(itemId); - } - - /** * Get all active item from a registry. * <p> * (Filter out all disable element stored in preferences) @@ -168,16 +149,18 @@ public final class ItemUtil { * * @param registry * Registry holding all items of this kind + * @param qualifier + * The preference qualifier (plug-in ID) * @param disabledItemPreferenceKey * Preference key where are stored disabled items. * @return {@link Set} of active items * @param <T> * Item type */ - public static <T> Set<IItemDescriptor<T>> getActiveItems(IItemRegistry<T> registry, + public static <T> Set<IItemDescriptor<T>> getActiveItems(IItemRegistry<T> registry, String qualifier, String disabledItemPreferenceKey) { - List<IItemDescriptor<T>> itemsDescriptor = ItemUtil.getItemsDescriptor(registry, - disabledItemPreferenceKey, EMFCompareRCPPlugin.getDefault().getEMFComparePreferences()); + List<IItemDescriptor<T>> itemsDescriptor = getItemsDescriptor(registry, qualifier, + disabledItemPreferenceKey); if (itemsDescriptor == null) { return Sets.newLinkedHashSet(registry.getItemDescriptors()); diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/DefaultRCPMatchEngineFactory.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/DefaultRCPMatchEngineFactory.java index bec9117ea..f94fc982a 100644 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/DefaultRCPMatchEngineFactory.java +++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/DefaultRCPMatchEngineFactory.java @@ -11,21 +11,20 @@ package org.eclipse.emf.compare.rcp.internal.match; import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Platform; import org.eclipse.emf.compare.EMFCompareMessages; import org.eclipse.emf.compare.match.DefaultMatchEngine; import org.eclipse.emf.compare.match.IMatchEngine; import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; -import org.eclipse.emf.compare.rcp.internal.extension.IConfigurableItem; import org.eclipse.emf.compare.scope.IComparisonScope; import org.eclipse.emf.compare.utils.UseIdentifiers; -import org.osgi.service.prefs.Preferences; /** * Implementation of {@link IMatchEngine.Factory} for the {@link DefaultMatchEngine} that can be configured. * * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a> */ -public class DefaultRCPMatchEngineFactory implements IMatchEngine.Factory, IConfigurableItem { +public class DefaultRCPMatchEngineFactory implements IMatchEngine.Factory { /** Attribute used to retrieve UseIdentifier attribute from preferences. */ public static final String USE_IDENTIFIER_ATTR = "UseIdentifier"; //$NON-NLS-1$ @@ -36,9 +35,6 @@ public class DefaultRCPMatchEngineFactory implements IMatchEngine.Factory, IConf /** Rank of the factory. */ private int rank; - /** Configuration used to instance the match engine. */ - private Preferences config; - /** * Constructor. */ @@ -50,22 +46,17 @@ public class DefaultRCPMatchEngineFactory implements IMatchEngine.Factory, IConf * Parse the input preference to retrieve the value of * {@link DefaultRCPMatchEngineFactory#USE_IDENTIFIER_ATTR}. * - * @param pref - * {@link Preferences} holding configuration for this {@link IMatchEngine.Factory}. * @return The value of {@link DefaultRCPMatchEngineFactory#USE_IDENTIFIER_ATTR}. */ - public static UseIdentifiers getUseIdentifierValue(Preferences pref) { + public static UseIdentifiers getUseIdentifierValue() { UseIdentifiers result; - if (pref != null) { - String storedPref = pref.get(USE_IDENTIFIER_ATTR, DEFAULT_USE_IDENTIFIER_ATRIBUTE.toString()); - try { - result = UseIdentifiers.valueOf(storedPref); - } catch (IllegalArgumentException e) { - EMFCompareRCPPlugin.getDefault().log(IStatus.ERROR, EMFCompareMessages - .getString("RCPMatchEngineFactory.INCORECT_USE_IDENTIFIER_ATTRIBUTE")); //$NON-NLS-1$ - result = DEFAULT_USE_IDENTIFIER_ATRIBUTE; - } - } else { + String storedPref = Platform.getPreferencesService().getString(EMFCompareRCPPlugin.PLUGIN_ID, + USE_IDENTIFIER_ATTR, DEFAULT_USE_IDENTIFIER_ATRIBUTE.toString(), null); + try { + result = UseIdentifiers.valueOf(storedPref); + } catch (IllegalArgumentException e) { + EMFCompareRCPPlugin.getDefault().log(IStatus.ERROR, + EMFCompareMessages.getString("RCPMatchEngineFactory.INCORECT_USE_IDENTIFIER_ATTRIBUTE")); //$NON-NLS-1$ result = DEFAULT_USE_IDENTIFIER_ATRIBUTE; } return result; @@ -75,7 +66,7 @@ public class DefaultRCPMatchEngineFactory implements IMatchEngine.Factory, IConf * {@inheritDoc} */ public IMatchEngine getMatchEngine() { - final UseIdentifiers useUdentifier = getUseIdentifierValue(config); + final UseIdentifiers useUdentifier = getUseIdentifierValue(); return DefaultMatchEngine.create(useUdentifier, EMFCompareRCPPlugin.getDefault().getWeightProviderRegistry()); } @@ -102,19 +93,4 @@ public class DefaultRCPMatchEngineFactory implements IMatchEngine.Factory, IConf return true; } - /** - * {@inheritDoc} - */ - public Preferences getConfiguration() { - return config; - } - - /** - * {@inheritDoc} - */ - public void setConfiguration(Preferences inputConfig) { - this.config = inputConfig; - - } - } diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/MatchEngineFactoryDescriptor.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/MatchEngineFactoryDescriptor.java index e224438d7..3b0cb4561 100644 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/MatchEngineFactoryDescriptor.java +++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/MatchEngineFactoryDescriptor.java @@ -16,11 +16,7 @@ import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IConfigurationElement; import org.eclipse.emf.compare.match.IMatchEngine; import org.eclipse.emf.compare.match.IMatchEngine.Factory; -import org.eclipse.emf.compare.rcp.internal.extension.IConfigurableItem; -import org.eclipse.emf.compare.rcp.internal.extension.impl.ItemUtil; import org.eclipse.emf.compare.rcp.internal.extension.impl.LazyItemDescriptor; -import org.eclipse.emf.compare.rcp.internal.preferences.EMFComparePreferences; -import org.osgi.service.prefs.Preferences; /** * Descriptor for {@link IMatchEngine.Factory}. @@ -39,7 +35,7 @@ public class MatchEngineFactoryDescriptor extends LazyItemDescriptor<IMatchEngin * @param rank * {@link LazyItemDescriptor#getRank()} * @param config - * {@link IConfigurableItem} element used to create this item. + * {@link IConfigurationElement} element used to create this item. * @param id * {@link LazyItemDescriptor#getID()} */ @@ -58,11 +54,6 @@ public class MatchEngineFactoryDescriptor extends LazyItemDescriptor<IMatchEngin factory = (Factory)getConfig() .createExecutableExtension(MatchEngineFactoryRegistryListener.ATT_CLASS); factory.setRanking(getRank()); - if (factory instanceof IConfigurableItem) { - Preferences configuration = ItemUtil.getConfigurationPreferenceNode( - EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, getID()); - ((IConfigurableItem)factory).setConfiguration(configuration); - } } catch (CoreException e) { Throwables.propagate(e); } diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/MatchEngineFactoryRegistryWrapper.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/MatchEngineFactoryRegistryWrapper.java index 0b09cbb69..ab05a0f35 100644 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/MatchEngineFactoryRegistryWrapper.java +++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/match/MatchEngineFactoryRegistryWrapper.java @@ -24,9 +24,9 @@ import java.util.Collections; import java.util.Iterator; import java.util.List; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; import org.eclipse.emf.compare.match.IMatchEngine; import org.eclipse.emf.compare.match.IMatchEngine.Factory; +import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; import org.eclipse.emf.compare.rcp.internal.extension.IItemDescriptor; import org.eclipse.emf.compare.rcp.internal.extension.IItemRegistry; import org.eclipse.emf.compare.rcp.internal.extension.impl.AbstractItemDescriptor; @@ -48,22 +48,14 @@ public class MatchEngineFactoryRegistryWrapper implements IMatchEngine.Factory.R /** Instance of the registry that need to be wrapped. */ private IItemRegistry<IMatchEngine.Factory> registry; - /** Preferences holding disabled match engines. */ - private final IEclipsePreferences preferences; - /** * Constructor. * - * @param registy + * @param registry * {@link MatchEngineFactoryRegistryWrapper#registry} - * @param preferences - * Preferences holding disabled match engines. */ - public MatchEngineFactoryRegistryWrapper(IItemRegistry<Factory> registy, - IEclipsePreferences preferences) { - super(); - this.registry = registy; - this.preferences = preferences; + public MatchEngineFactoryRegistryWrapper(IItemRegistry<Factory> registry) { + this.registry = registry; } /** @@ -176,7 +168,7 @@ public class MatchEngineFactoryRegistryWrapper implements IMatchEngine.Factory.R */ private Collection<IItemDescriptor<IMatchEngine.Factory>> getDisabledEngines() { Collection<IItemDescriptor<Factory>> result = ItemUtil.getItemsDescriptor(registry, - EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES, preferences); + EMFCompareRCPPlugin.PLUGIN_ID, EMFComparePreferences.MATCH_ENGINE_DISABLE_ENGINES); if (result == null) { result = Collections.emptyList(); } diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorRegistryImpl.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorRegistryImpl.java index 927128c88..ac6a6af01 100644 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorRegistryImpl.java +++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/postprocessor/PostProcessorRegistryImpl.java @@ -103,8 +103,7 @@ public class PostProcessorRegistryImpl implements IPostProcessor.Descriptor.Regi */ private Collection<IItemDescriptor<IPostProcessor.Descriptor>> getDisabledEngines() { List<IItemDescriptor<IPostProcessor.Descriptor>> result = ItemUtil.getItemsDescriptor(baseRegisty, - EMFComparePreferences.DISABLED_POST_PROCESSOR, - EMFCompareRCPPlugin.getDefault().getEMFComparePreferences()); + EMFCompareRCPPlugin.PLUGIN_ID, EMFComparePreferences.DISABLED_POST_PROCESSOR); if (result == null) { result = Collections.emptyList(); } diff --git a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/preferences/EMFComparePreferences.java b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/preferences/EMFComparePreferences.java index 53cf6052a..f3340866f 100644 --- a/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/preferences/EMFComparePreferences.java +++ b/plugins/org.eclipse.emf.compare.rcp/src/org/eclipse/emf/compare/rcp/internal/preferences/EMFComparePreferences.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2014, 2015 Obeo. + * Copyright (c) 2014, 2016 Obeo. * 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 @@ -15,10 +15,11 @@ import com.google.common.collect.Lists; import java.util.List; -import org.eclipse.core.runtime.preferences.IEclipsePreferences; +import org.eclipse.core.runtime.Platform; +import org.eclipse.emf.compare.rcp.EMFCompareRCPPlugin; -/** - * All preferences constant for EMF Compare. +/*** + * Preferences constants and utilities for the EMF Compare RCP plug-in. * * @author <a href="mailto:arthur.daussy@obeo.fr">Arthur Daussy</a> */ @@ -91,13 +92,11 @@ public final class EMFComparePreferences { /** * Gets the ids of all disabled EMF Compare adapter factory descriptors. * - * @param preferenceStore - * {@link IEclipsePreferences} where are stored the preferences. * @return List of ids; */ - public static List<String> getDisabledAdapterFacotryDescriptorIds(IEclipsePreferences preferenceStore) { - String disabledAdapterFactoriesString = preferenceStore - .get(EMFComparePreferences.DISABLED_ADAPTER_FACTORY, ""); //$NON-NLS-1$ + public static List<String> getDisabledAdapterFactoryDescriptorIds() { + String disabledAdapterFactoriesString = Platform.getPreferencesService() + .getString(EMFCompareRCPPlugin.PLUGIN_ID, DISABLED_ADAPTER_FACTORY, "", null); //$NON-NLS-1$ final List<String> disabledAdapterFactories = Lists.newArrayList( Splitter.on(';').omitEmptyStrings().trimResults().split(disabledAdapterFactoriesString)); |