Class FieldEditor
- Direct Known Subclasses:
- AbstractEncodingFieldEditor,- BooleanFieldEditor,- ColorFieldEditor,- ComboFieldEditor,- FontFieldEditor,- ListEditor,- RadioGroupFieldEditor,- ScaleFieldEditor,- StringFieldEditor
A field editor presents the value of a preference to the end user. The value is loaded from a preference store; if modified by the end user, the value is validated and eventually stored back to the preference store. A field editor reports an event when the value, or the validity of the value, changes.
 Field editors should be used in conjunction with a field editor preference
 page (FieldEditorPreferencePage) which coordinates everything
 and provides the message line which display messages emanating from the
 editor.
 
This package contains ready-to-use field editors for various types of preferences:
- BooleanFieldEditor- booleans
- IntegerFieldEditor- integers
- StringFieldEditor- text strings
- RadioGroupFieldEditor- enumerations
- ColorFieldEditor- RGB colors
- FontFieldEditor- fonts
- DirectoryFieldEditor- directories
- FileFieldEditor- files
- PathEditor- paths
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected static final intGap between label and control.static final StringProperty name constant (value"field_editor_is_valid") to signal a change in the validity of the value of this field editor.static final StringProperty name constant (value"field_editor_value") to signal a change in the value of this field editor.
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCreates a new field editor.protectedFieldEditor(String name, String labelText, Composite parent) Creates a new field editor.
- 
Method SummaryModifier and TypeMethodDescriptionprotected abstract voidadjustForNumColumns(int numColumns) Adjusts the horizontal span of this field editor's basic controls.protected voidApplies a font.protected voidcheckParent(Control control, Composite parent) Checks if the given parent is the current parent of the supplied control; throws an (unchecked) exception if they are not correctly related.protected voidClears the error message from the message line.protected voidClears the normal message from the message line.protected intconvertHorizontalDLUsToPixels(Control control, int dlus) Returns the number of pixels corresponding to the given number of horizontal dialog units.protected intconvertVerticalDLUsToPixels(Control control, int dlus) Returns the number of pixels corresponding to the given number of vertical dialog units.protected voidcreateControl(Composite parent) Creates this field editor's main control containing all of its basic controls.voiddispose()Disposes the SWT resources used by this field editor.protected abstract voiddoFillIntoGrid(Composite parent, int numColumns) Fills this field editor's basic controls into the given parent.protected abstract voiddoLoad()Initializes this field editor with the preference value from the preference store.protected abstract voidInitializes this field editor with the default preference value from the preference store.protected abstract voiddoStore()Stores the preference value from this field editor into the preference store.voidfillIntoGrid(Composite parent, int numColumns) Fills this field editor's basic controls into the given parent.protected voidfireStateChanged(String property, boolean oldValue, boolean newValue) Informs this field editor's listener, if it has one, about a change to one of this field editor's boolean-valued properties.protected voidfireValueChanged(String property, Object oldValue, Object newValue) Informs this field editor's listener, if it has one, about a change to one of this field editor's properties.Returns the symbolic font name used by this field editor.protected LabelReturns the label control.getLabelControl(Composite parent) Returns this field editor's label component.Returns this field editor's label text.abstract intReturns the number of basic controls this field editor consists of.protected DialogPagegetPage()Return the DialogPage that the receiver is sending updates to.Returns the name of the preference this field editor operates on.protected PreferencePageDeprecated.use #getPage()Returns the preference store used by this field editor.protected voidInitialize the field editor with the given preference name and label.booleanisValid()Returns whether this field editor contains a valid value.voidload()Initializes this field editor with the preference value from the preference store.voidInitializes this field editor with the default preference value from the preference store.booleanReturns whether this field editor currently presents the default value for its preference.protected voidRefreshes this field editor's valid state after a value change and fires anIS_VALIDproperty change event if warranted.protected voidsetButtonLayoutData(Button button) Set the GridData on button to be one that is spaced for the current font.voidsetEnabled(boolean enabled, Composite parent) Set whether or not the controls in the field editor are enabled.voidsetFocus()Sets the focus to this field editor.voidsetLabelText(String text) Sets this field editor's label text.voidsetPage(DialogPage dialogPage) Set the page to be the receiver.voidsetPreferenceName(String name) Sets the name of the preference this field editor operates on.voidsetPreferencePage(PreferencePage preferencePage) Deprecated.use #setPage(DialogPage)voidSets the preference store used by this field editor.protected voidsetPresentsDefaultValue(boolean booleanValue) Sets whether this field editor is presenting the default value.voidSets or removes the property change listener for this field editor.protected voidshowErrorMessage(String msg) Shows the given error message in the page for this field editor if it has one.protected voidshowMessage(String msg) Shows the given message in the page for this field editor if it has one.voidstore()Stores this field editor's value back into the preference store.
- 
Field Details- 
IS_VALIDProperty name constant (value"field_editor_is_valid") to signal a change in the validity of the value of this field editor.- See Also:
 
