Although preferences can be stored, providing a user interface is necessary for end users. A preference page implements the IPreferencePage
interface. The easiest way is to use FieldEditorPreferencePage
as a super class, which provides most of the standard plug-in behavior needed. Perform the following steps:
plugin.xml
of the clock.ui
plug-in. In order to declare a new preference page, use the org.eclipse.ui.preferencePages
extension point. Add the following code:<extension point="org.eclipse.ui.preferencePages"><page name="Clock"class="com.packtpub.e4.clock.ui.ClockPreferencePage"id="com.packtpub.e4.clock.ui.preference.page"/> </extension>
plugin.xml
in the editor and clicking on Add in the Extensions tab and selecting the preferencePages extension point.ClockPreferencePage
that extends FieldEditorPreferencePage
in the com.packtpub.e4.clock.ui
package as follows:public class ClockPreferencePage extends FieldEditorPreferencePageimplements IWorkbenchPreferencePage { protected void createFieldEditors() { } public void init(IWorkbench workbench) { } }
IntegerFieldEditor
for storing the launch count by adding it to the createFieldEditors()
method as follows:protected void createFieldEditors() { addField(new IntegerFieldEditor("launchCount", "Number of times it has been launched",getFieldEditorParent())); }
FieldEditorPreferencePage
needs to be connected to the plug-in's PreferenceStore
as follows:public void init(IWorkbench workbench){ setPreferenceStore( Activator.getDefault().getPreferenceStore()); }
The preferences page was created and connected to the preferences window and the correct preference store (obtained from the plug-in's Activator
). Instances of FieldEditor
were added to display properties on a per-property basis.
The implementation of getFieldEditorParent()
is something that needs to be called each time a field editor is created. It might be tempting to refactor this into a common variable, but the JavaDoc says that the value cannot be cached. If the FLAT
style is used, then it will create a new instance of the parent each time it is called.