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