]> source.dussan.org Git - vaadin-framework.git/commitdiff
Properly pass the AbstractField internal value to shared state in Slider and Progress...
authorJohannes Dahlström <johannesd@vaadin.com>
Mon, 11 Feb 2013 15:04:15 +0000 (17:04 +0200)
committerVaadin Code Review <review@vaadin.com>
Mon, 18 Feb 2013 17:11:50 +0000 (17:11 +0000)
* 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
server/src/com/vaadin/ui/ProgressIndicator.java
server/src/com/vaadin/ui/Slider.java
uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/slider/SliderValueFromDataSource.java [new file with mode: 0644]

index 22b90b224f891048f6b1f343b69e2a57ae0bd636..0ace0a4f26e84d02e4df114579ea5b05122617e5 100644 (file)
@@ -110,6 +110,13 @@ public class CheckBox extends AbstractField<Boolean> {
         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);
index 96c2d2814a5b3798fa77c29b5a4e23cbf480720a..c481aa1e8fe2bae5f342a29a743aba424bc60653 100644 (file)
@@ -157,4 +157,19 @@ public class ProgressIndicator extends AbstractField<Float> 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;
+    }
 }
index 2bf05f895c02a2d4a638ba12f1e657866bbe623e..e63fdc5e10e103820c520d14f05b7bc3c65c8483 100644 (file)
@@ -263,6 +263,22 @@ public class Slider extends AbstractField<Double> {
         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 (file)
index 0000000..8b5a706
--- /dev/null
@@ -0,0 +1,32 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head profile="http://selenium-ide.openqa.org/profiles/test-case">
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+<link rel="selenium.base" href="http://localhost:8070/" />
+<title>SliderValueFromDataSource</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">SliderValueFromDataSource</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/SliderValueFromDataSource?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>assertAttribute</td>
+       <td>vaadin=runSliderValueFromDataSource::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VProgressIndicator[0]/domChild[0]/domChild[0]@style</td>
+       <td>regex:.*(width|WIDTH): 50%.*</td>
+</tr>
+<tr>
+       <td>assertAttribute</td>
+       <td>vaadin=runSliderValueFromDataSource::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VSlider[0]/domChild[2]/domChild[0]@style</td>
+       <td>regex:.*(margin-left|MARGIN-LEFT): 94px.*</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
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 (file)
index 0000000..141dc5b
--- /dev/null
@@ -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<TestBean>(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;
+    }
+}