Archive
Posts Tagged ‘rcp’
Eclipse RCP Preferences – Storing & Retrieving values using preferences
December 30, 2011
Leave a comment
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.. 🙂
Categories: eclipse rcp
eclipse rcp, rcp