Search in sources :

Example 11 with FormatStrings

use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.

the class FormatStringsLoader method init.

@EventListener(ContextRefreshedEvent.class)
private void init() {
    for (Locale locale : coreProperties.getAvailableLocales()) {
        String numberDecimalSeparator = getMessage("numberDecimalSeparator", locale);
        String numberGroupingSeparator = getMessage("numberGroupingSeparator", locale);
        String integerFormat = getMessage("integerFormat", locale);
        String doubleFormat = getMessage("doubleFormat", locale);
        String decimalFormat = getMessage("decimalFormat", locale);
        String dateFormat = getMessage("dateFormat", locale);
        String dateTimeFormat = getMessage("dateTimeFormat", locale);
        String offsetDateTimeFormat = getMessage("offsetDateTimeFormat", locale);
        String timeFormat = getMessage("timeFormat", locale);
        String offsetTimeFormat = getMessage("offsetTimeFormat", locale);
        String trueString = getMessage("trueString", locale);
        String falseString = getMessage("falseString", locale);
        if (numberDecimalSeparator.equals("numberDecimalSeparator") || numberGroupingSeparator.equals("numberGroupingSeparator") || integerFormat.equals("integerFormat") || doubleFormat.equals("doubleFormat") || decimalFormat.equals("decimalFormat") || dateFormat.equals("dateFormat") || dateTimeFormat.equals("dateTimeFormat") || offsetDateTimeFormat.equals("offsetDateTimeFormat") || timeFormat.equals("timeFormat") || offsetTimeFormat.equals("offsetTimeFormat"))
            log.warn("Localized format strings are not defined for {}", locale);
        formatStringsRegistry.setFormatStrings(locale.stripExtensions(), new FormatStrings(numberDecimalSeparator.charAt(0), numberGroupingSeparator.charAt(0), integerFormat, doubleFormat, decimalFormat, dateFormat, dateTimeFormat, offsetDateTimeFormat, timeFormat, offsetTimeFormat, trueString, falseString));
    }
}
Also used : Locale(java.util.Locale) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) EventListener(org.springframework.context.event.EventListener)

Example 12 with FormatStrings

use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.

the class IntegerDatatype method format.

@Override
public String format(Object value, Locale locale) {
    if (value == null)
        return "";
    FormatStrings formatStrings = formatStringsRegistry.getFormatStringsOrNull(locale);
    if (formatStrings == null)
        return format(value);
    DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
    NumberFormat format = new DecimalFormat(formatStrings.getIntegerFormat(), formatSymbols);
    return format.format(value);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 13 with FormatStrings

use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.

the class LongDatatype method format.

@Override
public String format(Object value, Locale locale) {
    if (value == null) {
        return "";
    }
    FormatStrings formatStrings = formatStringsRegistry.getFormatStringsOrNull(locale);
    if (formatStrings == null) {
        return format(value);
    }
    DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
    NumberFormat format = new DecimalFormat(formatStrings.getIntegerFormat(), formatSymbols);
    return format.format(value);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 14 with FormatStrings

use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.

the class LongDatatype method parse.

@Override
public Long 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();
    NumberFormat format = new DecimalFormat(formatStrings.getIntegerFormat(), formatSymbols);
    return parse(value, format).longValue();
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 15 with FormatStrings

use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.

the class TimeDatatype 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.getTimeFormat());
    return 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