From c4a0bc318ec9c6b41d652e7020ee39784cc1eb10 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Mon, 11 Feb 2013 17:04:15 +0200 Subject: [PATCH] Properly pass the AbstractField internal value to shared state in Slider and ProgressIndicator (#10921) * In case of a null value, 0 is stored to shared state. This is consistent with how CheckBox is already implemented. * This somewhat hacky solution should be replaced with a better one once AbstractField itself is migrated. See #11064. Change-Id: I2b313af8491a6deccdc7a509dcd1b718482cdcd4 --- server/src/com/vaadin/ui/CheckBox.java | 7 +++ .../src/com/vaadin/ui/ProgressIndicator.java | 15 +++++ server/src/com/vaadin/ui/Slider.java | 16 +++++ .../slider/SliderValueFromDataSource.html | 32 ++++++++++ .../slider/SliderValueFromDataSource.java | 59 +++++++++++++++++++ 5 files changed, 129 insertions(+) create mode 100644 uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.html create mode 100644 uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.java diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java index 22b90b224f..0ace0a4f26 100644 --- a/server/src/com/vaadin/ui/CheckBox.java +++ b/server/src/com/vaadin/ui/CheckBox.java @@ -110,6 +110,13 @@ public class CheckBox extends AbstractField { return (CheckBoxState) super.getState(); } + /* + * Overridden to keep the shared state in sync with the AbstractField + * internal value. Should be removed once AbstractField is refactored to use + * shared state. + * + * See tickets #10921 and #11064. + */ @Override protected void setInternalValue(Boolean newValue) { super.setInternalValue(newValue); diff --git a/server/src/com/vaadin/ui/ProgressIndicator.java b/server/src/com/vaadin/ui/ProgressIndicator.java index 96c2d2814a..c481aa1e8f 100644 --- a/server/src/com/vaadin/ui/ProgressIndicator.java +++ b/server/src/com/vaadin/ui/ProgressIndicator.java @@ -157,4 +157,19 @@ public class ProgressIndicator extends AbstractField implements return getState().pollingInterval; } + /* + * Overridden to keep the shared state in sync with the AbstractField + * internal value. Should be removed once AbstractField is refactored to use + * shared state. + * + * See tickets #10921 and #11064. + */ + @Override + protected void setInternalValue(Float newValue) { + super.setInternalValue(newValue); + if (newValue == null) { + newValue = 0.0f; + } + getState().state = newValue; + } } diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java index 2bf05f895c..e63fdc5e10 100644 --- a/server/src/com/vaadin/ui/Slider.java +++ b/server/src/com/vaadin/ui/Slider.java @@ -263,6 +263,22 @@ public class Slider extends AbstractField { getState().value = newFieldValue; } + /* + * Overridden to keep the shared state in sync with the AbstractField + * internal value. Should be removed once AbstractField is refactored to use + * shared state. + * + * See tickets #10921 and #11064. + */ + @Override + protected void setInternalValue(Double newValue) { + super.setInternalValue(newValue); + if (newValue == null) { + newValue = 0.0; + } + getState().value = newValue; + } + /** * Thrown when the value of the slider is about to be set to a value that is * outside the valid range of the slider. diff --git a/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.html b/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.html new file mode 100644 index 0000000000..8b5a7067e4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.html @@ -0,0 +1,32 @@ + + + + + + +SliderValueFromDataSource + + + + + + + + + + + + + + + + + + + + + + +
SliderValueFromDataSource
open/run/SliderValueFromDataSource?restartApplication
assertAttributevaadin=runSliderValueFromDataSource::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VProgressIndicator[0]/domChild[0]/domChild[0]@styleregex:.*(width|WIDTH): 50%.*
assertAttributevaadin=runSliderValueFromDataSource::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]@styleregex:.*(margin-left|MARGIN-LEFT): 94px.*
+ + diff --git a/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.java b/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.java new file mode 100644 index 0000000000..141dc5baf4 --- /dev/null +++ b/uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.java @@ -0,0 +1,59 @@ +package com.vaadin.tests.components.slider; + +import com.vaadin.data.Item; +import com.vaadin.data.util.BeanItem; +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.ProgressIndicator; +import com.vaadin.ui.Slider; + +public class SliderValueFromDataSource extends AbstractTestUI { + + public static class TestBean { + + private double doubleValue = 10.0; + private float floatValue = 0.5f; + + public double getDoubleValue() { + return doubleValue; + } + + public void setDoubleValue(double doubleValue) { + this.doubleValue = doubleValue; + } + + public float getFloatValue() { + return floatValue; + } + + public void setFloatValue(float floatValue) { + this.floatValue = floatValue; + } + } + + @Override + protected void setup(VaadinRequest request) { + Item item = new BeanItem(new TestBean()); + + Slider slider = new Slider(0, 20); + slider.setWidth("200px"); + slider.setPropertyDataSource(item.getItemProperty("doubleValue")); + addComponent(slider); + + ProgressIndicator pi = new ProgressIndicator(); + pi.setPollingInterval(60 * 1000); + pi.setWidth("200px"); + pi.setPropertyDataSource(item.getItemProperty("floatValue")); + addComponent(pi); + } + + @Override + protected String getTestDescription() { + return "Slider and ProgressIndicator do not properly pass a value from data source to the client"; + } + + @Override + protected Integer getTicketNumber() { + return 10921; + } +} -- 2.39.5