- Type Parameters:
M- the model's typeV- 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.
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 TypeMethodDescriptiondefault voidInvoked 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.booleanReturns whether parsing to model should be lenient.booleanReturns 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 isI18NText.booleanReturns whether the model is modified compared to value saved viasaveModelValue(Object).
Only invoked ifisMappingIncomplete()istrue.default booleanReturns whether toModel must be invoked twice.
An example is a DoubleStringTranslator:
let fraction number input be 1.211111 and formatting scale 2.voidsaveModelValue(M modelValue) Remembers the model value for later check if changed.
Only invoked ifisMappingIncomplete()istrue.default MConverts a view value to a model value.Function to translate a view value to a model value.default VConverts 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 to translate a model value to a view value.- Returns:
- the function
-
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 isI18NText.- Returns:
- true if view may look unchanged but the model could be modified
-
saveModelValue
Remembers the model value for later check if changed.
Only invoked ifisMappingIncomplete()istrue.- Parameters:
modelValue- the model value
-
isModelModified
boolean isModelModified()Returns whether the model is modified compared to value saved viasaveModelValue(Object).
Only invoked ifisMappingIncomplete()istrue.- 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
Converts a model value to a view value.- Parameters:
value- the model's value- Returns:
- the view's value
-
toModel
Converts a view value to a model value.- Parameters:
value- the view's value- Returns:
- the model's value
-