@@ -0,0 +1,3681 @@
+package com.vaadin.tests.components.textfield;%0A%0Aimport java.math.BigDecimal;%0Aimport java.math.RoundingMode;%0Aimport java.text.DecimalFormat;%0Aimport java.text.DecimalFormatSymbols;%0Aimport java.util.Locale;%0A%0Aimport com.vaadin.data.Property;%0Aimport com.vaadin.data.util.PropertyFormatter;%0Aimport com.vaadin.tests.components.TestBase;%0Aimport com.vaadin.ui.Button;%0Aimport com.vaadin.ui.Button.ClickEvent;%0Aimport com.vaadin.ui.Button.ClickListener;%0Aimport com.vaadin.ui.TextField;%0A%0A@SuppressWarnings(%22unchecked%22)%0Apublic class TextFieldWithPropertyFormatter extends TestBase %7B%0A%0A    private PropertyFormatter formatter;%0A    private Property property;%0A%0A    @Override%0A    protected void setup() %7B%0A        /*%0A         * Formatter that: - formats in UK currency style - scales to 2 fraction%0A         * digits - rounds half up%0A         */%0A        // Property containing BigDecimal%0A        property = new Property() %7B%0A            private BigDecimal value;%0A%0A            public Object getValue() %7B%0A                return value;%0A            %7D%0A%0A            public void setValue(Object newValue) throws ReadOnlyException,%0A                    ConversionException %7B%0A                if (newValue == null) %7B%0A                    value = null;%0A                %7D else if (newValue instanceof BigDecimal) %7B%0A                    value = (BigDecimal) newValue;%0A                %7D else %7B%0A                    throw new ConversionException();%0A                %7D%0A            %7D%0A%0A            public Class%3C?%3E getType() %7B%0A                return BigDecimal.class;%0A            %7D%0A%0A            public boolean isReadOnly() %7B%0A                return false;%0A            %7D%0A%0A            public void setReadOnly(boolean newStatus) %7B%0A                // ignore%0A            %7D%0A        %7D;%0A%0A        formatter = new PropertyFormatter(property) %7B%0A            private final DecimalFormat df = new DecimalFormat(%22#,##0.00%22,%0A                    DecimalFormatSymbols.getInstance(Locale.UK));%0A            %7B%0A                df.setParseBigDecimal(true);%0A                df.setRoundingMode(RoundingMode.HALF_UP);%0A            %7D%0A%0A            @Override%0A            public String format(Object value) %7B%0A                final String retVal;%0A                if (value == null) %7B%0A                    retVal = %22%22;%0A                %7D else %7B%0A                    retVal = df.format(value);%0A                %7D%0A                return retVal;%0A            %7D%0A%0A            @Override%0A            public Object parse(String formattedValue) throws Exception %7B%0A                if (formattedValue != null%0A                        && formattedValue.trim().length() != 0) %7B%0A                    BigDecimal value = (BigDecimal) df.parse(formattedValue);%0A                    value = value.setScale(2, BigDecimal.ROUND_HALF_UP);%0A                    return value;%0A                %7D%0A                return null;%0A            %7D%0A        %7D;%0A%0A        final TextField tf1 = new TextField();%0A%0A        tf1.setPropertyDataSource(formatter);%0A%0A        addComponent(tf1);%0A%0A        Button b = new Button(%0A                %22Sync (typing 12345.6789 and clicking this should format field)%22);%0A        b.addListener(new ClickListener() %7B%0A            public void buttonClick(ClickEvent event) %7B%0A            %7D%0A        %7D);%0A        addComponent(b);%0A        b = new Button(%22Set '12345.6789' to textfield on the server side%22);%0A        b.addListener(new ClickListener() %7B%0A            public void buttonClick(ClickEvent event) %7B%0A                tf1.setValue(%2212345.6789%22);%0A            %7D%0A        %7D);%0A        addComponent(b);%0A%0A    %7D%0A%0A    @Override%0A    protected String getDescription() %7B%0A        return %22Should work%22;%0A    %7D%0A%0A    @Override%0A    protected Integer getTicketNumber() %7B%0A        return 4394;%0A    %7D%0A%0A%7D%0A

test case related to #4394 and possibly to #7724