diff options
author | Johannes Dahlström <johannesd@vaadin.com> | 2015-03-18 15:35:47 +0200 |
---|---|---|
committer | Johannes Dahlström <johannesd@vaadin.com> | 2015-03-20 11:32:06 +0200 |
commit | 4a40924cd8715f664cf08ea6bfff7c83d96d14d4 (patch) | |
tree | b49f75d01dac6519c2bf8bc146eddfc47d7d05a4 /server | |
parent | 7d4de11c54060286bbc7adfeefa2891f3a461b1d (diff) | |
download | vaadin-framework-4a40924cd8715f664cf08ea6bfff7c83d96d14d4.tar.gz vaadin-framework-4a40924cd8715f664cf08ea6bfff7c83d96d14d4.zip |
Fix Declarative support for BigDecimal properties (#17205)
Change-Id: I766172c125b7e771b4bc8e2db1f39d1ae828fea6
Diffstat (limited to 'server')
-rw-r--r-- | server/src/com/vaadin/ui/declarative/DesignFormatter.java | 15 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java | 16 |
2 files changed, 26 insertions, 5 deletions
diff --git a/server/src/com/vaadin/ui/declarative/DesignFormatter.java b/server/src/com/vaadin/ui/declarative/DesignFormatter.java index cc5071fe9d..728b3d1077 100644 --- a/server/src/com/vaadin/ui/declarative/DesignFormatter.java +++ b/server/src/com/vaadin/ui/declarative/DesignFormatter.java @@ -29,6 +29,7 @@ import java.util.TimeZone; import java.util.concurrent.ConcurrentHashMap; import com.vaadin.data.util.converter.Converter; +import com.vaadin.data.util.converter.StringToBigDecimalConverter; import com.vaadin.data.util.converter.StringToDoubleConverter; import com.vaadin.data.util.converter.StringToFloatConverter; import com.vaadin.event.ShortcutAction; @@ -68,8 +69,8 @@ public class DesignFormatter implements Serializable { */ protected void mapDefaultTypes() { // numbers use standard toString/valueOf approach - for (Class<?> c : new Class<?>[] { Integer.class, Byte.class, - Short.class, Long.class, BigDecimal.class }) { + for (Class<?> c : new Class<?>[] { Byte.class, Short.class, + Integer.class, Long.class }) { DesignToStringConverter<?> conv = new DesignToStringConverter(c); converterMap.put(c, conv); try { @@ -134,6 +135,16 @@ public class DesignFormatter implements Serializable { converterMap.put(Double.class, doubleConverter); converterMap.put(double.class, doubleConverter); + final DecimalFormat bigDecimalFmt = new DecimalFormat("0.###", symbols); + bigDecimalFmt.setGroupingUsed(false); + bigDecimalFmt.setParseBigDecimal(true); + converterMap.put(BigDecimal.class, new StringToBigDecimalConverter() { + @Override + protected NumberFormat getFormat(Locale locale) { + return bigDecimalFmt; + }; + }); + // strings do nothing converterMap.put(String.class, new Converter<String, String>() { diff --git a/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java b/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java index 1e6d446427..05b2484767 100644 --- a/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java +++ b/server/tests/src/com/vaadin/tests/design/DesignFormatterTest.java @@ -18,6 +18,7 @@ package com.vaadin.tests.design; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; +import java.math.BigDecimal; import java.text.SimpleDateFormat; import java.util.Date; import java.util.HashSet; @@ -57,9 +58,10 @@ public class DesignFormatterTest { byte.class, short.class, int.class, long.class, float.class, double.class, Boolean.class, Character.class, Byte.class, Short.class, Integer.class, Long.class, Float.class, - Double.class, String.class, ShortcutAction.class, Date.class, - FileResource.class, ExternalResource.class, - ThemeResource.class, Resource.class, TimeZone.class }) { + Double.class, BigDecimal.class, String.class, + ShortcutAction.class, Date.class, FileResource.class, + ExternalResource.class, ThemeResource.class, Resource.class, + TimeZone.class }) { assertTrue("not supported " + type.getSimpleName(), formatter.canConvert(type)); } @@ -145,6 +147,14 @@ public class DesignFormatterTest { } @Test + public void testBigDecimal() { + BigDecimal bd = new BigDecimal("123456789123456789.123456789123456789"); + assertEquals("123456789123456789.123", formatter.format(bd)); + assertEquals(bd, formatter.parse( + "123456789123456789.123456789123456789", BigDecimal.class)); + } + + @Test public void testChar() { char c = '\uABCD'; assertEquals("\uABCD", formatter.format(c)); |