Search in sources :

Example 6 with FormatStrings

use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.

the class DoubleDatatype method format.

@Override
public String format(Object value, Locale locale) {
    if (value == null) {
        return "";
    }
    FormatStrings formatStrings = formatStringsRegistry.getFormatStringsOrNull(locale);
    if (formatStrings == null) {
        return format(value);
    }
    DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
    NumberFormat format = new DecimalFormat(formatStrings.getDoubleFormat(), formatSymbols);
    return format.format(value);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) DecimalFormat(java.text.DecimalFormat) NumberFormat(java.text.NumberFormat)

Example 7 with FormatStrings

use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.

the class PivotTableLocaleHelper method getPivotTableLocaleMap.

public Map<String, Object> getPivotTableLocaleMap(Locale locale) {
    Map<String, Object> localeMap = new LinkedHashMap<>();
    // Number formatting
    String[] formatTypes = { "floatFormat", "integerFormat", "percentFormat" };
    FormatStrings formatStrings = formatStringsRegistry.getFormatStrings(locale);
    for (String type : formatTypes) {
        Map<String, String> typeMessages = new HashMap<>();
        typeMessages.put("digitsAfterDecimal", messages.getMessage("pivottable." + type + ".digitsAfterDecimal", locale));
        typeMessages.put("scaler", messages.getMessage("pivottable." + type + ".scaler", locale));
        typeMessages.put("prefix", messages.getMessage("pivottable." + type + ".prefix", locale));
        typeMessages.put("suffix", messages.getMessage("pivottable." + type + ".suffix", locale));
        typeMessages.put("showZero", messages.getMessage("pivottable." + type + ".showZero", locale));
        if (formatStrings != null) {
            DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
            typeMessages.put("thousandsSep", Character.toString(formatSymbols.getGroupingSeparator()));
            typeMessages.put("decimalSep", Character.toString(formatSymbols.getDecimalSeparator()));
        } else {
            typeMessages.put("thousandsSep", messages.getMessage("pivottable." + type + ".thousandsSep", locale));
            typeMessages.put("decimalSep", messages.getMessage("pivottable." + type + ".decimalSep", locale));
        }
        localeMap.put(type, typeMessages);
    }
    if (formatStrings != null) {
        DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
        localeMap.put("percentFormat.suffix", Character.toString(formatSymbols.getPercent()));
    }
    // Other
    localeMap.put("renderError", messages.getMessage("pivottable.renderError", locale));
    localeMap.put("computeError", messages.getMessage("pivottable.computeError", locale));
    localeMap.put("uiRenderError", messages.getMessage("pivottable.uiRenderError", locale));
    localeMap.put("selectAll", messages.getMessage("pivottable.selectAll", locale));
    localeMap.put("selectNone", messages.getMessage("pivottable.selectNone", locale));
    localeMap.put("apply", messages.getMessage("pivottable.apply", locale));
    localeMap.put("cancel", messages.getMessage("pivottable.cancel", locale));
    localeMap.put("tooMany", messages.getMessage("pivottable.tooMany", locale));
    localeMap.put("filterResults", messages.getMessage("pivottable.filterResults", locale));
    localeMap.put("totals", messages.getMessage("pivottable.totals", locale));
    localeMap.put("vs", messages.getMessage("pivottable.vs", locale));
    localeMap.put("by", messages.getMessage("pivottable.by", locale));
    localeMap.put("aggregation", getAggregationsLocaleMap(locale));
    localeMap.put("renderer", getRenderersLocaleMap(locale));
    return localeMap;
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) LinkedHashMap(java.util.LinkedHashMap) HashMap(java.util.HashMap) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) LinkedHashMap(java.util.LinkedHashMap)

Example 8 with FormatStrings

use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.

the class ChartImpl method setupChartLocale.

