]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix Declarative support for Slider (#17196)
authorJohannes Dahlström <johannesd@vaadin.com>
Wed, 18 Mar 2015 13:42:48 +0000 (15:42 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 24 Mar 2015 13:39:37 +0000 (13:39 +0000)
Change-Id: I5cc390566af38115939416591a549f06e39d3153

server/src/com/vaadin/ui/Slider.java
server/tests/src/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java [new file with mode: 0644]

index 99e1e8d5e9c4e9a027c25983d398a4d1c2690b61..40a4047d53283f82355b50c6c8b7f615e8c5a794 100644 (file)
 
 package com.vaadin.ui;
 
+import java.util.Collection;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+
 import com.vaadin.shared.ui.slider.SliderOrientation;
 import com.vaadin.shared.ui.slider.SliderServerRpc;
 import com.vaadin.shared.ui.slider.SliderState;
+import com.vaadin.ui.declarative.DesignAttributeHandler;
+import com.vaadin.ui.declarative.DesignContext;
 
 /**
  * A component for selecting a numerical value within a range.
@@ -353,4 +360,35 @@ public class Slider extends AbstractField<Double> {
         // Slider is never really "empty"
         return false;
     }
+
+    @Override
+    public void readDesign(Element design, DesignContext context) {
+        super.readDesign(design, context);
+        Attributes attr = design.attributes();
+        if (attr.hasKey("vertical")) {
+            setOrientation(SliderOrientation.VERTICAL);
+        }
+        if (!attr.get("value").isEmpty()) {
+            setValue(DesignAttributeHandler.readAttribute("value", attr,
+                    Double.class));
+        }
+    }
+
+    @Override
+    public void writeDesign(Element design, DesignContext context) {
+        super.writeDesign(design, context);
+        if (getOrientation() == SliderOrientation.VERTICAL) {
+            design.attr("vertical", "");
+        }
+        Slider defaultSlider = context.getDefaultInstance(this);
+        DesignAttributeHandler.writeAttribute(this, "value",
+                design.attributes(), defaultSlider);
+    }
+
+    @Override
+    protected Collection<String> getCustomAttributes() {
+        Collection<String> result = super.getCustomAttributes();
+        result.add("orientation");
+        return result;
+    }
 }
diff --git a/server/tests/src/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java
new file mode 100644 (file)
index 0000000..9ef28af
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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.slider;
+
+import org.junit.Test;
+
+import com.vaadin.shared.ui.slider.SliderOrientation;
+import com.vaadin.tests.design.DeclarativeTestBase;
+import com.vaadin.ui.Slider;
+
+/**
+ * Tests declarative support for implementations of {@link Slider}.
+ * 
+ * @since
+ * @author Vaadin Ltd
+ */
+public class SliderDeclarativeTest extends DeclarativeTestBase<Slider> {
+
+    @Test
+    public void testDefault() {
+        String design = "<v-slider>";
+
+        Slider expected = new Slider();
+
+        testRead(design, expected);
+        testWrite(design, expected);
+    }
+
+    @Test
+    public void testHorizontal() {
+        String design = "<v-slider min=10 max=20 resolution=1 value=12.3>";
+
+        Slider expected = new Slider();
+        expected.setMin(10.0);
+        expected.setMax(20.0);
+        expected.setResolution(1);
+        expected.setValue(12.3);
+
+        testRead(design, expected);
+        testWrite(design, expected);
+    }
+
+    @Test
+    public void testVertical() {
+        String design = "<v-slider vertical>";
+
+        Slider expected = new Slider();
+        expected.setOrientation(SliderOrientation.VERTICAL);
+
+        testRead(design, expected);
+        testWrite(design, expected);
+    }
+}