use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.
the class UiTestAssistConfiguration method init.
@EventListener
public void init(ContextRefreshedEvent event) {
// saving session to avoid it be GC'ed
VaadinSession.setCurrent(vaadinSession = createTestVaadinSession());
formatStringsRegistry.setFormatStrings(Locale.ENGLISH, new FormatStrings('.', ',', "#,##0", "#,##0.###", "#,##0.##", "dd/MM/yyyy", "dd/MM/yyyy HH:mm", "dd/MM/yyyy HH:mm Z", "HH:mm", "HH:mm Z", "True", "False"));
}
use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.
the class NumberFormatter method apply.
@Nullable
@Override
public String apply(@Nullable Number value) {
if (value == null) {
return null;
}
if (format == null) {
Datatype datatype = datatypeRegistry.get(value.getClass());
return datatype.format(value, currentAuthentication.getLocale());
} else {
if (format.startsWith("msg://")) {
format = messages.getMessage(format.substring(6));
}
FormatStrings formatStrings = formatStringsRegistry.getFormatStrings(currentAuthentication.getLocale());
if (formatStrings == null)
throw new IllegalStateException("FormatStrings are not defined for " + LocaleResolver.localeToString(currentAuthentication.getLocale()));
DecimalFormat decimalFormat = new DecimalFormat(format, formatStrings.getFormatSymbols());
return decimalFormat.format(value);
}
}
Aggregations