protected void setupChartLocale(AbstractChart chart) {
    chart.setLanguage(LocaleResolver.localeToString(currentAuthentication.getLocale()));
    // number formatting
    FormatStrings formatStrings = formatStringsRegistry.getFormatStrings(currentAuthentication.getLocale());
    if (formatStrings != null) {
        DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
        chart.setPrecision(-1);
        chart.setPercentPrecision(2);
        chart.setDecimalSeparator(Character.toString(formatSymbols.getDecimalSeparator()));
        chart.setThousandsSeparator(Character.toString(formatSymbols.getGroupingSeparator()));
    }
    // number prefixes
    List<BigNumberPrefix> bigPrefixes = new ArrayList<>();
    for (BigNumberPower power : BigNumberPower.values()) {
        bigPrefixes.add(new BigNumberPrefix(power, messages.getMessage("amcharts.bigNumberPower." + power.name())));
    }
    chart.setPrefixesOfBigNumbers(bigPrefixes);
    List<SmallNumberPrefix> smallPrefixes = new ArrayList<>();
    for (SmallNumberPower power : SmallNumberPower.values()) {
        smallPrefixes.add(new SmallNumberPrefix(power, messages.getMessage("amcharts.smallNumberPower." + power.name())));
    }
    chart.setPrefixesOfSmallNumbers(smallPrefixes);
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) ArrayList(java.util.ArrayList)

Example 9 with FormatStrings

use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.

the class CustomChartImpl method setupChartLocale.

protected void setupChartLocale(AbstractChart chart) {
    // language
    if (StringUtils.isEmpty(chart.getLanguage())) {
        chart.setLanguage(LocaleResolver.localeToString(currentAuthentication.getLocale()));
    }
    // export
    if (chart.getExport() != null && chart.getExport().getDateFormat() == null) {
        chart.getExport().setDateFormat(messages.getMessage("amcharts.export.dateFormat"));
    }
    // number formatting
    FormatStrings formatStrings = formatStringsRegistry.getFormatStrings(currentAuthentication.getLocale());
    if (formatStrings != null) {
        DecimalFormatSymbols formatSymbols = formatStrings.getFormatSymbols();
        if (chart.getPrecision() == null) {
            chart.setPrecision(-1);
        }
        if (chart.getPercentPrecision() == null) {
            chart.setPercentPrecision(2);
        }
        if (chart.getDecimalSeparator() == null) {
            chart.setDecimalSeparator(Character.toString(formatSymbols.getDecimalSeparator()));
        }
        if (chart.getThousandsSeparator() == null) {
            chart.setThousandsSeparator(Character.toString(formatSymbols.getGroupingSeparator()));
        }
    }
    // number prefixes
    if (BooleanUtils.isTrue(chart.getUsePrefixes())) {
        if (chart.getPrefixesOfBigNumbers() == null) {
            List<BigNumberPrefix> prefixes = new ArrayList<>();
            for (BigNumberPower power : BigNumberPower.values()) {
                prefixes.add(new BigNumberPrefix(power, messages.getMessage("amcharts.bigNumberPower." + power.name())));
            }
            chart.setPrefixesOfBigNumbers(prefixes);
        }
        if (chart.getPrefixesOfSmallNumbers() == null) {
            List<SmallNumberPrefix> prefixes = new ArrayList<>();
            for (SmallNumberPower power : SmallNumberPower.values()) {
                prefixes.add(new SmallNumberPrefix(power, messages.getMessage("amcharts.smallNumberPower." + power.name())));
            }
            chart.setPrefixesOfSmallNumbers(prefixes);
        }
    }
}
Also used : DecimalFormatSymbols(java.text.DecimalFormatSymbols) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) ArrayList(java.util.ArrayList)

Example 10 with FormatStrings

use of io.jmix.core.metamodel.datatype.FormatStrings in project jmix by jmix-framework.

the class PivotTableSerializerTest method setupTest.

@BeforeEach
public void setupTest() {
    authenticator.begin();
    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"));
    dataItems = new ArrayList<>();
    LocalDateTime localDateTime = LocalDateTime.of(2010, Month.APRIL, 10, 14, 11, 59);
    Date date = Date.from(localDateTime.toInstant(ZoneOffset.UTC));
    dataItems.add(new MapDataItem(Maps.of("id", 1L, "name", "one", "localDateTime", localDateTime, "localDate", localDateTime.toLocalDate(), "date", date)));
}
Also used : LocalDateTime(java.time.LocalDateTime) FormatStrings(io.jmix.core.metamodel.datatype.FormatStrings) MapDataItem(io.jmix.ui.data.impl.MapDataItem) BeforeEach(org.junit.jupiter.api.BeforeEach)

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