Search in sources :

Example 11 with FormatStrings

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

the class DateDatatype 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);
    }
    DateFormat format = new SimpleDateFormat(formatStrings.getDateFormat());
    return format.format(value);
}
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 12 with FormatStrings

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

the class DoubleDatatype 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.getDoubleFormat(), 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)

Example 13 with FormatStrings

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

the class IntegerDatatype method parse.

@Override
public Integer 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).intValue();
}
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 14 with FormatStrings

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

the class LongDatatype 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.getIntegerFormat(), 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)

Example 15 with FormatStrings

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

the class TimeDatatype 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);
    }
    DateFormat format = new SimpleDateFormat(formatStrings.getTimeFormat());
    format.setLenient(false);
    return format.format(value);
}
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)

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