java.lang.Object
com.dlsc.formsfx.model.structure.Element<F>
com.dlsc.formsfx.model.structure.Field<F>
- All Implemented Interfaces:
FormElement
- Direct Known Subclasses:
DataField,SelectionField
public abstract class Field<F extends Field<F>> extends Element<F> implements FormElement
This class provides the base implementation for a FormsFX field. It is not
meant to be used directly, but instead acts as a base for concrete
implementations.
A field is the smallest unit of the form. It contains only the value and
relevant information.
- Author:
- Sacha Schmid, Rinesch Murugathas
-
Property Summary
Properties Type Property Description javafx.beans.property.BooleanPropertychangedjavafx.beans.property.BooleanPropertyeditablejavafx.beans.property.ListProperty<String>errorMessagesThe results of the field's validation is stored in this property.javafx.beans.property.StringPropertylabelThe label acts as a description for the field.javafx.beans.property.StringPropertyplaceholderThe placeholder is only visible in an empty field.javafx.beans.property.BooleanPropertyrequiredjavafx.beans.property.StringPropertytooltipThe tooltip is an extension of the label.javafx.beans.property.BooleanPropertyvalidThe field's current state is represented by the value properties, as well as by thevalidandchangedflags. -
Field Summary
Fields Modifier and Type Field Description protected javafx.beans.InvalidationListenerbindingModeListenerWith the continuous binding mode, values are always directly persisted upon any changes.protected javafx.beans.property.BooleanPropertychangedprotected javafx.beans.property.BooleanPropertyeditableprotected javafx.beans.property.ListProperty<String>errorMessageKeysprotected javafx.beans.property.ListProperty<String>errorMessagesThe results of the field's validation is stored in this property.protected Map<javafx.event.EventType<FieldEvent>,List<javafx.event.EventHandler<? super FieldEvent>>>eventHandlersprotected javafx.beans.property.StringPropertyidFields can be styled using CSS through ID or class hooks.protected javafx.beans.property.StringPropertylabelThe label acts as a description for the field.protected javafx.beans.property.StringPropertylabelKeyprotected javafx.beans.property.StringPropertyplaceholderThe placeholder is only visible in an empty field.protected javafx.beans.property.StringPropertyplaceholderKeyprotected SimpleControl<F>rendererprotected Supplier<SimpleControl<F>>rendererSupplierprotected javafx.beans.property.BooleanPropertyrequiredprotected javafx.beans.property.StringPropertyrequiredErrorprotected javafx.beans.property.StringPropertyrequiredErrorKeyEvery field can be marked asrequiredandeditable.protected javafx.beans.property.IntegerPropertyspanprotected javafx.beans.property.ListProperty<String>styleClassprotected javafx.beans.property.StringPropertytooltipThe tooltip is an extension of the label.protected javafx.beans.property.StringPropertytooltipKeyprotected TranslationServicetranslationServiceThe translation service is passed down from the containing section.protected javafx.beans.property.BooleanPropertyvalidThe field's current state is represented by the value properties, as well as by thevalidandchangedflags. -
Constructor Summary
Constructors Modifier Constructor Description protectedField()Internal constructor for theFieldclass. -
Method Summary
Modifier and Type Method Description FieldaddEventHandler(javafx.event.EventType<FieldEvent> eventType, javafx.event.EventHandler<? super FieldEvent> eventHandler)Registers an event handler to this field.javafx.beans.property.BooleanPropertychangedProperty()Feditable(boolean newValue)Sets the editable property of the current field.javafx.beans.property.BooleanPropertyeditableProperty()javafx.beans.property.ListProperty<String>errorMessagesProperty()The results of the field's validation is stored in this property.protected voidfireEvent(FieldEvent event)List<String>getErrorMessages()Gets the value of the property errorMessages.StringgetLabel()Gets the value of the property label.javafx.scene.NodegetLabelDescription()StringgetPlaceholder()Gets the value of the property placeholder.SimpleControl<F>getRenderer()StringgetTooltip()Gets the value of the property tooltip.javafx.scene.NodegetValueDescription()booleanhasChanged()booleanisEditable()Gets the value of the property editable.booleanisI18N()booleanisRequired()Gets the value of the property required.booleanisValid()Gets the value of the property valid.Flabel(String newValue)Sets the label property of the current field.FlabelDescription(String newValue)Sets the label description property of the current field.FlabelDescription(javafx.scene.Node newValue)Sets the label description property of the current field.javafx.beans.property.StringPropertylabelProperty()The label acts as a description for the field.static BooleanFieldofBooleanType(boolean defaultValue)Creates a newBooleanFieldwith the given default value.static BooleanFieldofBooleanType(javafx.beans.property.BooleanProperty binding)Creates a newBooleanFieldwith the given property.static DateFieldofDate(LocalDate defaultValue)Creates a newDateFieldwith given default valuestatic DateFieldofDate(javafx.beans.property.ObjectProperty<LocalDate> binding)Creates a newDateFieldwith given propertystatic DoubleFieldofDoubleType(double defaultValue)Creates a newDoubleFieldwith the given default value.static DoubleFieldofDoubleType(javafx.beans.property.DoubleProperty binding)Creates a newDoubleFieldwith the given property.static IntegerFieldofIntegerType(int defaultValue)Creates a newIntegerFieldwith the given default value.static IntegerFieldofIntegerType(javafx.beans.property.IntegerProperty binding)Creates a newIntegerFieldwith the given property.static <T> MultiSelectionField<T>ofMultiSelectionType(List<T> items)Creates a newMultiSelectionFieldwith the given items and no pre-defined selection.static <T> MultiSelectionField<T>ofMultiSelectionType(List<T> items, List<Integer> selection)Creates a newMultiSelectionFieldwith the given items and a pre-defined selection.static <T> MultiSelectionField<T>ofMultiSelectionType(javafx.beans.property.ListProperty<T> itemsBinding, javafx.beans.property.ListProperty<T> selectionBinding)Creates a newMultiSelectionFieldwith the given properties for items and selection.static PasswordFieldofPasswordType(String defaultValue)Creates a newPasswordFieldwith the given default value.static PasswordFieldofPasswordType(javafx.beans.property.StringProperty binding)Creates a newPasswordFieldwith the given property.static <T> SingleSelectionField<T>ofSingleSelectionType(List<T> items)Creates a newSingleSelectionFieldwith the given items and no pre-defined selection.static <T> SingleSelectionField<T>ofSingleSelectionType(List<T> items, int selection)Creates a newSingleSelectionFieldwith the given items and a pre-defined selection.static <T> SingleSelectionField<T>ofSingleSelectionType(javafx.beans.property.ListProperty<T> itemsBinding, javafx.beans.property.ObjectProperty<T> selectionBinding)Creates a newSingleSelectionFieldwith the given properties for items and selection.static StringFieldofStringType(String defaultValue)Creates a newStringFieldwith the given default value.static StringFieldofStringType(javafx.beans.property.StringProperty binding)Creates a newStringFieldwith the given property.Fplaceholder(String newValue)Sets the placeholder property of the current field.javafx.beans.property.StringPropertyplaceholderProperty()The placeholder is only visible in an empty field.FieldremoveEventHandler(javafx.event.EventType<FieldEvent> eventType, javafx.event.EventHandler<? super FieldEvent> eventHandler)Unregisters a previously registered event handler from this field.Frender(SimpleControl<F> newValue)Sets the control that renders this field.Frender(Supplier<SimpleControl<F>> newValue)Sets the control supplier that renders this field.Frequired(boolean newValue)Sets the required property to for the current field without providing an error message.Frequired(String errorMessage)Sets the required property to true for the current field.javafx.beans.property.BooleanPropertyrequiredProperty()abstract voidsetBindingMode(BindingMode newValue)Activates or deactivates thebindingModeListenerbased on the givenBindingMode.Ftooltip(String newValue)Sets the tooltip property of the current field.javafx.beans.property.StringPropertytooltipProperty()The tooltip is an extension of the label.voidtranslate(TranslationService newValue)This internal method is called by the containing section when a new translation has been added to the form.protected voidupdateElement(javafx.beans.property.StringProperty displayProperty, javafx.beans.property.StringProperty keyProperty)Updates a displayable field property to include translated text.protected abstract booleanvalidate()Validates a user input based on the field's value transformer and its validation rules.javafx.beans.property.BooleanPropertyvalidProperty()The field's current state is represented by the value properties, as well as by thevalidandchangedflags.FvalueDescription(String newValue)Sets the value description property of the current field.FvalueDescription(javafx.scene.Node newValue)Sets the value description property of the current field.Methods inherited from class com.dlsc.formsfx.model.structure.Element
getID, getSpan, getStyleClass, id, idProperty, span, span, spanProperty, styleClass, styleClassProperty
-
Property Details
-
placeholder
public javafx.beans.property.StringProperty placeholderPropertyThe placeholder is only visible in an empty field. It provides a hint to the user about what should be entered into the field. This property is translatable if aTranslationServiceis set on the containing form.- See Also:
getPlaceholder()
-
label
public javafx.beans.property.StringProperty labelPropertyThe label acts as a description for the field. It is always visible to the user and tells them what should be entered into the field. This property is translatable if aTranslationServiceis set on the containing form.- See Also:
getLabel()
-
tooltip
public javafx.beans.property.StringProperty tooltipPropertyThe tooltip is an extension of the label. It contains additional information about the contained data that is only contextually visible. This property is translatable if aTranslationServiceis set on the containing form.- See Also:
getTooltip()
-
valid
public javafx.beans.property.BooleanProperty validPropertyThe field's current state is represented by the value properties, as well as by thevalidandchangedflags.- See Also:
isValid()
-
changed
public javafx.beans.property.BooleanProperty changedProperty -
required
public javafx.beans.property.BooleanProperty requiredProperty- See Also:
isRequired()
-
editable
public javafx.beans.property.BooleanProperty editableProperty- See Also:
isEditable()
-
errorMessages
The results of the field's validation is stored in this property. After every validation, the results are updated and reflected in this property. This property is translatable if aTranslationServiceis set on the containing form.- See Also:
getErrorMessages()
-
-
Field Details
-
label
protected final javafx.beans.property.StringProperty labelThe label acts as a description for the field. It is always visible to the user and tells them what should be entered into the field. This property is translatable if aTranslationServiceis set on the containing form. -
labelKey
protected final javafx.beans.property.StringProperty labelKey -
tooltip
protected final javafx.beans.property.StringProperty tooltipThe tooltip is an extension of the label. It contains additional information about the contained data that is only contextually visible. This property is translatable if aTranslationServiceis set on the containing form. -
tooltipKey
protected final javafx.beans.property.StringProperty tooltipKey -
placeholder
protected final javafx.beans.property.StringProperty placeholderThe placeholder is only visible in an empty field. It provides a hint to the user about what should be entered into the field. This property is translatable if aTranslationServiceis set on the containing form. -
placeholderKey
protected final javafx.beans.property.StringProperty placeholderKey -
requiredErrorKey
protected final javafx.beans.property.StringProperty requiredErrorKeyEvery field can be marked asrequiredandeditable. These properties can change the field's behaviour. -
requiredError
protected final javafx.beans.property.StringProperty requiredError -
required
protected final javafx.beans.property.BooleanProperty required -
editable
protected final javafx.beans.property.BooleanProperty editable -
valid
protected final javafx.beans.property.BooleanProperty validThe field's current state is represented by the value properties, as well as by thevalidandchangedflags. -
changed
protected final javafx.beans.property.BooleanProperty changed -
id
protected final javafx.beans.property.StringProperty idFields can be styled using CSS through ID or class hooks. -
styleClass
-
span
protected final javafx.beans.property.IntegerProperty span -
errorMessages
The results of the field's validation is stored in this property. After every validation, the results are updated and reflected in this property. This property is translatable if aTranslationServiceis set on the containing form. -
errorMessageKeys
-
translationService
The translation service is passed down from the containing section. It is used to translate all translatable values of the field. -
renderer
-
rendererSupplier
-
eventHandlers
protected final Map<javafx.event.EventType<FieldEvent>,List<javafx.event.EventHandler<? super FieldEvent>>> eventHandlers -
bindingModeListener
protected final javafx.beans.InvalidationListener bindingModeListenerWith the continuous binding mode, values are always directly persisted upon any changes.
-
-
Constructor Details
-
Field
protected Field()Internal constructor for theFieldclass. To create new elements, see the static factory methods in this class.
-
-
Method Details
-
ofPasswordType
Creates a newPasswordFieldwith the given default value.- Parameters:
defaultValue- The initial value and persistent value of the field.- Returns:
- Returns a new
PasswordField.
-
ofPasswordType
Creates a newPasswordFieldwith the given property.- Parameters:
binding- The property from the model to be bound with.- Returns:
- Returns a new
PasswordField.
-
ofStringType
Creates a newStringFieldwith the given default value.- Parameters:
defaultValue- The initial value and persistent value of the field.- Returns:
- Returns a new
StringField.
-
ofStringType
Creates a newStringFieldwith the given property.- Parameters:
binding- The property from the model to be bound with.- Returns:
- Returns a new
StringField.
-
ofDoubleType
Creates a newDoubleFieldwith the given default value.- Parameters:
defaultValue- The initial value and persistent value of the field.- Returns:
- Returns a new
DoubleField.
-
ofDoubleType
Creates a newDoubleFieldwith the given property.- Parameters:
binding- The property from the model to be bound with.- Returns:
- Returns a new
DoubleField.
-
ofIntegerType
Creates a newIntegerFieldwith the given default value.- Parameters:
defaultValue- The initial value and persistent value of the field.- Returns:
- Returns a new
IntegerField.
-
ofIntegerType
Creates a newIntegerFieldwith the given property.- Parameters:
binding- The property from the model to be bound with.- Returns:
- Returns a new
IntegerField.
-
ofBooleanType
Creates a newBooleanFieldwith the given default value.- Parameters:
defaultValue- The initial value and persistent value of the field.- Returns:
- Returns a new
BooleanField.
-
ofBooleanType
Creates a newBooleanFieldwith the given property.- Parameters:
binding- The property from the model to be bound with.- Returns:
- Returns a new
BooleanField.
-
ofMultiSelectionType
public static <T> MultiSelectionField<T> ofMultiSelectionType(List<T> items, List<Integer> selection)Creates a newMultiSelectionFieldwith the given items and a pre-defined selection.- Parameters:
items- The list of available items on the field.selection- The pre-defined indices of the selected items.- Returns:
- Returns a new
MultiSelectionField.
-
ofMultiSelectionType
Creates a newMultiSelectionFieldwith the given items and no pre-defined selection.- Parameters:
items- The list of available items on the field.- Returns:
- Returns a new
MultiSelectionField.
-
ofMultiSelectionType
public static <T> MultiSelectionField<T> ofMultiSelectionType(javafx.beans.property.ListProperty<T> itemsBinding, javafx.beans.property.ListProperty<T> selectionBinding)Creates a newMultiSelectionFieldwith the given properties for items and selection.- Parameters:
itemsBinding- The items property to be bound with.selectionBinding- The selection property to be bound with.- Returns:
- Returns a new
MultiSelectionField.
-
ofSingleSelectionType
Creates a newSingleSelectionFieldwith the given items and a pre-defined selection.- Parameters:
items- The list of available items on the field.selection- The pre-defined index of the selected item.- Returns:
- Returns a new
SingleSelectionField.
-
ofSingleSelectionType
Creates a newSingleSelectionFieldwith the given items and no pre-defined selection.- Parameters:
items- The list of available items on the field.- Returns:
- Returns a new
SingleSelectionField.
-
ofSingleSelectionType
public static <T> SingleSelectionField<T> ofSingleSelectionType(javafx.beans.property.ListProperty<T> itemsBinding, javafx.beans.property.ObjectProperty<T> selectionBinding)Creates a newSingleSelectionFieldwith the given properties for items and selection.- Parameters:
itemsBinding- The items property to be bound with.selectionBinding- The selection property to be bound with.- Returns:
- Returns a new
SingleSelectionField.
-
ofDate
Creates a newDateFieldwith given default value- Parameters:
defaultValue- The initial value and persistent value of the field.- Returns:
- Returns a new
DateField.
-
ofDate
Creates a newDateFieldwith given property- Parameters:
binding- The property from the model to be bound with.- Returns:
- Returns a new
DateField.
-
required
Sets the required property to for the current field without providing an error message.- Parameters:
newValue- The new state of the required property.- Returns:
- Returns the current field to allow for chaining.
-
required
Sets the required property to true for the current field.- Parameters:
errorMessage- The error message if the field is not filled in.- Returns:
- Returns the current field to allow for chaining.
-
editable
Sets the editable property of the current field.- Parameters:
newValue- The new value for the editable property.- Returns:
- Returns the current field to allow for chaining.
-
label
Sets the label property of the current field.- Parameters:
newValue- The new value for the label property. This can be the label itself or a key that is then used for translation.- Returns:
- Returns the current field to allow for chaining.
- See Also:
TranslationService
-
labelDescription
Sets the label description property of the current field.- Parameters:
newValue- The new value for the label description property.- Returns:
- Returns the current field to allow for chaining.
-
labelDescription
Sets the label description property of the current field.- Parameters:
newValue- The new value for the label description property, wrapped with aText.- Returns:
- Returns the current field to allow for chaining.
-
valueDescription
Sets the value description property of the current field.- Parameters:
newValue- The new value for the field description property.- Returns:
- Returns the current field to allow for chaining.
-
valueDescription
Sets the value description property of the current field.- Parameters:
newValue- The new value for the field description property, wrapped with aText.- Returns:
- Returns the current field to allow for chaining.
-
tooltip
Sets the tooltip property of the current field.- Parameters:
newValue- The new value for the tooltip property. This can be the label itself or a key that is then used for translation.- Returns:
- Returns the current field to allow for chaining.
- See Also:
TranslationService
-
placeholder
Sets the placeholder property of the current field.- Parameters:
newValue- The new value for the placeholder property. This can be the label itself or a key that is then used for translation.- Returns:
- Returns the current field to allow for chaining.
- See Also:
TranslationService
-
render
Sets the control that renders this field.- Parameters:
newValue- The new control to render the field.- Returns:
- Returns the current field to allow for chaining.
-
render
Sets the control supplier that renders this field. The supplier is only called when required, i.e., when the GUI is created.- Parameters:
newValue- The new control supplier to render the field.- Returns:
- Returns the current field to allow for chaining.
-
setBindingMode
Activates or deactivates thebindingModeListenerbased on the givenBindingMode.- Parameters:
newValue- The new binding mode for the current field.
-
translate
This internal method is called by the containing section when a new translation has been added to the form.- Parameters:
newValue- The new service to use for translating translatable values.
-
updateElement
protected void updateElement(javafx.beans.property.StringProperty displayProperty, javafx.beans.property.StringProperty keyProperty)Updates a displayable field property to include translated text.- Parameters:
displayProperty- The property that is displayed to the user.keyProperty- The internal property that holds the translation key.
-
validate
protected abstract boolean validate()Validates a user input based on the field's value transformer and its validation rules. Also considers therequiredflag. This method directly updates thevalidproperty.- Returns:
- Returns whether the user input is a valid value or not.
-
getPlaceholder
Gets the value of the property placeholder.- Property description:
- The placeholder is only visible in an empty field. It provides a hint to
the user about what should be entered into the field.
This property is translatable if a
TranslationServiceis set on the containing form.
-
placeholderProperty
public javafx.beans.property.StringProperty placeholderProperty()The placeholder is only visible in an empty field. It provides a hint to the user about what should be entered into the field. This property is translatable if aTranslationServiceis set on the containing form.- See Also:
getPlaceholder()
-
getLabel
Gets the value of the property label.- Property description:
- The label acts as a description for the field. It is always visible to
the user and tells them what should be entered into the field.
This property is translatable if a
TranslationServiceis set on the containing form.
-
labelProperty
public javafx.beans.property.StringProperty labelProperty()The label acts as a description for the field. It is always visible to the user and tells them what should be entered into the field. This property is translatable if aTranslationServiceis set on the containing form.- See Also:
getLabel()
-
getTooltip
Gets the value of the property tooltip.- Property description:
- The tooltip is an extension of the label. It contains additional
information about the contained data that is only contextually visible.
This property is translatable if a
TranslationServiceis set on the containing form.
-
tooltipProperty
public javafx.beans.property.StringProperty tooltipProperty()The tooltip is an extension of the label. It contains additional information about the contained data that is only contextually visible. This property is translatable if aTranslationServiceis set on the containing form.- See Also:
getTooltip()
-
isValid
public boolean isValid()Gets the value of the property valid.- Property description:
- The field's current state is represented by the value properties, as
well as by the
validandchangedflags.
-
validProperty
public javafx.beans.property.BooleanProperty validProperty()The field's current state is represented by the value properties, as well as by thevalidandchangedflags.- See Also:
isValid()
-
hasChanged
public boolean hasChanged() -
changedProperty
public javafx.beans.property.BooleanProperty changedProperty() -
isRequired
public boolean isRequired()Gets the value of the property required.- Property description:
-
requiredProperty
public javafx.beans.property.BooleanProperty requiredProperty()- See Also:
isRequired()
-
isEditable
public boolean isEditable()Gets the value of the property editable.- Property description:
-
editableProperty
public javafx.beans.property.BooleanProperty editableProperty()- See Also:
isEditable()
-
isI18N
public boolean isI18N() -
getRenderer
-
getErrorMessages
Gets the value of the property errorMessages.- Property description:
- The results of the field's validation is stored in this property. After
every validation, the results are updated and reflected in this property.
This property is translatable if a
TranslationServiceis set on the containing form.
-
errorMessagesProperty
The results of the field's validation is stored in this property. After every validation, the results are updated and reflected in this property. This property is translatable if aTranslationServiceis set on the containing form.- See Also:
getErrorMessages()
-
addEventHandler
public Field addEventHandler(javafx.event.EventType<FieldEvent> eventType, javafx.event.EventHandler<? super FieldEvent> eventHandler)Registers an event handler to this field. The handler is called when the field receives anEventof the specified type during the bubbling phase of event delivery.- Parameters:
eventType- the type of the events to receive by the handlereventHandler- the handler to register- Throws:
NullPointerException- if either event type or handler arenull.
-
removeEventHandler
public Field removeEventHandler(javafx.event.EventType<FieldEvent> eventType, javafx.event.EventHandler<? super FieldEvent> eventHandler)Unregisters a previously registered event handler from this field. One handler might have been registered for different event types, so the caller needs to specify the particular event type from which to unregister the handler.- Parameters:
eventType- the event type from which to unregistereventHandler- the handler to unregister- Throws:
NullPointerException- if either event type or handler arenull.
-
fireEvent
-
getLabelDescription
public javafx.scene.Node getLabelDescription() -
getValueDescription
public javafx.scene.Node getValueDescription()
-