Home > eclipse rcp > Eclipse RCP Preferences – Storing & Retrieving values using preferences

Eclipse RCP Preferences – Storing & Retrieving values using preferences

Often in the IDE development, we require to store some application specific values. We can make use of eclipse preferences to store and retrieve values.

The Eclipse has three different types of scopes.
Configuration scope
Default scope
Instance scope

The below code snippet shows how we can store and retrieve values using configuration scope:

 
Preferences preferences = ConfigurationScope.INSTANCE.getNode("com.mycomp.client");
Preferences pref = preferences.node("node1");
pref.put("key", "val");
 try
  {
  // Forcing the application to save the preferences
  preferences.flush();
  }
  catch (BackingStoreException e)
  {
    e.printStackTrace();
  }

Retrieving the stored value:


 Preferences preferences = ConfigurationScope.INSTANCE.getNode("com.mycomp.client");
 Preferences pref  = preferences.node("node1");
 String val = pref.get("key", "default");

For further reference you can refer here

Note: Preferences are workspace specific. So If the workspace is changed or deleted then the stored values will be lost.

Happy coding.. 🙂

Advertisements
Categories: eclipse rcp Tags: ,
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: