Search in sources :

Example 6 with FormatStrings

use of com.haulmont.chile.core.datatypes.FormatStrings in project cuba by cuba-platform.

the class LongDatatype method parse.

@Override
public Long parse(String value, Locale locale) throws ParseException {
    if (StringUtils.isBlank(value)) {
        return null;
    }
    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(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(com.haulmont.chile.core.datatypes.FormatStrings) FormatStringsRegistry(com.haulmont.chile.core.datatypes.FormatStringsRegistry) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 7 with FormatStrings

use of com.haulmont.chile.core.datatypes.FormatStrings in project cuba by cuba-platform.

the class TimeDatatype method parse.

@Override
public Date parse(String value, Locale locale) throws ParseException {
    if (StringUtils.isBlank(value)) {
        return null;
    }
    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale);
    if (formatStrings == null) {
        return parse(value);
    }
    DateFormat format = new SimpleDateFormat(formatStrings.getTimeFormat());
    return format.parse(value.trim());
}
Also used : FormatStrings(com.haulmont.chile.core.datatypes.FormatStrings) FormatStringsRegistry(com.haulmont.chile.core.datatypes.FormatStringsRegistry) SimpleDateFormat(java.text.SimpleDateFormat) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat)

Example 8 with FormatStrings

use of com.haulmont.chile.core.datatypes.FormatStrings in project cuba by cuba-platform.

the class NumberFormatter method format.

@Override
public String format(Number value) {
    if (value == null) {
        return null;
    }
    String pattern = element != null ? element.attributeValue("format") : null;
    if (pattern == null) {
        Datatype datatype = Datatypes.getNN(value.getClass());
        return datatype.format(value, userSessionSource.getLocale());
    } else {
        if (pattern.startsWith("msg://")) {
            pattern = messages.getMainMessage(pattern.substring(6, pattern.length()));
        }
        FormatStrings formatStrings = Datatypes.getFormatStrings(userSessionSource.getLocale());
        if (formatStrings == null)
            throw new IllegalStateException("FormatStrings are not defined for " + userSessionSource.getLocale());
        DecimalFormat format = new DecimalFormat(pattern, formatStrings.getFormatSymbols());
        return format.format(value);
    }
}
Also used : FormatStrings(com.haulmont.chile.core.datatypes.FormatStrings) DecimalFormat(java.text.DecimalFormat) Datatype(com.haulmont.chile.core.datatypes.Datatype)

Example 9 with FormatStrings

use of com.haulmont.chile.core.datatypes.FormatStrings in project cuba by cuba-platform.

the class BigDecimalDatatype method parse.

@Override
public BigDecimal parse(String value, Locale locale) throws ParseException {
    if (StringUtils.isBlank(value)) {
        return null;
    }
    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(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(com.haulmont.chile.core.datatypes.FormatStrings) FormatStringsRegistry(com.haulmont.chile.core.datatypes.FormatStringsRegistry) DecimalFormat(java.text.DecimalFormat) BigDecimal(java.math.BigDecimal)

Example 10 with FormatStrings

use of com.haulmont.chile.core.datatypes.FormatStrings in project cuba by cuba-platform.

the class BigDecimalDatatype method format.

@Override
public String format(Object value, Locale locale) {
    if (value == null) {
        return "";
    }
    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(locale);
    if (formatStrings == null) {
        return format(value);
    }
    DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
    NumberFormat format = new DecimalFormat(formatStrings.getDecimalFormat(), formatSymbols);
    return format.format(value);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) FormatStrings(com.haulmont.chile.core.datatypes.FormatStrings) FormatStringsRegistry(com.haulmont.chile.core.datatypes.FormatStringsRegistry) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Aggregations

FormatStrings (com.haulmont.chile.core.datatypes.FormatStrings)16 FormatStringsRegistry (com.haulmont.chile.core.datatypes.FormatStringsRegistry)13 DecimalFormat (java.text.DecimalFormat)10 DecimalFormatSymbols (java.text.DecimalFormatSymbols)9 NumberFormat (java.text.NumberFormat)7 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Datatype (com.haulmont.chile.core.datatypes.Datatype)1 Configuration (com.haulmont.cuba.core.global.Configuration)1 GlobalConfig (com.haulmont.cuba.core.global.GlobalConfig)1 BigDecimal (java.math.BigDecimal)1 Locale (java.util.Locale)1 Properties (java.util.Properties)1 PostConstruct (javax.annotation.PostConstruct)1