Home > Software engineering >  What's the difference between "Default scope" and "BundleDefaultsScope" amo
What's the difference between "Default scope" and "BundleDefaultsScope" amo

Time:01-11

I'm new to Eclipse Preference scope, I have read this article and learned something. Then I went to read some code and found something that was confusing to me.

In org.eclipse.ant.internal.ui.AntUIPreferenceInitializer, use BundleDefaultsScope :

IPreferenceStore prefs = AntUIPlugin.getDefault().getPreferenceStore();
prefs.setDefault(IAntUIPreferenceConstants.ANT_FIND_BUILD_FILE_NAMES, "build.xml"); //$NON-NLS-1$

In org.eclipse.ui.internal.ide.IDEPreferenceInitializer, use Default scope:

IEclipsePreferences node = DefaultScope.INSTANCE.getNode(IDEWorkbenchPlugin.getDefault().getBundle().getSymbolicName());

Why? What's the difference? What could be the purpose of such a design?

CodePudding user response:

IPreferenceStore is a layer on top ofIEclipsePreference. It provides a single interface to the instance and default preference scopes. It can also be used for more complicated things using multiple stores (the Ant example is actually one of them using Ants own OverlayPreferenceStore).

Usually IPreferenceStore uses the ScopedPreferenceStore implementation.

ScopedPreferenceStore usually uses a InstanceScope and a DefaultScope for a plug-in (Bundle) but can be set up with other scopes.

IPreferenceStore.setDefault ends up calling the DefaultScope put method (and set calls the InstanceScope put)

CodePudding user response:

Default Scope cannot be persisted and the default value cannot be changed. The default value is usually defined by program or product. Such as org.eclipse.platform/plugin_customization.ini

BundleDefaults Scope cannot be persisted but is allowed to change, it's just more used for setting the default preference value, Usually it is used with Plugin.getPreferenceStore().setDefault .

org.eclipse.core.internal.preferences.DefaultPreferences
org.eclipse.core.internal.preferences.BundleDefaultPreferences
  • Related