diff options
author | Artur Signell <artur@vaadin.com> | 2015-02-05 00:23:25 +0200 |
---|---|---|
committer | Artur Signell <artur@vaadin.com> | 2015-02-05 16:45:56 +0200 |
commit | 50724f2d0d1e225b5c24d097d3c4b8529b7a8f3f (patch) | |
tree | 7dd55058719f8414c4a4cbe87e2336554c555de1 /server | |
parent | 713b8f0bbb714a0266145d956fe6699b98941d82 (diff) | |
download | vaadin-framework-50724f2d0d1e225b5c24d097d3c4b8529b7a8f3f.tar.gz vaadin-framework-50724f2d0d1e225b5c24d097d3c4b8529b7a8f3f.zip |
Declarative support for ProgressBar (#16316)
Change-Id: I8c13b19218e0da936abdb0860d492a3d5a096aa7
Diffstat (limited to 'server')
4 files changed, 99 insertions, 82 deletions
diff --git a/server/src/com/vaadin/ui/ProgressBar.java b/server/src/com/vaadin/ui/ProgressBar.java index bf52cefefe..c288695ae1 100644 --- a/server/src/com/vaadin/ui/ProgressBar.java +++ b/server/src/com/vaadin/ui/ProgressBar.java @@ -16,8 +16,12 @@ package com.vaadin.ui; +import org.jsoup.nodes.Element; + import com.vaadin.data.Property; import com.vaadin.shared.ui.progressindicator.ProgressBarState; +import com.vaadin.ui.declarative.DesignAttributeHandler; +import com.vaadin.ui.declarative.DesignContext; /** * Shows the current progress of a long running task. @@ -149,4 +153,21 @@ public class ProgressBar extends AbstractField<Float> implements getState().state = newValue; } + @Override + public void readDesign(Element design, DesignContext designContext) { + super.readDesign(design, designContext); + if (design.hasAttr("value") && !design.attr("value").isEmpty()) { + setValue(DesignAttributeHandler.readAttribute("value", + design.attributes(), Float.class)); + } + } + + @Override + public void writeDesign(Element design, DesignContext designContext) { + super.writeDesign(design, designContext); + Float defaultValue = ((ProgressBar) designContext + .getDefaultInstance(this)).getValue(); + DesignAttributeHandler.writeAttribute("value", design.attributes(), + getValue(), defaultValue, Float.class); + } } diff --git a/server/src/com/vaadin/ui/declarative/DesignFormatter.java b/server/src/com/vaadin/ui/declarative/DesignFormatter.java index 985b9235f3..d2fbf2c765 100644 --- a/server/src/com/vaadin/ui/declarative/DesignFormatter.java +++ b/server/src/com/vaadin/ui/declarative/DesignFormatter.java @@ -28,11 +28,12 @@ import java.util.TimeZone; import java.util.concurrent.ConcurrentHashMap; import com.vaadin.data.util.converter.Converter; +import com.vaadin.data.util.converter.StringToDoubleConverter; +import com.vaadin.data.util.converter.StringToFloatConverter; import com.vaadin.event.ShortcutAction; import com.vaadin.server.Resource; import com.vaadin.ui.declarative.converters.DesignDateConverter; import com.vaadin.ui.declarative.converters.DesignEnumConverter; -import com.vaadin.ui.declarative.converters.DesignFormatConverter; import com.vaadin.ui.declarative.converters.DesignObjectConverter; import com.vaadin.ui.declarative.converters.DesignResourceConverter; import com.vaadin.ui.declarative.converters.DesignShortcutActionConverter; @@ -111,16 +112,20 @@ public class DesignFormatter implements Serializable { // floats and doubles use formatters DecimalFormatSymbols symbols = new DecimalFormatSymbols(new Locale( "en_US")); - DecimalFormat fmt = new DecimalFormat("0.###", symbols); + final DecimalFormat fmt = new DecimalFormat("0.###", symbols); fmt.setGroupingUsed(false); - converterMap.put(Float.class, new DesignFormatConverter<Float>( - Float.class, fmt)); - converterMap.put(Float.TYPE, new DesignFormatConverter<Float>( - Float.class, fmt)); - converterMap.put(Double.class, new DesignFormatConverter<Double>( - Double.class, fmt)); - converterMap.put(Double.TYPE, new DesignFormatConverter<Double>( - Double.class, fmt)); + converterMap.put(Float.class, new StringToFloatConverter() { + @Override + protected java.text.NumberFormat getFormat(Locale locale) { + return fmt; + }; + }); + converterMap.put(Double.class, new StringToDoubleConverter() { + @Override + protected java.text.NumberFormat getFormat(Locale locale) { + return fmt; + }; + }); // strings do nothing converterMap.put(String.class, new Converter<String, String>() { diff --git a/server/src/com/vaadin/ui/declarative/converters/DesignFormatConverter.java b/server/src/com/vaadin/ui/declarative/converters/DesignFormatConverter.java deleted file mode 100644 index e9b26fce0b..0000000000 --- a/server/src/com/vaadin/ui/declarative/converters/DesignFormatConverter.java +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright 2000-2014 Vaadin Ltd. - * - * Licensed under the Apache License, Version 2.0 (the "License"); you may not - * use this file except in compliance with the License. You may obtain a copy of - * the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations under - * the License. - */ -package com.vaadin.ui.declarative.converters; - -import java.text.Format; -import java.text.ParseException; -import java.util.Locale; - -import com.vaadin.data.util.converter.Converter; - -/** - * Converter based on Java Formats rather than static methods. - * - * @since 7.4 - * @author Vaadin Ltd - * @param <TYPE> - * Type of the object to format. - */ -public class DesignFormatConverter<TYPE> implements Converter<String, TYPE> { - - private final Format format; - private final Class<? extends TYPE> type; - - /** - * Constructs an instance of the converter. - */ - public DesignFormatConverter(Class<? extends TYPE> type, Format format) { - this.type = type; - this.format = format; - } - - @Override - public TYPE convertToModel(String value, Class<? extends TYPE> targetType, - Locale locale) throws Converter.ConversionException { - try { - return targetType.cast(this.format.parseObject(value)); - } catch (ParseException e) { - throw new Converter.ConversionException(e); - } - } - - @Override - public String convertToPresentation(TYPE value, - Class<? extends String> targetType, Locale locale) - throws Converter.ConversionException { - return this.format.format(value); - } - - @Override - public Class<TYPE> getModelType() { - return (Class<TYPE>) this.type; - } - - @Override - public Class<String> getPresentationType() { - return String.class; - } - -} diff --git a/server/tests/src/com/vaadin/tests/server/component/progressbar/ProgressBarDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/progressbar/ProgressBarDeclarativeTest.java new file mode 100644 index 0000000000..c98883a4a7 --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/progressbar/ProgressBarDeclarativeTest.java @@ -0,0 +1,63 @@ +/* + * Copyright 2000-2014 Vaadin Ltd. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy of + * the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the + * License for the specific language governing permissions and limitations under + * the License. + */ +package com.vaadin.tests.server.component.progressbar; + +import org.junit.Test; + +import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.ui.ProgressBar; + +/** + * Test cases for reading the properties of selection components. + * + * @author Vaadin Ltd + */ +public class ProgressBarDeclarativeTest extends + DeclarativeTestBase<ProgressBar> { + + public String getBasicDesign() { + return "<v-progress-bar value=0.5 indeterminate='true'>"; + + } + + public ProgressBar getBasicExpected() { + ProgressBar ns = new ProgressBar(); + ns.setIndeterminate(true); + ns.setValue(0.5f); + return ns; + } + + @Test + public void testReadBasic() { + testRead(getBasicDesign(), getBasicExpected()); + } + + @Test + public void testWriteBasic() { + testWrite(stripOptionTags(getBasicDesign()), getBasicExpected()); + } + + @Test + public void testReadEmpty() { + testRead("<v-progress-bar>", new ProgressBar()); + } + + @Test + public void testWriteEmpty() { + testWrite("<v-progress-bar>", new ProgressBar()); + } + +}
\ No newline at end of file |