Search in sources :

Example 1 with FormatStrings

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());
}
Also used : FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) DateTimeFormatter(java.time.format.DateTimeFormatter) Nullable(javax.annotation.Nullable)

Example 2 with FormatStrings

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);
}
Also used : FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) DateTimeFormatter(java.time.format.DateTimeFormatter)

Example 3 with FormatStrings

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;
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) DecimalFormat(java.text.DecimalFormat)

Example 4 with FormatStrings

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);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal)

Example 5 with FormatStrings

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()));
}
Also used : FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Aggregations

FormatStrings (io.jmix.core.metamodel.datatype.FormatStrings)22 DecimalFormatSymbols (java.text.DecimalFormatSymbols)12 DecimalFormat (java.text.DecimalFormat)10 NumberFormat (java.text.NumberFormat)6 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 DateTimeFormatter (java.time.format.DateTimeFormatter)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 EventListener (org.springframework.context.event.EventListener)2 Datatype (io.jmix.core.metamodel.datatype.Datatype)1 MapDataItem (io.jmix.ui.data.impl.MapDataItem)1 BigDecimal (java.math.BigDecimal)1 LocalDateTime (java.time.LocalDateTime)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Locale (java.util.Locale)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1