| Free tutorials for Java, Eclipse and Web programming |
Version 1.1
Copyright © 2009 - 2011 Lars Vogel
29.03.2011
| Revision History | ||
|---|---|---|
| Revision 0.1 | 25.06.2009 | Lars Vogel |
| Created | ||
| Revision 0.2 - 1.01 | 15.09.2010 - 29.03.2011 | Lars Vogel |
| bug fixes and enhancements | ||
Table of Contents
Preferences are key / values pairs where the key is an arbitrary name for the preference. The value can be a boolean, string, int of another primitive type. Eclipse Preferences (org.osgi.service.prefs.Preferences) allow to save plugin specific configuration values.
Eclipse Preferences are very similar to Java Preferences with some support of additional features. They use the Eclipse framework to save and retrieve the configuration. Preferences are received and saved by get and put methods while the get methods also supply a default value in case the preferences is not yet set.
The Eclipse runtime defines three so-called scopes. The scope defines how the preference data is stored and how is is changeable.
Instance scope: If the user runs the same program twice the settings between the two programs may be different.
Configuration scope: If the user runs the same program twice then the settings between the two programs are the same.
Default scope: Default values which can not be changed. Supplied via configuration files in plugins and product definitions.
While you can create and manipulate preferences directly in your coding Eclipse provides an standard way for the user to maintain these values. Preference Pages are the default for doing this. Preference pages are declared via the extension point "org.eclipse.ui.preferencePages". Each preference page defines are class which is responsible for maintaining the preference values. This class must implement IWorkbenchPreferencePage and must have a non-parameter constructor. The class PreferencePage or one of its subclasses can get extended, a good template is usually FieldEditor PreferencePage.
To show the Preference dialog you can use the standard command "org.eclipse.ui.window.preferences".
The following assumes that you know how to create simple Eclipse RCP applications and that you know how to create commands and add them to the menu. Please see the Eclipse RCP and the Eclipse Commands tutorials .