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