Class Field<F extends Field<F>>

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 Details

    • placeholder

      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 a TranslationService is set on the containing form.
      See Also:
      getPlaceholder()
    • label

      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 a TranslationService is set on the containing form.
      See Also:
      getLabel()
    • tooltip

      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 a TranslationService is set on the containing form.
      See Also:
      getTooltip()
    • valid

      public javafx.beans.property.BooleanProperty validProperty
      The field's current state is represented by the value properties, as well as by the valid and changed flags.
      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

      public javafx.beans.property.ListProperty<String> 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 a TranslationService is set on the containing form.
      See Also:
      getErrorMessages()
  • Field Details

    • label

      protected final javafx.beans.property.StringProperty label
      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 TranslationService is set on the containing form.
    • labelKey

      protected final javafx.beans.property.StringProperty labelKey
    • tooltip

      protected final javafx.beans.property.StringProperty tooltip
      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 TranslationService is set on the containing form.
    • tooltipKey

      protected final javafx.beans.property.StringProperty tooltipKey
    • placeholder

      protected final javafx.beans.property.StringProperty placeholder
      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 TranslationService is set on the containing form.
    • placeholderKey

      protected final javafx.beans.property.StringProperty placeholderKey
    • requiredErrorKey

      protected final javafx.beans.property.StringProperty requiredErrorKey
      Every field can be marked as required and editable. 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 valid
      The field's current state is represented by the value properties, as well as by the valid and changed flags.
    • changed

      protected final javafx.beans.property.BooleanProperty changed
    • id

      protected final javafx.beans.property.StringProperty id
      Fields can be styled using CSS through ID or class hooks.
    • styleClass

      protected final javafx.beans.property.ListProperty<String> styleClass
    • span

      protected final javafx.beans.property.IntegerProperty span
    • errorMessages

      protected final javafx.beans.property.ListProperty<String> 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 a TranslationService is set on the containing form.
    • errorMessageKeys

      protected final javafx.beans.property.ListProperty<String> errorMessageKeys
    • translationService

      protected TranslationService translationService
      The translation service is passed down from the containing section. It is used to translate all translatable values of the field.
    • renderer

      protected SimpleControl<F extends Field<F>> renderer
    • rendererSupplier

      protected Supplier<SimpleControl<F extends Field<F>>> rendererSupplier
    • eventHandlers

      protected final Map<javafx.event.EventType<FieldEvent>,​List<javafx.event.EventHandler<? super FieldEvent>>> eventHandlers
    • bindingModeListener

      protected final javafx.beans.InvalidationListener bindingModeListener
      With the continuous binding mode, values are always directly persisted upon any changes.
  • Constructor Details

    • Field

      protected Field()
      Internal constructor for the Field class. To create new elements, see the static factory methods in this class.
  • Method Details

    • ofPasswordType

      public static PasswordField ofPasswordType​(String defaultValue)
      Creates a new PasswordField with the given default value.
      Parameters:
      defaultValue - The initial value and persistent value of the field.
      Returns:
      Returns a new PasswordField.
    • ofPasswordType

      public static PasswordField ofPasswordType​(javafx.beans.property.StringProperty binding)
      Creates a new PasswordField with the given property.
      Parameters:
      binding - The property from the model to be bound with.
      Returns:
      Returns a new PasswordField.
    • ofStringType

      public static StringField ofStringType​(String defaultValue)
      Creates a new StringField with the given default value.
      Parameters:
      defaultValue - The initial value and persistent value of the field.
      Returns:
      Returns a new StringField.
    • ofStringType

      public static StringField ofStringType​(javafx.beans.property.StringProperty binding)
      Creates a new StringField with the given property.
      Parameters:
      binding - The property from the model to be bound with.
      Returns:
      Returns a new StringField.
    • ofDoubleType

      public static DoubleField ofDoubleType​(double defaultValue)
      Creates a new DoubleField with the given default value.
      Parameters:
      defaultValue - The initial value and persistent value of the field.
      Returns:
      Returns a new DoubleField.
    • ofDoubleType

      public static DoubleField ofDoubleType​(javafx.beans.property.DoubleProperty binding)
      Creates a new DoubleField with the given property.
      Parameters:
      binding - The property from the model to be bound with.
      Returns:
      Returns a new DoubleField.
    • ofIntegerType

      public static IntegerField ofIntegerType​(int defaultValue)
      Creates a new IntegerField with the given default value.
      Parameters:
      defaultValue - The initial value and persistent value of the field.
      Returns:
      Returns a new IntegerField.
    • ofIntegerType

      public static IntegerField ofIntegerType​(javafx.beans.property.IntegerProperty binding)
      Creates a new IntegerField with the given property.
      Parameters:
      binding - The property from the model to be bound with.
      Returns:
      Returns a new IntegerField.
    • ofBooleanType

      public static BooleanField ofBooleanType​(boolean defaultValue)
      Creates a new BooleanField with the given default value.
      Parameters:
      defaultValue - The initial value and persistent value of the field.
      Returns:
      Returns a new BooleanField.
    • ofBooleanType

      public static BooleanField ofBooleanType​(javafx.beans.property.BooleanProperty binding)
      Creates a new BooleanField with 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 new MultiSelectionField with 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

      public static <T> MultiSelectionField<T> ofMultiSelectionType​(List<T> items)
      Creates a new MultiSelectionField with 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 new MultiSelectionField with 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

      public static <T> SingleSelectionField<T> ofSingleSelectionType​(List<T> items, int selection)
      Creates a new SingleSelectionField with 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

      public static <T> SingleSelectionField<T> ofSingleSelectionType​(List<T> items)
      Creates a new SingleSelectionField with 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 new SingleSelectionField with 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

      public static DateField ofDate​(LocalDate defaultValue)
      Creates a new DateField with given default value
      Parameters:
      defaultValue - The initial value and persistent value of the field.
      Returns:
      Returns a new DateField.
    • ofDate

      public static DateField ofDate​(javafx.beans.property.ObjectProperty<LocalDate> binding)
      Creates a new DateField with given property
      Parameters:
      binding - The property from the model to be bound with.
      Returns:
      Returns a new DateField.
    • required

      public F required​(boolean newValue)
      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

      public F required​(String errorMessage)
      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

      public F editable​(boolean newValue)
      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

      public F label​(String newValue)
      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

      public F labelDescription​(javafx.scene.Node newValue)
      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

      public F labelDescription​(String newValue)
      Sets the label description property of the current field.
      Parameters:
      newValue - The new value for the label description property, wrapped with a Text.
      Returns:
      Returns the current field to allow for chaining.
    • valueDescription

      public F valueDescription​(javafx.scene.Node newValue)
      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

      public F valueDescription​(String newValue)
      Sets the value description property of the current field.
      Parameters:
      newValue - The new value for the field description property, wrapped with a Text.
      Returns:
      Returns the current field to allow for chaining.
    • tooltip

      public F tooltip​(String newValue)
      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

      public F placeholder​(String newValue)
      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

      public F render​(SimpleControl<F> newValue)
      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

      public F render​(Supplier<SimpleControl<F>> newValue)
      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

      public abstract void setBindingMode​(BindingMode newValue)
      Activates or deactivates the bindingModeListener based on the given BindingMode.
      Parameters:
      newValue - The new binding mode for the current field.
    • translate

      public void translate​(TranslationService newValue)
      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 the required flag. This method directly updates the valid property.
      Returns:
      Returns whether the user input is a valid value or not.
    • getPlaceholder

      public String 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 TranslationService is 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 a TranslationService is set on the containing form.
      See Also:
      getPlaceholder()
    • getLabel

      public String 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 TranslationService is 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 a TranslationService is set on the containing form.
      See Also:
      getLabel()
    • getTooltip

      public String 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 TranslationService is 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 a TranslationService is 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 valid and changed flags.
    • validProperty

      public javafx.beans.property.BooleanProperty validProperty()
      The field's current state is represented by the value properties, as well as by the valid and changed flags.
      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

      public SimpleControl<F> getRenderer()
    • getErrorMessages

      public List<String> 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 TranslationService is set on the containing form.
    • errorMessagesProperty

      public javafx.beans.property.ListProperty<String> 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 a TranslationService is 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 an Event of the specified type during the bubbling phase of event delivery.
      Parameters:
      eventType - the type of the events to receive by the handler
      eventHandler - the handler to register
      Throws:
      NullPointerException - if either event type or handler are null.
    • 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 unregister
      eventHandler - the handler to unregister
      Throws:
      NullPointerException - if either event type or handler are null.
    • fireEvent

      protected void fireEvent​(FieldEvent event)
    • getLabelDescription

      public javafx.scene.Node getLabelDescription()
    • getValueDescription

      public javafx.scene.Node getValueDescription()