Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse Platform » Preferences and defaults in non-UI plugin
Preferences and defaults in non-UI plugin [message #373115] Wed, 29 July 2009 12:34
Thomas ten Cate is currently offline Thomas ten CateFriend
Messages: 1
Registered: July 2009
Junior Member
Hello,

I'm trying to port a plugin that uses the deprecated preferences API to
the new org.eclipse.core.runtime.preferences API. I read as much as I
could find on the preferences story, but I'm still confused.

The situation is (I think) a common one. The plug-in needs to store some
preferences in the InstanceScope. Several classes in the plug-in access
these preferences. I want the defaults to be set up in some central place,
which will of course be an AbstractPreferenceInitializer subclass.

Now there are several ways of going about this. Assume that MY_PLUGIN_ID
is the plugin ID and MY_PREF_ID is the preference key, of boolean type.

1. Platform.getPreferencesService.get(MY_PLUGIN_ID + "/" + MY_PREF_ID,
defaultValue, nodes)

These require that I pass in a default value, even if I pass in the
DefaultScope's root node as the last node in the nodes array. The result
would be that I have my defaults scattered all over the code, and they
might not even be consistent!

2. Platform.getPreferencesService.getBoolean(MY_PLUGIN_ID, MY_PREF_ID,
defaultValue, scopeContexts)

Again, I need to pass in a default value, even if the DefaultScope is in
the scopeContexts array.

3. new InstanceScope().getNode(MY_PLUGIN_ID).getBoolean(MY_PREF_ID,
defaultValue)

Again, it requires a default value. Makes sense in this case, because I
only look in the InstanceScope, not the DefaultScope. So fairly useless.

4. MyPlugin.getDefault().getPreferenceStore().getBoolean(MY_PRE F_ID)

This looks ideal! So clean and simple! But... I can't use it, because my
plugin does not inherit from AbstractUIPlugin. Therefore it doesn't have a
getPreferencesStore method. I would like to keep it independent of
org.eclipse.ui.plugin and org.eclipse.jface.preference, so
IPreferencesStore is out of the question. Why is it that only UI plugins
get this convenient interface?

It's hard to imagine that this common scenario was overlooked when
designing the new preferences API. Did I miss something? Am I being too
demanding here? Should I set up a class to statically hold the default
values, and use these all over the place? Should I stop whining and make
my plugin inherit from AbstractUIPlugin, even though it doesn't make any
UI contributions?

Any help would be much appreciated.

Thomas
Previous Topic:PlatformUI.getWorkbench().saveAll with ISaveableFilter on IFile
Next Topic:Issue with Junit tests and -noupdate
Goto Forum:
  


Current Time: Fri Apr 26 15:09:02 GMT 2024

Powered by FUDForum. Page generated in 0.03839 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top