Class StringFieldEditor
- Direct Known Subclasses:
IntegerFieldEditor
,StringButtonFieldEditor
This class may be used as is, or subclassed as required.
-
Field Summary
Modifier and TypeFieldDescriptionprotected String
Old text value.static int
Text limit constant (value-1
) indicating unlimited text limit and width.static final int
Validation strategy constant (value1
) indicating that the editor should perform validation only when the text widget loses focus.static final int
Validation strategy constant (value0
) indicating that the editor should perform validation after every key stroke.Fields inherited from class org.eclipse.jface.preference.FieldEditor
HORIZONTAL_GAP, IS_VALID, VALUE
-
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a new string field editorStringFieldEditor
(String name, String labelText, int widthInChars, int heigthInChars, int strategy, Composite parent) Creates a string field editor.StringFieldEditor
(String name, String labelText, int width, int strategy, Composite parent) Creates a string field editor.StringFieldEditor
(String name, String labelText, int width, Composite parent) Creates a string field editor.StringFieldEditor
(String name, String labelText, Composite parent) Creates a string field editor of unlimited width. -
Method Summary
Modifier and TypeMethodDescriptionprotected void
adjustForNumColumns
(int numColumns) Adjusts the horizontal span of this field editor's basic controls.protected boolean
Checks whether the text input field contains a valid value or not.protected Text
createTextWidget
(Composite parent) Create the text widget.protected boolean
Hook for subclasses to do specific state checks.protected void
doFillIntoGrid
(Composite parent, int numColumns) Fills this field editor's basic controls into the given parent.protected void
doLoad()
Initializes this field editor with the preference value from the preference store.protected void
Initializes this field editor with the default preference value from the preference store.protected void
doStore()
Stores the preference value from this field editor into the preference store.Returns the error message that will be displayed when and if an error occurs.int
Returns the number of basic controls this field editor consists of.Returns the field editor's value.protected Text
Returns this field editor's text control.getTextControl
(Composite parent) Returns this field editor's text control.boolean
Returns whether an empty string is a valid value.boolean
isValid()
Returns whether this field editor contains a valid value.protected void
Refreshes this field editor's valid state after a value change and fires anIS_VALID
property change event if warranted.void
setEmptyStringAllowed
(boolean b) Sets whether the empty string is a valid value or not.void
setEnabled
(boolean enabled, Composite parent) Set whether or not the controls in the field editor are enabled.void
setErrorMessage
(String message) Sets the error message that will be displayed when and if an error occurs.void
setFocus()
Sets the focus to this field editor.void
setStringValue
(String value) Sets this field editor's value.void
setTextLimit
(int limit) Sets this text field's text limit.void
setValidateStrategy
(int value) Sets the strategy for validating the text.void
Shows the error message set viasetErrorMessage
.protected void
Informs this field editor's listener, if it has one, about a change to the value (VALUE
property) provided that the old and new values are different.Methods inherited from class org.eclipse.jface.preference.FieldEditor
applyFont, checkParent, clearErrorMessage, clearMessage, convertHorizontalDLUsToPixels, convertVerticalDLUsToPixels, createControl, dispose, fillIntoGrid, fireStateChanged, fireValueChanged, getFieldEditorFontName, getLabelControl, getLabelControl, getLabelText, getPage, getPreferenceName, getPreferencePage, getPreferenceStore, init, load, loadDefault, presentsDefaultValue, setButtonLayoutData, setLabelText, setPage, setPreferenceName, setPreferencePage, setPreferenceStore, setPresentsDefaultValue, setPropertyChangeListener, showErrorMessage, showMessage, store
-
Field Details
-
VALIDATE_ON_KEY_STROKE
public static final int VALIDATE_ON_KEY_STROKEValidation strategy constant (value0
) indicating that the editor should perform validation after every key stroke. -
VALIDATE_ON_FOCUS_LOST
public static final int VALIDATE_ON_FOCUS_LOSTValidation strategy constant (value1
) indicating that the editor should perform validation only when the text widget loses focus. -
UNLIMITED
public static int UNLIMITEDText limit constant (value-1
) indicating unlimited text limit and width. -
oldValue
Old text value.- Since:
- 3.4 this field is protected.
-
-
Constructor Details
-
StringFieldEditor
protected StringFieldEditor()Creates a new string field editor -
StringFieldEditor
public StringFieldEditor(String name, String labelText, int widthInChars, int heigthInChars, int strategy, Composite parent) Creates a string field editor. Use the methodsetTextLimit
to limit the text.- Parameters:
name
- the name of the preference this field editor works onlabelText
- the label text of the field editorwidthInChars
- the width of the text input field in characters, orUNLIMITED
for no limitheigthInChars
- the height of the text input field in characters.strategy
- eitherVALIDATE_ON_KEY_STROKE
to perform on the fly checking (the default), orVALIDATE_ON_FOCUS_LOST
to perform validation only after the text has been typed inparent
- the parent of the field editor's control- Since:
- 3.17
-
StringFieldEditor
Creates a string field editor. Use the methodsetTextLimit
to limit the text.- Parameters:
name
- the name of the preference this field editor works onlabelText
- the label text of the field editorwidth
- the width of the text input field in characters, orUNLIMITED
for no limitstrategy
- eitherVALIDATE_ON_KEY_STROKE
to perform on the fly checking (the default), orVALIDATE_ON_FOCUS_LOST
to perform validation only after the text has been typed inparent
- the parent of the field editor's control- Since:
- 2.0
-
StringFieldEditor
Creates a string field editor. Use the methodsetTextLimit
to limit the text.- Parameters:
name
- the name of the preference this field editor works onlabelText
- the label text of the field editorwidth
- the width of the text input field in characters, orUNLIMITED
for no limitparent
- the parent of the field editor's control
-
StringFieldEditor
Creates a string field editor of unlimited width. Use the methodsetTextLimit
to limit the text.- Parameters:
name
- the name of the preference this field editor works onlabelText
- the label text of the field editorparent
- the parent of the field editor's control
-
-
Method Details
-
adjustForNumColumns
protected void adjustForNumColumns(int numColumns) Description copied from class:FieldEditor
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
getNumberOfControls
method.- Specified by:
adjustForNumColumns
in classFieldEditor
- Parameters:
numColumns
- the number of columns
-
checkState
protected boolean checkState()Checks whether the text input field contains a valid value or not.- Returns:
true
if the field value is valid, andfalse
if invalid
-
doCheckState
protected boolean doCheckState()Hook for subclasses to do specific state checks.The default implementation of this framework method does nothing and returns
true
. Subclasses should override this method to specific state checks.- Returns:
true
if the field value is valid, andfalse
if invalid
-
doFillIntoGrid
Fills this field editor's basic controls into the given parent.The string field implementation of this
FieldEditor
framework method contributes the text field. Subclasses may override but must callsuper.doFillIntoGrid
.- Specified by:
doFillIntoGrid
in classFieldEditor
- Parameters:
parent
- the composite used as a parent for the basic controls; the parent's layout must be aGridLayout
numColumns
- the number of columns
-
doLoad
protected void doLoad()Description copied from class:FieldEditor
Initializes this field editor with the preference value from the preference store.Subclasses must implement this method to properly initialize the field editor.
- Specified by:
doLoad
in classFieldEditor
-
doLoadDefault
protected void doLoadDefault()Description copied from class:FieldEditor
Initializes this field editor with the default preference value from the preference store.Subclasses must implement this method to properly initialize the field editor.
- Specified by:
doLoadDefault
in classFieldEditor
-
doStore
protected void doStore()Description copied from class:FieldEditor
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.
- Specified by:
doStore
in classFieldEditor
-
getErrorMessage
Returns the error message that will be displayed when and if an error occurs.- Returns:
- the error message, or
null
if none
-
getNumberOfControls
public int getNumberOfControls()Description copied from class:FieldEditor
Returns the number of basic controls this field editor consists of.- Specified by:
getNumberOfControls
in classFieldEditor
- Returns:
- the number of controls
-
getStringValue
Returns the field editor's value.- Returns:
- the current value
-
getTextControl
Returns this field editor's text control.- Returns:
- the text control, or
null
if no text field is created yet
-
getTextControl
Returns this field editor's text control.The control is created if it does not yet exist
- Parameters:
parent
- the parent- Returns:
- the text control
-
createTextWidget
Create the text widget.- Parameters:
parent
- the parent composite- Returns:
- The widget
- Since:
- 3.17
-
isEmptyStringAllowed
public boolean isEmptyStringAllowed()Returns whether an empty string is a valid value.- Returns:
true
if an empty string is a valid value, andfalse
if an empty string is invalid- See Also:
-
isValid
public boolean isValid()Description copied from class:FieldEditor
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
.- Overrides:
isValid
in classFieldEditor
- Returns:
true
if the field value is valid, andfalse
if invalid- See Also:
-
refreshValidState
protected void refreshValidState()Description copied from class:FieldEditor
Refreshes this field editor's valid state after a value change and fires anIS_VALID
property 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
.- Overrides:
refreshValidState
in classFieldEditor
- See Also:
-
setEmptyStringAllowed
public void setEmptyStringAllowed(boolean b) Sets whether the empty string is a valid value or not.- Parameters:
b
-true
if the empty string is allowed, andfalse
if it is considered invalid
-
setErrorMessage
Sets the error message that will be displayed when and if an error occurs.- Parameters:
message
- the error message
-
setFocus
public void setFocus()Description copied from class:FieldEditor
Sets the focus to this field editor.The default implementation of this framework method does nothing. Subclasses may reimplement.
- Overrides:
setFocus
in classFieldEditor
-
setStringValue
Sets this field editor's value.- Parameters:
value
- the new value, ornull
meaning the empty string
-
setTextLimit
public void setTextLimit(int limit) Sets this text field's text limit.- Parameters:
limit
- the limit on the number of character in the text input field, orUNLIMITED
for no limit
-
setValidateStrategy
public void setValidateStrategy(int value) Sets the strategy for validating the text.Calling this method has no effect after
createPartControl
is called. Thus this method is really only useful for subclasses to call in their constructor. However, it has public visibility for backward compatibility.- Parameters:
value
- eitherVALIDATE_ON_KEY_STROKE
to perform on the fly checking (the default), orVALIDATE_ON_FOCUS_LOST
to perform validation only after the text has been typed in
-
showErrorMessage
public void showErrorMessage()Shows the error message set viasetErrorMessage
. -
valueChanged
protected void valueChanged()Informs this field editor's listener, if it has one, about a change to the value (VALUE
property) provided that the old and new values are different.This hook is not called when the text is initialized (or reset to the default value) from the preference store.
-
setEnabled
Description copied from class:FieldEditor
Set whether or not the controls in the field editor are enabled.- Overrides:
setEnabled
in classFieldEditor
- Parameters:
enabled
- The enabled state.parent
- The parent of the controls in the group. Used to create the controls if required.
-