Interface ValueTranslator<M,V>

Type Parameters:
M - the model's type
V - the view's type
All Known Implementing Classes:
AbstractValueTranslator, BMoneyStringTranslator, BooleanBooleanTranslator, ByteStringTranslator, CharArrayCharArrayTranslator, CollectionTreeItemTranslator, ColorColorTranslator, DateStringTranslator, DoubleStringTranslator, EnumEnumTranslator, EnumStringTranslator, FloatStringTranslator, FractionNumberStringTranslator, I18NTextStringTranslator, IdentityTranslator, InstantStringTranslator, IntegerStringTranslator, LocalDateStringTranslator, LocalDateTimeStringTranslator, LocalTimeStringTranslator, LongStringTranslator, NumberStringTranslator, ObservableListTranslator, OffsetDateTimeStringTranslator, OffsetTimeStringTranslator, ShortStringTranslator, StringColorTranslator, StringStringTranslator, TemporalStringTranslator, TimestampStringTranslator, TimeStringTranslator, TreeItemTranslator, ValueStringTranslator, ZonedDateTimeStringTranslator

public interface ValueTranslator<M,V>
A value translator.
Converts between view and model types.

Notice: tentackle uses the term "translator" instead of "converter" to prevent tentackle-translators from being mixed up with JavaFX StringConverters.

Author:
harald
  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    Invoked explicitly by the application after binding properties have been updated.
    May be necessary if action must be taken by the translator.
    The method is provided for custom translators.
    Gets the component.
    boolean
    Returns whether parsing to model should be lenient.
    boolean
    Returns whether the model value is only mapped partially to the view.
    Such data types may hold more data that could have changed by the translator, but the view object still looks unchanged.
    An example for such a type is I18NText.
    boolean
    Returns whether the model is modified compared to value saved via saveModelValue(Object).
    Only invoked if isMappingIncomplete() is true.
    default boolean
    Returns whether toModel must be invoked twice.
    An example is a DoubleStringTranslator:
    let fraction number input be 1.211111 and formatting scale 2.
    void
    saveModelValue(M modelValue)
    Remembers the model value for later check if changed.
    Only invoked if isMappingIncomplete() is true.
    default M
    toModel(V value)
    Converts a view value to a model value.
    Function to translate a view value to a model value.
    default V
    toView(M value)
    Converts a model value to a view value.
    Function to translate a model value to a view value.
  • Method Details

    • getComponent

      FxComponent getComponent()
      Gets the component.
      Returns:
      the component
    • toViewFunction

      Function<M,V> toViewFunction()
      Function to translate a model value to a view value.
      Returns:
      the function
    • toModelFunction

      Function<V,M> toModelFunction()
      Function to translate a view value to a model value.
      Returns:
      the function
    • isLenient

      boolean isLenient()
      Returns whether parsing to model should be lenient.
      Returns:
      true if lenient, false is default
    • isMappingIncomplete

      boolean isMappingIncomplete()
      Returns whether the model value is only mapped partially to the view.
      Such data types may hold more data that could have changed by the translator, but the view object still looks unchanged.
      An example for such a type is I18NText.
      Returns:
      true if view may look unchanged but the model could be modified
    • saveModelValue

      void saveModelValue(M modelValue)
      Remembers the model value for later check if changed.
      Only invoked if isMappingIncomplete() is true.
      Parameters:
      modelValue - the model value
    • isModelModified

      boolean isModelModified()
      Returns whether the model is modified compared to value saved via saveModelValue(Object).
      Only invoked if isMappingIncomplete() is true.
      Returns:
      true if model is modified
    • needsToModelTwice

      default boolean needsToModelTwice()
      Returns whether toModel must be invoked twice.
      An example is a DoubleStringTranslator:
      let fraction number input be 1.211111 and formatting scale 2.
      • after first updateModel the model contains 1.211111
      • after formatting and updateView, the view contains 1.21 but the model still contains 1.211111
      • after second updateModel the model contains the correct value 1.21
      Returns:
      true to force a second translation roundtrip
    • bindingPropertiesUpdated

      default void bindingPropertiesUpdated()
      Invoked explicitly by the application after binding properties have been updated.
      May be necessary if action must be taken by the translator.
      The method is provided for custom translators. Not used by the framework itself.

      Example:

         getBinder().putBindingProperty(DomainContext.class, getDomainContext());
         pdoField.getValueTranslator().bindingPropertiesUpdated();
       
    • toView

      default V toView(M value)
      Converts a model value to a view value.
      Parameters:
      value - the model's value
      Returns:
      the view's value
    • toModel

      default M toModel(V value)
      Converts a view value to a model value.
      Parameters:
      value - the view's value
      Returns:
      the model's value