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.
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);
+ }
}
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;
// 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>() {
+++ /dev/null
-/*
- * 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;
- }
-
-}
--- /dev/null
+/*
+ * 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