Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » Use PreferenceStore and IScopeContext together(Extend a org.eclipse.jface.preference.PreferenceStore which uses org.osgi.service.prefs.Preferences)
Use PreferenceStore and IScopeContext together [message #1748120] Fri, 18 November 2016 15:31 Go to next message
Paolo M. is currently offline Paolo M.Friend
Messages: 8
Registered: November 2016
Junior Member
I'm trying to implement a PreferenceDialog with a PreferenceStore, which is synchronized with an osgi Preferences, what do you think about the below solution?
There are drawbacks?

Thank you

public class MyPreferenceStore extends PreferenceStore {
	private Preferences preferences;
	public MyPreferenceStore() {
		this.preferences = InstanceScope.INSTANCE.getNode(FrameworkUtil.getBundle(getClass()).getSymbolicName());
		setDefault(MY_PREFERENCE_1, "Default_1");
		setDefault(MY_PREFERENCE_2, "Default_2");
	public void load() throws IOException {
		StringBuffer propEntries = new StringBuffer();
		propEntries.append(createPropertyEntry(MY_PREFERENCE_1, "Default_1"));
		propEntries.append(createPropertyEntry(MY_PREFERENCE_2, "Default_2"));

		InputStream stream = new ByteArrayInputStream(propEntries.toString().getBytes(StandardCharsets.UTF_8));
	private String createPropertyEntry(String key, String defaultValue){
		String value = preferences.get(key, defaultValue);
		return key + "=" + value + System.getProperty("line.separator");
	public void save() throws IOException {
		// To set dirty = false;
		try {
		} catch (BackingStoreException e) {
	private void savePreference(String key){
		preferences.put(key, getString(key));
Re: Use PreferenceStore and IScopeContext together [message #1748189 is a reply to message #1748120] Mon, 21 November 2016 06:32 Go to previous message
Dirk Fauth is currently offline Dirk FauthFriend
Messages: 2621
Registered: July 2012
Senior Member
Not sure what your goal is. You are just wrapping the instance scope PreferenceStore of a bundle.

I have created a mechanism and published via GitHub that lets you create a PreferenceDialog via OSGi DS .. so you can contribute PreferenceNodeContributions via DS.

Not sure if this is something you are trying to achieve.
Previous Topic:Eclipse plugin life cycle
Next Topic:extension org.eclipse.ui.intro in E4
Goto Forum:

Current Time: Sat Oct 20 02:47:35 GMT 2018

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

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

Back to the top