The FieldEditorPreferencePage
supports other types of field editor. These different types of editor include
BooleanFieldEditor
,
ColorFieldEditor
, ScaleFieldEditor
,
FileFieldEditor
,
DirectoryFieldEditor
,
PathEditor
, and
RadioGroupFieldEditor
. Add a sample of each of these types to the ClockPreferencePage
page to find out what they can store. Perform the following steps:
createFieldEditors()
method of the ClockPreferencePage
and add the following code at the bottom of the method:addField(new BooleanFieldEditor("tick","Boolean value",getFieldEditorParent())); addField(new ColorFieldEditor("colour", "Favourite colour",getFieldEditorParent())); addField(new ScaleFieldEditor("scale", "Scale",getFieldEditorParent(), 0, 360, 10, 90)); addField(new FileFieldEditor("file", "Pick a file",getFieldEditorParent())); addField(new DirectoryFieldEditor("dir", "Pick a directory",getFieldEditorParent())); addField(new PathEditor("path","Path","Directory",getFieldEditorParent())); addField(new RadioGroupFieldEditor("group", "Radio choices", 3,data,getFieldEditorParent(),true));
This change added different types of standard field editors provided by the JFace package, to give a flavor of the types of data entry element that can be shown.
Some of the editors are specific to the kinds of entry points that are used in Eclipse itself, such as file, directory, or path editors. Others are more general such as colour, scale, boolean, or radio choices.
The values are persisted in the preferences format in a text values, appropriate to the data type. To see where the values are written to, go to the runtime-EclipseApplication/.metadata/.plugins/org.eclipse.core.runtime/.settings/com.packtpub.e4.clock.ui.prefs
file. The contents look similar to the following code:
colour=49,241,180 eclipse.preferences.version=1 favourite=Europe/Milton_Keynes group=Europe/Milton_Keynes launchCount=28 scale=78 tick=true
The persisted colour value is stored as a red/green/blue triple, while the boolean value is stored as a true
or false
value.