![]() | The Java Developer's Guide to Eclipse |
Chapter 17, Dialog Settings, Preferences, and User Settings, presented
the many options for storing keyed values as part of the
Eclipse platform. You learned how to initialize defaults and use either the
PreferenceStore, Preferences, or user settings APIs to get and set stored
values.
The example in the com.ibm.jdg2e.usersettings project
demonstrates the basic techniques for how stored values can be accessed from a preference page,
property page, or elsewhere in your plug-in. In doing so, this example also serves as a demonstration of
how a preference page, property page, and preference initializer can be implemented.
This example is best run as a project in a test workspace. This is because you are manipulating stored values that need to be cleared to reset the testing cycle. This is easy when launching the runtime Workbench for testing, but harder to do if the plug-in is installed.
First, setup the launch configuration to both clear the configuration area and start with a new workspace by doing the following.
Second, find each component of the example:

The values for two keys are shown in this view. Each value instance represents a different type of call for the given key. The Default, Configuration, Instance, and Project values represent direct calls to a specific node. For Key 1 the defined default is used as the default-default value. For Key 2 a hard-coded default-default value is used. The Cascaded Project value is the result of reading the key through a sequence of nodes (project, instance, configuration, default).

The preference page displays two keyed values that can be modified. If modified the instance values for the keys are changed. Leave them as-is for now.
The initial value for Key 1 is set using the preference store API (instance level) in the preference initializer defined by extension in the plug-in's manifest file. The Key 2 value is set as part of the preference page logic. It is now different than what was originally displayed in the view.

The Configuration, Instance, and Project values for each key can be modified here.
Note: The runtime Workbench mimics the behavior of an installed version of Eclipse by keeping user settings information around between launches. Working from the bottom up, each plug-in has a file for their settings in an appropriate location.
[project]/.settings).
.metadata/.plugins/org.eclipse.core.runtime).
eclipse/configuration/.settings). During testing these are managed by the Plug-in Development
Environment and are hidden in the state directory for the org.eclipse.core.pde plug-in. Check you
active workspace and its .metadata directory to hunt them down.
The User Settings API Demonstration plug-in is designed to show the behavior of the user settings API in various circumstances. The preference page, property page, and view user interfaces are designed to expose values in certain circumstances and let you better understand the scope of a given node for storing keyed values.
The plug-in manifest file includes the extension definitions
for the preference page, property page, and view and an extension
for the runtime preference initializer that is called when the plug-in is activated.
The table below contains the key classes from the com.ibm.jdg2e.usersettings
package that are used to implement the user interface and user settings control logic.
| Class (All) | Description |
CommonSettingsUI |
Reusable component for the UI shown in the view, preference page, and property page. |
SettingsView |
This class implements the view's user interface and function. |
PreferencePageSettingsDemo |
Preference page implementation that includes localized default value initialization and support for Instance value modification (uses Preference Store API). |
PropertyPageSettingsDemo |
Property page implementation that includes ability to modify Configuration, Instance, and Project nodes for the supported keyed values. |
ValueDefaults |
Runtime Preference Initializer as identified by extension for this plug-in. |
© Copyright International Business Machines Corporation, 2003, 2004, 2006. All Rights Reserved.
Code or samples provided herein are provided without warranty of any kind.