RSS

Search Engine

Tuesday, July 6, 2010

Preferences

1.1. Overview

Eclipse represents user settings via preferences. Eclipse preferences (org.osgi.service.prefs.Preferences) are very similar to java.utils.prefs.Preferences with some support of additional features. See Java Prerefrenses for an overview of java.utils.prefs.Preferences.

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. 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.

Eclipse Preferences use the Eclipse framework to save and retrieve data hence making is easy to re-use this.

The 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.

1.2. Preference Page

Preference Pages allow to modify / display the user / system settings. They have to implement the extension point org.eclipse.ui.preferencePages.

The 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.

1.3. Pre-requisite for the examples

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 Eclipse RCP

for information on this. Eclipse Command provides additional information around Eclipse Commands.

0 comments:

Post a Comment