use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.
the class AbstractTemporalDatatype method parse.
@Nullable
@Override
public T parse(@Nullable String value, Locale locale) throws ParseException {
if (StringUtils.isBlank(value)) {
return null;
}
FormatStrings formatStrings = formatStringsRegistry.getFormatStringsOrNull(locale);
if (formatStrings == null) {
return parse(value);
}
DateTimeFormatter formatter = getDateTimeFormatter(formatStrings, locale);
return formatter.parse(value.trim(), newInstance());
}
use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.
the class AbstractTemporalDatatype method format.
@Override
public String format(@Nullable Object value, Locale locale) {
if (value == null) {
return "";
}
FormatStrings formatStrings = formatStringsRegistry.getFormatStringsOrNull(locale);
if (formatStrings == null) {
return format(value);
}
DateTimeFormatter formatter = getDateTimeFormatter(formatStrings, locale);
return formatter.format((TemporalAccessor) value);
}
use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.
the class AdaptiveNumberDatatype method createLocalizedFormat.
protected java.text.NumberFormat createLocalizedFormat(Locale locale) {
FormatStrings formatStrings = formatStringsRegistry.getFormatStringsOrNull(locale);
if (formatStrings == null) {
return createFormat();
}
DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
if (!decimalSeparator.equals("")) {
formatSymbols.setDecimalSeparator(decimalSeparator.charAt(0));
}
if (!groupingSeparator.equals("")) {
formatSymbols.setGroupingSeparator(groupingSeparator.charAt(0));
}
DecimalFormat format = new DecimalFormat(formatPattern, formatSymbols);
setupFormat(format);
return format;
}
use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.
the class BigDecimalDatatype method parse.
@Override
public BigDecimal parse(String value, Locale locale) throws ParseException {
if (StringUtils.isBlank(value)) {
return null;
}
FormatStrings formatStrings = formatStringsRegistry.getFormatStringsOrNull(locale);
if (formatStrings == null) {
return parse(value);
}
DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
DecimalFormat format = new DecimalFormat(formatStrings.getDecimalFormat(), formatSymbols);
format.setParseBigDecimal(true);
return (BigDecimal) parse(value, format);
}
use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.
the class DateDatatype method parse.
@Override
public Date parse(String value, Locale locale) throws ParseException {
if (StringUtils.isBlank(value)) {
return null;
}
FormatStrings formatStrings = formatStringsRegistry.getFormatStringsOrNull(locale);
if (formatStrings == null) {
return parse(value);
}
DateFormat format = new SimpleDateFormat(formatStrings.getDateFormat());
format.setLenient(false);
return normalize(format.parse(value.trim()));
}
Aggregations