How can two eclipse plugin use the same preferences store?
Asked Answered
T

3

5

I have two plugins, say com.site.plugin.core and com.site.plugin.ui.
I'd like to separate core part from UI part, so at plugin com.site.plugin.ui I created Preferences page where I defined some preferences, which should be used by com.site.plugin.core. I check article at Eclipse site, but it is quite outdated, and linked bug also do not provide much info.
So is it possible to do this using standard Eclipse mechanism, or I need use direct low-level API via package org.eclipse.core.runtime.preferences?

Trichomonad answered 22/4, 2010 at 9:18 Comment(0)
S
5

I believe that the UI depends on Core and not otherwise. In this case, you could use the Core's preference store in the UI plugin's preference page, like this:

IPreferenceStore store = CorePluginActivator.getDefault().getPreferenceStore();
setPreferenceStore(store);

In this way the preference page will store the values in the Core plugin. The Core plugin can use the values without depending on the UI plugin.

Spindlelegs answered 10/3, 2011 at 4:28 Comment(0)
N
3

You can also access preferences in other plug-ins using the preference service:

String pref = Platform.getPreferencesService().getString(
    "org.myplugin.preferences.page", "pref name",
    "default value if pref not found", null);
Nearly answered 31/8, 2011 at 9:20 Comment(2)
Note that for me the 'org.myplugin.preferences.page' did not work, I had to use 'org.myplugin.id'.Doe
For me it was also the ID, thanks for the hint. Like this, this is the perfect solution for me :)Stantonstanway
S
1

Prefs stores are found per plugin. This is one way to get a prefs store for the plugin whose activator class is ActivatorA.

IPreferenceStore store = ActivatorA.getDefault().getPreferenceStore();

If you want another plugin to refer to the same store, perhaps you could expose some api on ActivatorA for it to get there, e.g.

public IPreferenceStore getSharedPrefs() {
    return ActivatorA.getDefault().getPreferenceStore();
}

The second plugin would find the shared store by doing this

IPreferenceStore sharedPrefs = ActivatorA.getSharedPrefs();

Good luck.

Stefaniestefano answered 10/5, 2010 at 23:19 Comment(2)
Hmmm... But in this case my core plugin should know about UI part. It is not good.Trichomonad
OK. In general terms what would an acceptable way for the core plug-in to locate the shared data, if not via the plugin that creates it. How about: a filepath?, Dialog-settings? a URL?Stefaniestefano

© 2022 - 2024 — McMap. All rights reserved.