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));
}
}
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;
}
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()));
}
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();
}
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);
}
Aggregations