Class StringFieldEditor
- Direct Known Subclasses:
- IntegerFieldEditor,- StringButtonFieldEditor
This class may be used as is, or subclassed as required.
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected StringOld text value.static intText limit constant (value-1) indicating unlimited text limit and width.static final intValidation strategy constant (value1) indicating that the editor should perform validation only when the text widget loses focus.static final intValidation strategy constant (value0) indicating that the editor should perform validation after every key stroke.Fields inherited from class org.eclipse.jface.preference.FieldEditorHORIZONTAL_GAP, IS_VALID, VALUE
- 
Constructor SummaryConstructorsModifierConstructorDescriptionprotectedCreates 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 SummaryModifier and TypeMethodDescriptionprotected voidadjustForNumColumns(int numColumns) Adjusts the horizontal span of this field editor's basic controls.protected booleanChecks whether the text input field contains a valid value or not.protected TextcreateTextWidget(Composite parent) Create the text widget.protected booleanHook for subclasses to do specific state checks.protected voiddoFillIntoGrid(Composite parent, int numColumns) Fills this field editor's basic controls into the given parent.protected voiddoLoad()Initializes this field editor with the preference value from the preference store.protected voidInitializes this field editor with the default preference value from the preference store.protected voiddoStore()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.intReturns the number of basic controls this field editor consists of.Returns the field editor's value.protected TextReturns this field editor's text control.getTextControl(Composite parent) Returns this field editor's text control.booleanReturns whether an empty string is a valid value.booleanisValid()Returns whether this field editor contains a valid value.protected voidRefreshes this field editor's valid state after a value change and fires anIS_VALIDproperty change event if warranted.voidsetEmptyStringAllowed(boolean b) Sets whether the empty string is a valid value or not.voidsetEnabled(boolean enabled, Composite parent) Set whether or not the controls in the field editor are enabled.voidsetErrorMessage(String message) Sets the error message that will be displayed when and if an error occurs.voidsetFocus()Sets the focus to this field editor.voidsetStringValue(String value) Sets this field editor's value.voidsetTextLimit(int limit) Sets this text field's text limit.voidsetValidateStrategy(int value) Sets the strategy for validating the text.voidShows the error message set viasetErrorMessage.protected voidInforms this field editor's listener, if it has one, about a change to the value (VALUEproperty) provided that the old and new values are different.Methods inherited from class org.eclipse.jface.preference.FieldEditorapplyFont, 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_STROKEpublic static final int VALIDATE_ON_KEY_STROKEValidation strategy constant (value0) indicating that the editor should perform validation after every key stroke.- See Also:
 
- 
VALIDATE_ON_FOCUS_LOSTpublic static final int VALIDATE_ON_FOCUS_LOSTValidation strategy constant (value1) indicating that the editor should perform validation only when the text widget loses focus.- See Also:
 
- 
UNLIMITEDpublic static int UNLIMITEDText limit constant (value-1) indicating unlimited text limit and width.
- 
oldValueOld text value.- Since:
- 3.4 this field is protected.
 
 
- 
- 
Constructor Details- 
StringFieldEditorprotected StringFieldEditor()Creates a new string field editor
- 
StringFieldEditorpublic StringFieldEditor(String name, String labelText, int widthInChars, int heigthInChars, int strategy, Composite parent) Creates a string field editor. Use the methodsetTextLimitto limit the text.- Parameters:
- name- the name of the preference this field editor works on
- labelText- the label text of the field editor
- widthInChars- the width of the text input field in characters, or- UNLIMITEDfor no limit
- heigthInChars- the height of the text input field in characters.
- strategy- either- VALIDATE_ON_KEY_STROKEto perform on the fly checking (the default), or- VALIDATE_ON_FOCUS_LOSTto perform validation only after the text has been typed in
- parent- the parent of the field editor's control
- Since:
- 3.17
 
- 
StringFieldEditorCreates a string field editor. Use the methodsetTextLimitto limit the text.- Parameters:
- name- the name of the preference this field editor works on
- labelText- the label text of the field editor
- width- the width of the text input field in characters, or- UNLIMITEDfor no limit
- strategy- either- VALIDATE_ON_KEY_STROKEto perform on the fly checking (the default), or- VALIDATE_ON_FOCUS_LOSTto perform validation only after the text has been typed in
- parent- the parent of the field editor's control
- Since:
- 2.0
 
- 
StringFieldEditorCreates a string field editor. Use the methodsetTextLimitto limit the text.- Parameters:
- name- the name of the preference this field editor works on
- labelText- the label text of the field editor
- width- the width of the text input field in characters, or- UNLIMITEDfor no limit
- parent- the parent of the field editor's control
 
