Class ValidationStrategy<MVT,TVT>
java.lang.Object
com.amalgamasimulation.desktop.binding.ValidationStrategy<MVT,TVT>
- Type Parameters:
MVT- The type of the model valueTVT- The type of the target (UI) value
A configurable validation strategy for data binding between model and target values.
Provides conversion and validation capabilities with customizable error messages.
Key features include:
- Value validation through predicates
- Bi-directional value conversion
- Customizable error messages
- Fluent API for configuration
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionThe error message to display when validation fails. -
Constructor Summary
ConstructorsConstructorDescriptionValidationStrategy(String errorMessage) ValidationStrategy(String errorMessage, ValidationStrategy.TypeStrategy type) -
Method Summary
Modifier and TypeMethodDescriptionSets the validation predicate.convertToModel(TVT value) Converts a target value to a model value.convertToTarget(MVT value) Converts a model value to a target value.Gets the error message for validation failures.getType()Sets the error message for validation failures.setToModelConverter(Function<TVT, MVT> toModelConverter) Sets the converter from target (UI) value to model value.setToTargetConverter(Function<MVT, TVT> toTargetConverter) Sets the converter from model value to target (UI) value.booleanTests whether a target value is valid.
-
Field Details
-
errorMessage
The error message to display when validation fails.
-
-
Constructor Details
-
ValidationStrategy
-
ValidationStrategy
-
-
Method Details
-
check
Sets the validation predicate.- Parameters:
cheker- The predicate to validate target values- Returns:
- this strategy instance for method chaining
-
setToModelConverter
Sets the converter from target (UI) value to model value.- Parameters:
toModelConverter- The conversion function- Returns:
- this strategy instance for method chaining
-
setToTargetConverter
Sets the converter from model value to target (UI) value.- Parameters:
toTargetConverter- The conversion function- Returns:
- this strategy instance for method chaining
-
message
Sets the error message for validation failures.- Parameters:
errorMessage- The error message to display- Returns:
- this strategy instance for method chaining
-
test
Tests whether a target value is valid.- Parameters:
value- The target value to validate- Returns:
- true if the value is valid, false otherwise
-
convertToModel
Converts a target value to a model value.- Parameters:
value- The target value to convert- Returns:
- The converted model value, or null if no converter is set
-
convertToTarget
Converts a model value to a target value.- Parameters:
value- The model value to convert- Returns:
- The converted target value, or null if no converter is set
-
getDecorationMessage
Gets the error message for validation failures.- Returns:
- The current error message
-
getType
-