- 
VALUEProperty name constant (value"field_editor_value") to signal a change in the value of this field editor.- See Also:
 
- 
HORIZONTAL_GAPprotected static final int HORIZONTAL_GAPGap between label and control.- See Also:
 
 
- 
- 
Constructor Details- 
FieldEditorprotected FieldEditor()Creates a new field editor.
- 
FieldEditorCreates a new field editor.- Parameters:
- name- the name of the preference this field editor works on
- labelText- the label text of the field editor
- parent- the parent of the field editor's control
 
 
- 
- 
Method Details- 
adjustForNumColumnsprotected abstract void adjustForNumColumns(int numColumns) Adjusts the horizontal span of this field editor's basic controls.Subclasses must implement this method to adjust the horizontal span of controls so they appear correct in the given number of columns. The number of columns will always be equal to or greater than the value returned by this editor's getNumberOfControlsmethod.- Parameters:
- numColumns- the number of columns
 
- 
applyFontprotected void applyFont()Applies a font.The default implementation of this framework method does nothing. Subclasses should override this method if they want to change the font of the SWT control to a value different than the standard dialog font. 
- 
checkParentChecks if the given parent is the current parent of the supplied control; throws an (unchecked) exception if they are not correctly related.- Parameters:
- control- the control
- parent- the parent control
 
- 
clearErrorMessageprotected void clearErrorMessage()Clears the error message from the message line.
- 
clearMessageprotected void clearMessage()Clears the normal message from the message line.
- 
convertHorizontalDLUsToPixelsReturns the number of pixels corresponding to the given number of horizontal dialog units.Clients may call this framework method, but should not override it. - Parameters:
- control- the control being sized
- dlus- the number of horizontal dialog units
- Returns:
- the number of pixels
 
- 
convertVerticalDLUsToPixelsReturns the number of pixels corresponding to the given number of vertical dialog units.Clients may call this framework method, but should not override it. - Parameters:
- control- the control being sized
- dlus- the number of vertical dialog units
- Returns:
- the number of pixels
 
- 
createControlCreates this field editor's main control containing all of its basic controls.- Parameters:
- parent- the parent control
 
- 
disposepublic void dispose()Disposes the SWT resources used by this field editor.
- 
doFillIntoGridFills this field editor's basic controls into the given parent.Subclasses must implement this method to create the controls for this field editor. Note this method may be called by the constructor, so it must not access fields on the receiver object because they will not be fully initialized. - Parameters:
- parent- the composite used as a parent for the basic controls; the parent's layout must be a- GridLayout
- numColumns- the number of columns
 
- 
doLoadprotected abstract void doLoad()Initializes this field editor with the preference value from the preference store.Subclasses must implement this method to properly initialize the field editor. 
- 
doLoadDefaultprotected abstract void doLoadDefault()Initializes this field editor with the default preference value from the preference store.Subclasses must implement this method to properly initialize the field editor. 
- 
doStoreprotected abstract void doStore()Stores the preference value from this field editor into the preference store.Subclasses must implement this method to save the entered value into the preference store. 
- 
fillIntoGridFills this field editor's basic controls into the given parent.- Parameters:
- parent- the composite used as a parent for the basic controls; the parent's layout must be a- GridLayout
- numColumns- the number of columns
 
- 
fireStateChangedInforms this field editor's listener, if it has one, about a change to one of this field editor's boolean-valued properties. Does nothing if the old and new values are the same.- Parameters:
- property- the field editor property name, such as- VALUEor- IS_VALID
- oldValue- the old value
- newValue- the new value
 
