Module org.tentackle.fx
Package org.tentackle.fx.translate
Class TemporalStringTranslator<T extends Temporal>
java.lang.Object
org.tentackle.fx.translate.AbstractValueTranslator<M,String>
org.tentackle.fx.translate.ValueStringTranslator<T>
org.tentackle.fx.translate.TemporalStringTranslator<T>
- Type Parameters:
T- theTemporaltype
- All Implemented Interfaces:
ValueTranslator<T,,String> NumberShortcut.WindowProvider,SmartDateTimeParser.Shortcut
- Direct Known Subclasses:
InstantStringTranslator,LocalDateStringTranslator,LocalDateTimeStringTranslator,LocalTimeStringTranslator,OffsetDateTimeStringTranslator,OffsetTimeStringTranslator,ZonedDateTimeStringTranslator
public abstract class TemporalStringTranslator<T extends Temporal>
extends ValueStringTranslator<T>
implements NumberShortcut.WindowProvider, SmartDateTimeParser.Shortcut
String translator for date- and/or time types based on
Temporal.-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringProperty to define the sliding day input window.static final StringProperty to define the sliding month input window.static final StringComponent property for a reference date supplier of type Supplier<T>.
'@' as input will be replaced by the supplier's date.
Example:static final StringProperty to define the sliding year input window. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidConnects two fields as reference date suppliers.
Each field provides the reference date for the other one.
Replaces code like:protected abstract SmartDateTimeParser<T>Creates the parser instance according to the concrete data type.protected StringFormats the given value.intprotected intGets the default day window forgetDayWindow().protected intGets the default month window forgetMonthWindow().protected intGets the default value forgetYearWindow().Gets the list of filters.Gets the list of error handlers.protected TGets the last formatted value.intprotected SmartDateTimeParser<T>Gets the parser instance.protected Supplier<?>Gets the reference date supplier.Gets the list of default shortcuts.intprotected TParses the input.<V extends Temporal>
Vparse(SmartDateTimeParser<V> parser, V currentValue, String part) test(SmartDateTimeParser<? extends Temporal> parser, String text) Function to translate a view value to a model value.Function to translate a model value to a view value.Methods inherited from class org.tentackle.fx.translate.ValueStringTranslator
getComponent, getValidChars, toModelMethods inherited from class org.tentackle.fx.translate.AbstractValueTranslator
isLenient, isMappingIncomplete, isModelModified, saveModelValue, setLenientMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface org.tentackle.fx.ValueTranslator
bindingPropertiesUpdated, needsToModelTwice, toView
-
Field Details
-
REFERENCE_DATE_SUPPLIER
Component property for a reference date supplier of type Supplier<T>.
'@' as input will be replaced by the supplier's date.
Example:blahField.getProperties.put(REFERENCE_DATE_SUPPLIER, (Supplier<LocalDate>) () -> otherDate);
-
YEAR_WINDOW
Property to define the sliding year input window.Example:
blahField.getProperties().put(TemporalStringTranslator.YEAR_WINDOW, 30);
-
MONTH_WINDOW
Property to define the sliding month input window.Example:
blahField.getProperties().put(TemporalStringTranslator.MONTH_WINDOW, 2);
-
DAY_WINDOW
Property to define the sliding day input window.Example:
blahField.getProperties().put(TemporalStringTranslator.DAY_WINDOW, 1);
-
-
Constructor Details
-
TemporalStringTranslator
Creates a translator.- Parameters:
component- the text component
-
-
Method Details
-
connectAsReferenceDateSuppliers
Connects two fields as reference date suppliers.
Each field provides the reference date for the other one.
Replaces code like:fromField.getProperties().put(TemporalStringTranslator.REFERENCE_DATE_SUPPLIER, (Supplier
by) () -> until); untilField.getProperties().put(TemporalStringTranslator.REFERENCE_DATE_SUPPLIER, (Supplier ) () -> from); TemporalStringTranslator.connectAsReferenceDateSuppliers(fromField, untilField);
ThrowsBindingExceptionif one of the fields is not bound.- Parameters:
a- the first componentb- the second component
-
toViewFunction
Description copied from interface:ValueTranslatorFunction to translate a model value to a view value.- Specified by:
toViewFunctionin interfaceValueTranslator<T extends Temporal,String> - Returns:
- the function
-
toModelFunction
Description copied from interface:ValueTranslatorFunction to translate a view value to a model value.- Specified by:
toModelFunctionin interfaceValueTranslator<T extends Temporal,String> - Returns:
- the function
-
getReferenceDateSupplier
Gets the reference date supplier.- Returns:
- the date supplier, null if none
-
getYearWindow
public int getYearWindow()- Specified by:
getYearWindowin interfaceNumberShortcut.WindowProvider
-
getDefaultYearWindow
protected int getDefaultYearWindow()Gets the default value forgetYearWindow().- Returns:
- the default (50 years)
-
getMonthWindow
public int getMonthWindow()- Specified by:
getMonthWindowin interfaceNumberShortcut.WindowProvider
-
getDefaultMonthWindow
protected int getDefaultMonthWindow()Gets the default month window forgetMonthWindow().- Returns:
- the default (-1 == disabled)
-
getDayWindow
public int getDayWindow()- Specified by:
getDayWindowin interfaceNumberShortcut.WindowProvider
-
getDefaultDayWindow
protected int getDefaultDayWindow()Gets the default day window forgetDayWindow().- Returns:
- the default (-1 == disabled)
-
test
public SmartDateTimeParser.TextRange test(SmartDateTimeParser<? extends Temporal> parser, String text) - Specified by:
testin interfaceSmartDateTimeParser.Shortcut
-
parse
- Specified by:
parsein interfaceSmartDateTimeParser.Shortcut
-
getShortcuts
Gets the list of default shortcuts.- Returns:
- the list of shortcuts
-
getHandlers
Gets the list of error handlers.- Returns:
- the handlers
-
getFilters
Gets the list of filters.- Returns:
- the list of filters
-
createParser
Creates the parser instance according to the concrete data type.- Returns:
- the parser
-
getParser
Gets the parser instance.- Returns:
- the parser
-
format
Formats the given value.- Parameters:
value- the temporal value- Returns:
- the formatted string
-
getLastValue
Gets the last formatted value.- Returns:
- the last date- or time formatted
-
parse
Parses the input.- Parameters:
s- the input string- Returns:
- the model value
-