- 
StringFieldEditorCreates a string field editor of unlimited width. Use the methodsetTextLimitto limit the text.- 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 void adjustForNumColumns(int numColumns) Description copied from class:FieldEditorAdjusts 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.- Specified by:
- adjustForNumColumnsin class- FieldEditor
- Parameters:
- numColumns- the number of columns
 
- 
checkStateprotected boolean checkState()Checks whether the text input field contains a valid value or not.- Returns:
- trueif the field value is valid, and- falseif invalid
 
- 
doCheckStateprotected 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:
- trueif the field value is valid, and- falseif invalid
 
- 
doFillIntoGridFills this field editor's basic controls into the given parent.The string field implementation of this FieldEditorframework method contributes the text field. Subclasses may override but must callsuper.doFillIntoGrid.- Specified by:
- doFillIntoGridin class- FieldEditor
- 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 void doLoad()Description copied from class:FieldEditorInitializes this field editor with the preference value from the preference store.Subclasses must implement this method to properly initialize the field editor. - Specified by:
- doLoadin class- FieldEditor
 
- 
doLoadDefaultprotected void doLoadDefault()Description copied from class:FieldEditorInitializes 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:
- doLoadDefaultin class- FieldEditor
 
- 
doStoreprotected void doStore()Description copied from class:FieldEditorStores 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:
- doStorein class- FieldEditor
 
- 
getErrorMessageReturns the error message that will be displayed when and if an error occurs.- Returns:
- the error message, or nullif none
 
- 
getNumberOfControlspublic int getNumberOfControls()Description copied from class:FieldEditorReturns the number of basic controls this field editor consists of.- Specified by:
- getNumberOfControlsin class- FieldEditor
- Returns:
- the number of controls
 
- 
getStringValueReturns the field editor's value.- Returns:
- the current value
 
- 
getTextControlReturns this field editor's text control.- Returns:
- the text control, or nullif no text field is created yet
 
- 
getTextControlReturns this field editor's text control.The control is created if it does not yet exist - Parameters:
- parent- the parent
- Returns:
- the text control
 
- 
createTextWidgetCreate the text widget.- Parameters:
- parent- the parent composite
- Returns:
- The widget
- Since:
- 3.17
 
- 
isEmptyStringAllowedpublic boolean isEmptyStringAllowed()Returns whether an empty string is a valid value.- Returns:
- trueif an empty string is a valid value, and- falseif an empty string is invalid
- See Also:
 
- 
isValidpublic boolean isValid()Description copied from class:FieldEditorReturns 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:
- isValidin class- FieldEditor
- Returns:
- trueif the field value is valid, and- falseif invalid
- See Also:
 
- 
refreshValidStateprotected void refreshValidState()Description copied from class:FieldEditorRefreshes 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.- Overrides:
- refreshValidStatein class- FieldEditor
- See Also:
 
- 
setEmptyStringAllowedpublic void setEmptyStringAllowed(boolean b) Sets whether the empty string is a valid value or not.- Parameters:
- b-- trueif the empty string is allowed, and- falseif it is considered invalid
 
- 
setErrorMessageSets the error message that will be displayed when and if an error occurs.- Parameters:
- message- the error message
 
- 
setFocuspublic void setFocus()Description copied from class:FieldEditorSets the focus to this field editor.The default implementation of this framework method does nothing. Subclasses may reimplement. - Overrides:
- setFocusin class- FieldEditor
 
- 
setStringValueSets this field editor's value.- Parameters:
- value- the new value, or- nullmeaning the empty string
 
- 
setTextLimitpublic 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, or- UNLIMITEDfor no limit
 
- 
setValidateStrategypublic void setValidateStrategy(int value) Sets the strategy for validating the text.Calling this method has no effect after createPartControlis 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- either- VALIDATE_ON_KEY_STROKEto perform on the fly checking (the default), or- VALIDATE_ON_FOCUS_LOSTto perform validation only after the text has been typed in
 
- 
showErrorMessagepublic void showErrorMessage()Shows the error message set viasetErrorMessage.
- 
valueChangedprotected void valueChanged()Informs this field editor's listener, if it has one, about a change to the value (VALUEproperty) 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. 
- 
setEnabledDescription copied from class:FieldEditorSet whether or not the controls in the field editor are enabled.- Overrides:
- setEnabledin class- FieldEditor
- Parameters:
- enabled- The enabled state.
- parent- The parent of the controls in the group. Used to create the controls if required.
 
 
-