Showing posts with label ConfigurationScope. Show all posts
Showing posts with label ConfigurationScope. Show all posts

Wednesday, December 9, 2015

Preferences sharing across all workspaces - Handling programatically

To share preferences across all workspaces in eclipse, you need to save preferences via ConfigurationScope.

What is configuration scope ?

Preferences stored in this scope are shared by all workspaces that are launched using a particular configuration of Eclipse plug-ins. On a single-user installation, this serves to capture preferences that are common to all workspaces launched by that user. On a multi-user installation, these preferences are shared by all users of the configuration.

How to save ?

IEclipsePreferences store = ConfigurationScope.INSTANCE.getNode(MyUIPlugin.PLUGIN_ID);
if (store != null)
{
store.putBoolean(MyFLAG_PREF, true);
try
{
store.flush();
}
catch (BackingStoreException e)
{
//Log exception
}
}


How to retrieve the saved preference value?

boolean isSet = Platform.getPreferencesService().getBoolean(MyUIPlugin.PLUGIN_ID,
MyFLAG_PREF, false, new IScopeContext[] { ConfigurationScope.INSTANCE });


Understand more about preference scopes: