Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Rich Client Platform (RCP) » Use default preferences for a workspace
Use default preferences for a workspace [message #1747269] Fri, 11 November 2016 13:04 Go to next message
Alexander Fichtinger is currently offline Alexander FichtingerFriend
Messages: 62
Registered: January 2013
Member
Hey guys,

and another problem / question:

Our customer wants to use Default Preferences for a workspace which he is using. This default preferences are provided by us.

So I thought of the following solution:


  • Set all the required preferences
  • Export the Preferences
  • Import the preferences programatically everytime the user creates a new workspace or project


Is this a good solution? Or is there a better way to do this?

Kind regards
Re: Use default preferences for a workspace [message #1747305 is a reply to message #1747269] Fri, 11 November 2016 20:20 Go to previous messageGo to next message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 788
Registered: January 2012
Senior Member

If you set defaults preferences in the DefaultScope, which is programmatic, then you shouldn't need to do anything.

But I'm guessing you want to provide different defaults for this customer. The best I can think of is to have your preference initializer check and load a properties file specified via a system property on the command-line, and use it to over-ride your defaults when setting the DefaultScope.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Re: Use default preferences for a workspace [message #1747400 is a reply to message #1747305] Mon, 14 November 2016 10:16 Go to previous messageGo to next message
Alexander Fichtinger is currently offline Alexander FichtingerFriend
Messages: 62
Registered: January 2013
Member
Thanks for your answer Brian.

Now I'm doing the following:

I specified this code in the plugin.xml:

    <extension point="org.eclipse.core.runtime.preferences">
      <initializer
            class="example.PreferenceInitializer">
      </initializer>
  </extension>


And my PreferenceInitializer looks like this:


package com.logicals.oemplugin.branding.example;

import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;

/**
 * Class used to initialize default preference values.
 */
public class PreferenceInitializer extends AbstractPreferenceInitializer
{
  /*
   * (non-Javadoc)
   * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer#initializeDefaultPreferences()
   */
  @Override
  public void initializeDefaultPreferences()
  {
    final org.eclipse.core.runtime.preferences.IPreferencesService preferenceService = Platform.getPreferencesService();
    preferenceService.importPreferences(new FileInputStream(new File("myPrefsFile.prefs")));
  }
}


The problem is that the PreferenceInitializer is not called, when I start my application.

Is there something missing in plugin.xml or am I using the wrong extension point?

Thanks again... =)

Re: Use default preferences for a workspace [message #1747413 is a reply to message #1747400] Mon, 14 November 2016 11:50 Go to previous messageGo to next message
Alexander Fichtinger is currently offline Alexander FichtingerFriend
Messages: 62
Registered: January 2013
Member
UPDATE =)

Now my solution is this:

I created an Activator with the following code:

package com.logicals.oemplugin.branding.example;

import java.io.InputStream;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.preferences.*;
import org.osgi.framework.*;

// Copyright (C) logi.cals GmbH. All rights reserved.

public class Activator implements BundleActivator
{
  private static final String BRANDING_PLUGIN_NODE = "example";
  private static final String DEFAULT_PREFERENCES_ALREADY_SET = BRANDING_PLUGIN_NODE + ".defaultPreferencesAlreadySet";

  @Override
  public void start(final BundleContext context)
    throws Exception
  {
    IEclipsePreferences preferences = InstanceScope.INSTANCE.getNode(BRANDING_PLUGIN_NODE);

    if (!preferences.getBoolean(DEFAULT_PREFERENCES_ALREADY_SET, false))
    {
      final InputStream preferencesFileStream = Activator.class.getResourceAsStream("/resources/defaultPreferences.epf");
      Platform.getPreferencesService().importPreferences(preferencesFileStream);
    }

    preferences = InstanceScope.INSTANCE.getNode(BRANDING_PLUGIN_NODE);
    preferences.putBoolean(DEFAULT_PREFERENCES_ALREADY_SET, true);
    preferences.flush();
  }

  @Override
  public void stop(final BundleContext context)
    throws Exception
  {
  }
}


The workflow is the following:
- Customer sets his requested default preferences.
- He exports it to an .epf-file
- This file is used in the Activator.
- Preferences are set to default if the workspace is used for the first time.

I think this is a very easy and convenient way for our customer to achieve what he wants.

@Brian: Do you see any advantage in using a PreferenceInitializer?







Re: Use default preferences for a workspace [message #1748423 is a reply to message #1747413] Wed, 23 November 2016 01:01 Go to previous message
Brian de Alwis is currently offline Brian de AlwisFriend
Messages: 788
Registered: January 2012
Senior Member

Your usecase might actually be a better use of the org.eclipse.ui.startup extension point.

The problem with using a bundle activator is that it requires that bundle to be somehow activated. So you have to be very certain that there is no circumstance where your customer can launch the application and somehow not trigger this bundle.


Eclipse Platform committer. Ask me about Eclipse support, training, and consulting.
Previous Topic:Eclipse RCP Project to RAP Convert
Next Topic:Get previous selection after disable and enable radio drop down menu in Eclipse 3.7 RCP
Goto Forum:
  


Current Time: Mon Nov 19 06:47:14 GMT 2018

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

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

Back to the top