### Field editors

The implementation of a preference page is primarily SWT code. SWT code is used to create the preference page controls, set the values of the controls, and retrieve the values of the controls. The org.eclipse.jface.preference package provides helper classes, called field editors, that create the widgets and implement the value setting and retrieval code for the most common preference types. The platform provides field editors for displaying and updating many value types, including booleans, colors, strings, integers, fonts, and file names.

FieldEditorPreferencePage implements a page that uses these field editors to display and store the preference values on the page. Instead of creating SWT controls to fill its contents, a FieldEditorPreferencePage subclass creates field editors to display the contents. All of the fields on the page must be implemented as field editors. The following is a snippet from the debug UI preferences page:

    protected void createFieldEditors() {
    	addField(new BooleanFieldEditor(IDebugUIConstants.PREF_BUILD_BEFORE_LAUNCH,
    		DebugPreferencesMessages.getString("DebugPreferencePage.auto_build_before_launch"),
    		SWT.NONE, getFieldEditorParent()));
    	...
    	String[][] perspectiveNamesAndIds = getPerspectiveNamesAndIds();
    	addField(new ComboFieldEditor(IDebugUIConstants.PREF_SHOW_DEBUG_PERSPECTIVE_DEFAULT,
    		DebugPreferencesMessages.getString("DebugPreferencePage.Default_perspective_for_Debug_2"), //$NON-NLS-1$
    		perspectiveNamesAndIds,
    		getFieldEditorParent()));
    	...
    }

Each field editor is assigned the name of its corresponding preference key and the text label for the SWT control that it will create. The kind of control created depends on the type of field editor. For example, a boolean field editor creates a checkbox.

Since the preference page is associated with a preference store (specified in the doGetPreferenceStore method), the code for storing the current values, for initializing the control values from the preference store, and for restoring the controls to their default values can all be implemented in the FieldEditorPreferencePage.

The FieldEditorPreferencePage will use a grid layout with one column as the default layout for field editor widgets. For special layout requirements, you can override the createContents method.