- 
fireValueChangedInforms this field editor's listener, if it has one, about a change to one of this field editor's properties.- Parameters:
- property- the field editor property name, such as- VALUEor- IS_VALID
- oldValue- the old value object, or- null
- newValue- the new value, or- null
 
- 
getFieldEditorFontNameReturns the symbolic font name used by this field editor.- Returns:
- the symbolic font name
 
- 
getLabelControlReturns the label control.- Returns:
- the label control, or nullif no label control has been created
 
- 
getLabelControlReturns this field editor's label component.The label is created if it does not already exist - Parameters:
- parent- the parent
- Returns:
- the label control
 
- 
getLabelTextReturns this field editor's label text.- Returns:
- the label text
 
- 
getNumberOfControlspublic abstract int getNumberOfControls()Returns the number of basic controls this field editor consists of.- Returns:
- the number of controls
 
- 
getPreferenceNameReturns the name of the preference this field editor operates on.- Returns:
- the name of the preference
 
- 
getPreferencePageDeprecated.use #getPage()Returns the preference page in which this field editor appears.- Returns:
- the preference page, or nullif none
 
- 
getPageReturn the DialogPage that the receiver is sending updates to.- Returns:
- DialogPage or nullif it has not been set.
- Since:
- 3.1
 
- 
getPreferenceStoreReturns the preference store used by this field editor.- Returns:
- the preference store, or nullif none
- See Also:
 
- 
initInitialize the field editor with the given preference name and label.- Parameters:
- name- the name of the preference this field editor works on
- text- the label text of the field editor
 
- 
isValidpublic boolean isValid()Returns whether this field editor contains a valid value.The default implementation of this framework method returns true. Subclasses wishing to perform validation should override both this method andrefreshValidState.- Returns:
- trueif the field value is valid, and- falseif invalid
- See Also:
 
- 
loadpublic void load()Initializes this field editor with the preference value from the preference store.
- 
loadDefaultpublic void loadDefault()Initializes this field editor with the default preference value from the preference store.
- 
presentsDefaultValuepublic boolean presentsDefaultValue()Returns whether this field editor currently presents the default value for its preference.- Returns:
- trueif the default value is presented, and- falseotherwise
 
- 
refreshValidStateprotected void refreshValidState()Refreshes this field editor's valid state after a value change and fires anIS_VALIDproperty change event if warranted.The default implementation of this framework method does nothing. Subclasses wishing to perform validation should override both this method and isValid.- See Also:
 
- 
setFocuspublic void setFocus()Sets the focus to this field editor.The default implementation of this framework method does nothing. Subclasses may reimplement. 
- 
setLabelTextSets this field editor's label text. The label is typically presented to the left of the entry field.- Parameters:
- text- the label text
 
- 
setPreferenceNameSets the name of the preference this field editor operates on.The ability to change this allows the same field editor object to be reused for different preferences. For example: ... editor.setPreferenceName("font"); editor.load();- Parameters:
- name- the name of the preference
 
- 
setPreferencePageDeprecated.use #setPage(DialogPage)Sets the preference page in which this field editor appears.- Parameters:
- preferencePage- the preference page, or- nullif none
 
- 
setPageSet the page to be the receiver.- Parameters:
- dialogPage- the new receiver
- Since:
- 3.1
 
- 
setPreferenceStoreSets the preference store used by this field editor.- Parameters:
- store- the preference store, or- nullif none
- See Also:
 
- 
setPresentsDefaultValueprotected void setPresentsDefaultValue(boolean booleanValue) Sets whether this field editor is presenting the default value.- Parameters:
- booleanValue-- trueif the default value is being presented, and- falseotherwise
 
- 
setPropertyChangeListenerSets or removes the property change listener for this field editor.Note that field editors can support only a single listener. - Parameters:
- listener- a property change listener, or- nullto remove
 
- 
showErrorMessageShows the given error message in the page for this field editor if it has one.- Parameters:
- msg- the error message
 
- 
showMessageShows the given message in the page for this field editor if it has one.- Parameters:
- msg- the message
 
- 
storepublic void store()Stores this field editor's value back into the preference store.
- 
setButtonLayoutDataSet the GridData on button to be one that is spaced for the current font.- Parameters:
- button- the button the data is being set on.
 
- 
setEnabledSet whether or not the controls in the field editor are enabled.- Parameters:
- enabled- The enabled state.
- parent- The parent of the controls in the group. Used to create the controls if required.
 
 
-