Search in sources :

Example 1 with FormatStrings

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

the class AbstractMessages method init.

@PostConstruct
protected void init() {
    mainMessagePack = AppContext.getProperty("cuba.mainMessagePack");
    if (mainMessagePack == null) {
        throw new DevelopmentException("Property cuba.mainMessagePack is not set");
    }
    log.debug("Main message pack: " + mainMessagePack);
    for (Locale locale : globalConfig.getAvailableLocales().values()) {
        String numberDecimalSeparator = getMainMessage("numberDecimalSeparator", locale);
        String numberGroupingSeparator = getMainMessage("numberGroupingSeparator", locale);
        String integerFormat = getMainMessage("integerFormat", locale);
        String doubleFormat = getMainMessage("doubleFormat", locale);
        String decimalFormat = getMainMessage("decimalFormat", locale);
        String dateFormat = getMainMessage("dateFormat", locale);
        String dateTimeFormat = getMainMessage("dateTimeFormat", locale);
        String timeFormat = getMainMessage("timeFormat", locale);
        String trueString = getMainMessage("trueString", locale);
        String falseString = getMainMessage("falseString", locale);
        if (numberDecimalSeparator.equals("numberDecimalSeparator") || numberGroupingSeparator.equals("numberGroupingSeparator") || integerFormat.equals("integerFormat") || doubleFormat.equals("doubleFormat") || decimalFormat.equals("decimalFormat") || dateFormat.equals("dateFormat") || dateTimeFormat.equals("dateTimeFormat") || timeFormat.equals("timeFormat"))
            log.warn("Localized format strings are not defined. " + "Check cuba.mainMessagePack application property, it must point to a valid set of main message packs.");
        formatStringsRegistry.setFormatStrings(messageTools.trimLocale(locale), new FormatStrings(numberDecimalSeparator.charAt(0), numberGroupingSeparator.charAt(0), integerFormat, doubleFormat, decimalFormat, dateFormat, dateTimeFormat, timeFormat, trueString, falseString));
    }
}
Also used : FormatStrings(com.haulmont.chile.core.datatypes.FormatStrings) PostConstruct(javax.annotation.PostConstruct)

Example 2 with FormatStrings

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

the class AdaptiveNumberDatatype method createLocalizedFormat.

protected java.text.NumberFormat createLocalizedFormat(Locale locale) {
    FormatStrings formatStrings = AppBeans.get(FormatStringsRegistry.class).getFormatStrings(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(com.haulmont.chile.core.datatypes.FormatStrings) FormatStringsRegistry(com.haulmont.chile.core.datatypes.FormatStringsRegistry) DecimalFormat(java.text.DecimalFormat)

Example 3 with FormatStrings

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

the class DateDatatype 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.getDateFormat());
    format.setLenient(false);
    return normalize(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 4 with FormatStrings

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

the class DoubleDatatype method parse.

@Override
public Double 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.getDoubleFormat(), formatSymbols);
    return parse(value, format).doubleValue();
}
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 5 with FormatStrings

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

the class IntegerDatatype 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)

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