Time for action: using other field editors

The FieldEditorPreferencePage supports other types of field editors. These different types include BooleanFieldEditor, ColorFieldEditor, ScaleFieldEditor, FileFieldEditor, DirectoryFieldEditor, PathEditor, and RadioGroupFieldEditor. Add a sample of each of these types to the Clock preference page to find out what they can store.

  1. Open the createFieldEditors method of ClockPreferencePage and add the following at the bottom of the method:
    addField(new BooleanFieldEditor("tick", "Boolean value",
    getFieldEditorParent()));
    addField(new ColorFieldEditor("color", "Favorite color",
    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));
  2. Run the target Eclipse instance, and go to the Clock preference page. It will look like this:
    Time for action: using other field editors

What just happened?

This change added different types of standard field editors provided by the JFace package, to give a flavor of the types of data entry elements 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 color, scale, boolean, or radio choices.

The values are persisted in the preferences format as text values, appropriate to the data type. To see what 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 like this:

color=49,241,180
eclipse.preferences.version=1
favorite=Europe/Milton_Keynes
group=Europe/Milton_Keynes
launchCount=28
scale=78
tick=true

The persisted color value is stored as a red/green/blue triple, while the boolean value is stored as a true or false value.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.19.56.114