Skip to main content



      Home
Home » Eclipse Projects » Rich Client Platform (RCP) » using AbstractPreferenceInitializer versus Activator.start()
using AbstractPreferenceInitializer versus Activator.start() [message #460010] Mon, 11 December 2006 11:05 Go to next message
Eclipse UserFriend
R3.2.1, WinXP

I've been playng around with the "best" way to init default-values for my prefs, in an RCP app that
contains a number of "optional" plug-ins each having their own PrefPage. (The PrefPages are all
working fine, show up when the "optional" plug-in is included in the build, etc.)

The main (app) plug-in of course does not make direct reference to any of the Pref-Pages of the
"optional" plug-ins, but I have placed the String *keys* in some common module in order to refer to
them -- some of the prefs that are surfaced to users via an "optional" plug-in are actually used by
other plug-ins.

I need for at least some of the prefs-values to have their defaults init'd (and their stored values
read) *before* any GUI elements are created.

I'm using the PreferenceStore provided by AbstractUIPlugin.

So -- my question: is it better to init the default values of the prefs of the "optional" plug-ins:

(a) in the MyFooActivator's start() method, as follows:
@Override
public void start(final BundleContext context) throws Exception {
super.start(context);
try {
MyFooPreferences.setDefaults(PlatformUI.getPreferenceStore() );
} catch (Exception exn) {
exn.printStackTrace();
}
}

OR (b) in an AbstractPreferenceInitializer specified using the "initializer" tag of the
"org.eclipse.core.runtime.preferences" extension-point? (I have not yet tried this system.)

OR (c) in my WorkbenchAdvisor's preStartup() method, as follows:
final IPreferenceStore store = PlatformUI.getPreferenceStore();
MainAppPreferences.setDefaults(store); // set the app's pref-defaults

// set the defaults for other plugins, using a module of their keys,
// that is resident in the main app plug-in:
store.setDefault(OtherPluginsPrefsKeys.MY_FOO_KEY, AppConfigs.MY_FOO_DEFAULT);

// the "AppConfigs" is just a module of set/get methods, pushed down into
// a low-level (non-UI) plug-in on which any plug-in in the system can depend:
AppConfigs.setSomeIntValue(store.getInt(OtherPluginsPrefsKey s.MY_FOO_KEY));

Or?

thanks for the advice,
Paul
Re: using AbstractPreferenceInitializer versus Activator.start() [message #460028 is a reply to message #460010] Mon, 11 December 2006 17:38 Go to previous message
Eclipse UserFriend
There's also being able to expose the preference store via an accessor method in your bundle, and that inside you can use the set up of defaults:

public PreferenceStore getPreferenceStore() {
  if (!initialised) {
    store = PlatformUI.getPreferenceStore();
    setDefaults(store);
  }
  return store;
}   


You can then use this prior to accessing/displaying any values.

Alex.
Previous Topic:How to run a project using UTF-8 encoding?
Next Topic:Problem with TabbedProperties View
Goto Forum:
  


Current Time: Sat Mar 22 09:19:27 EDT 2025

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

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

Back to the top