Search in sources :

Example 16 with FormatStrings

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

the class TimeDatatype 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);
    }
    DateFormat format = new SimpleDateFormat(formatStrings.getTimeFormat());
    format.setLenient(false);
    return format.format(value);
}
Also used : FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 17 with FormatStrings

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

the class DateDatatype 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);
    }
    DateFormat format = new SimpleDateFormat(formatStrings.getDateFormat());
    return format.format(value);
}
Also used : FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 18 with FormatStrings

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

the class DoubleDatatype method parse.

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

Example 19 with FormatStrings

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

the class IntegerDatatype method parse.

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

Example 20 with FormatStrings

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

the class BigDecimalDatatype 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();
    java.text.NumberFormat format = new DecimalFormat(formatStrings.getDecimalFormat(), formatSymbols);
    return format.format(value);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) DecimalFormat(java.text.DecimalFormat)

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