Class DataField<P extends javafx.beans.property.Property,​V,​F extends Field<F>>

java.lang.Object
com.dlsc.formsfx.model.structure.Element<F>
com.dlsc.formsfx.model.structure.Field<F>
com.dlsc.formsfx.model.structure.DataField<P,​V,​F>
All Implemented Interfaces:
FormElement
Direct Known Subclasses:
BooleanField, DateField, DoubleField, IntegerField, PasswordField, StringField

public abstract class DataField<P extends javafx.beans.property.Property,​V,​F extends Field<F>>
extends Field<F>
DataField holds a single value. This value can be represented and manipulated as a String. It is stored as a concrete type.
Author:
Sacha Schmid, Rinesch Murugathas
  • Property Details

    • userInput

      public javafx.beans.property.StringProperty userInputProperty
      See Also:
      getUserInput()
    • value

      public P extends javafx.beans.property.Property valueProperty
      Every field tracks its value in multiple ways. - The user input is bound to a specific control's input value and is a 1-to-1 representation of what the user enters. - The value is the last valid value entered by the user. This means that the value passes the type transformation of the concrete field and all user-defined validations. - The persistent value is the value that was last saved on the field. It is the responsibility of the form creator to persist the field values at the correct time.
      See Also:
      getValue()
  • Field Details

    • value

      protected final P extends javafx.beans.property.Property value
      Every field tracks its value in multiple ways. - The user input is bound to a specific control's input value and is a 1-to-1 representation of what the user enters. - The value is the last valid value entered by the user. This means that the value passes the type transformation of the concrete field and all user-defined validations. - The persistent value is the value that was last saved on the field. It is the responsibility of the form creator to persist the field values at the correct time.
    • persistentValue

      protected final P extends javafx.beans.property.Property persistentValue
    • userInput

      protected final javafx.beans.property.StringProperty userInput
    • validators

      protected final List<Validator<V>> validators
      Every field contains a list of validators. The validators are limited to the ones that correspond to the field's type.
    • stringConverter

      protected javafx.util.StringConverter<V> stringConverter
    • formatErrorKey

      protected final javafx.beans.property.StringProperty formatErrorKey
      The format error is displayed when the value transformation fails. This property is translatable if a TranslationService is set on the containing form.
    • formatError

      protected final javafx.beans.property.StringProperty formatError
  • Constructor Details

    • DataField

      protected DataField​(P valueProperty, P persistentValueProperty)
      Internal constructor for the DataField class. To create new elements, see the static factory methods in Field.
      Parameters:
      valueProperty - The property that is used to store the current valid value of the field.
      persistentValueProperty - The property that is used to store the latest persisted value of the field.
  • Method Details

    • format

      public F format​(javafx.util.StringConverter<V> newValue)
      Sets the string converter for the current field.
      Parameters:
      newValue - The string converter that transforms the user input string to the field's underlying value and back.
      Returns:
      Returns the current field to allow for chaining.
    • format

      public F format​(javafx.util.StringConverter<V> newValue, String errorMessage)
      Applies a new string converter that converts the entered string input to a concrete value.
      Parameters:
      newValue - The string converter that transforms the user input string to the field's underlying value and back.
      errorMessage - The error message to display if the transformation was unsuccessful.
      Returns:
      Returns the current field to allow for chaining.
    • format

      @Deprecated public F format​(ValueTransformer<V> newValue)
      Deprecated.
      Use format(StringConverter) instead
      Sets the value transformer for the current field.
      Parameters:
      newValue - The value transformer that parses the user input string to the field's underlying value.
      Returns:
      Returns the current field to allow for chaining.
    • format

      @Deprecated public F format​(ValueTransformer<V> newValue, String errorMessage)
      Deprecated.
      Use format(StringConverter, errorMessage) instead
      Applies a new value transformer that converts the entered string input to a concrete value.
      Parameters:
      newValue - The new value transformer. Takes a string as an input and returns the concrete type.
      errorMessage - The error message to display if the transformation was unsuccessful.
      Returns:
      Returns the current field to allow for chaining.
    • format

      public F format​(String errorMessage)
      Adds an error message to handle formatting errors with the default value transformers.
      Parameters:
      errorMessage - The error message to display if the transformation was unsuccessful.
      Returns:
      Returns the current field to allow for chaining.
    • validate

      @SafeVarargs public final F validate​(Validator<V>... newValue)
      Sets the list of validators for the current field. This overrides all validators that have previously been added.
      Parameters:
      newValue - The validators that are to be used for validating this field. Limited to validators that are able to handle the field's underlying type.
      Returns:
      Returns the current field to allow for chaining.
    • bind

      public F bind​(P binding)
      Binds the given property with the field.
      Parameters:
      binding - The property to be bound with.
      Returns:
      Returns the current field to allow for chaining.
    • unbind

      public F unbind​(P binding)
      Unbinds the given property with the field.
      Parameters:
      binding - The property to be unbound with.
      Returns:
      Returns the current field to allow for chaining.
    • setBindingMode

      public void setBindingMode​(BindingMode newValue)
      Activates or deactivates the bindingModeListener based on the given BindingMode.
      Specified by:
      setBindingMode in class Field<F extends Field<F>>
      Parameters:
      newValue - The new binding mode for the current field.
    • persist

      public void persist()
      Stores the field's current value in its persistent value. This stores the user's changes in the model.
    • reset

      public void reset()
      Sets the field's current value to its persistent value, thus resetting any changes made by the user.
    • validateRequired

      protected boolean validateRequired​(String newValue)
      Validates that the new field input matches the required condition.
      Parameters:
      newValue - The new value to check for the required state.
      Returns:
      Returns whether the input matches the required condition.
    • validate

      public 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.
      Specified by:
      validate in class Field<F extends Field<F>>
      Returns:
      Returns whether the user input is a valid value or not.
    • translate

      public void translate​(TranslationService service)
      This internal method is called by the containing section when a new translation has been added to the form.
      Overrides:
      translate in class Field<F extends Field<F>>
      Parameters:
      service - The new service to use for translating translatable values.
    • getUserInput

      public String getUserInput()
      Gets the value of the property userInput.
      Property description:
    • userInputProperty

      public javafx.beans.property.StringProperty userInputProperty()
      See Also:
      getUserInput()
    • getValue

      public V getValue()
      Gets the value of the property value.
      Property description:
      Every field tracks its value in multiple ways. - The user input is bound to a specific control's input value and is a 1-to-1 representation of what the user enters. - The value is the last valid value entered by the user. This means that the value passes the type transformation of the concrete field and all user-defined validations. - The persistent value is the value that was last saved on the field. It is the responsibility of the form creator to persist the field values at the correct time.
    • valueProperty

      public P valueProperty()
      Every field tracks its value in multiple ways. - The user input is bound to a specific control's input value and is a 1-to-1 representation of what the user enters. - The value is the last valid value entered by the user. This means that the value passes the type transformation of the concrete field and all user-defined validations. - The persistent value is the value that was last saved on the field. It is the responsibility of the form creator to persist the field values at the correct time.
      See Also:
      getValue()