Search in sources :

Example 21 with FormatStrings

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"));
}
Also used : FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) EventListener(org.springframework.context.event.EventListener)

Example 22 with FormatStrings

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);
    }
}
Also used : FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) DecimalFormat(java.text.DecimalFormat) Datatype(io.jmix.core.metamodel.datatype.Datatype) Nullable(javax.annotation.Nullable)

Aggregations

FormatStrings (io.jmix.core.metamodel.datatype.FormatStrings)22 DecimalFormatSymbols (java.text.DecimalFormatSymbols)12 DecimalFormat (java.text.DecimalFormat)10 NumberFormat (java.text.NumberFormat)6 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 DateTimeFormatter (java.time.format.DateTimeFormatter)2 ArrayList (java.util.ArrayList)2 Nullable (javax.annotation.Nullable)2 EventListener (org.springframework.context.event.EventListener)2 Datatype (io.jmix.core.metamodel.datatype.Datatype)1 MapDataItem (io.jmix.ui.data.impl.MapDataItem)1 BigDecimal (java.math.BigDecimal)1 LocalDateTime (java.time.LocalDateTime)1 HashMap (java.util.HashMap)1 LinkedHashMap (java.util.LinkedHashMap)1 Locale (java.util.Locale)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1