summaryrefslogtreecommitdiffstats
path: root/server
diff options
context:
space:
mode:
authorJohannes Dahlström <johannesd@vaadin.com>2015-03-18 15:42:48 +0200
committerVaadin Code Review <review@vaadin.com>2015-03-24 13:39:37 +0000
commite3bf98708cb02e0772a46496ef8720657253e1ce (patch)
treec663ae7178c17253d02c40c987eb1cb23b4066fc /server
parentf18a9642b7ad5831719b2c15c1b4adb788b386e8 (diff)
downloadvaadin-framework-e3bf98708cb02e0772a46496ef8720657253e1ce.tar.gz
vaadin-framework-e3bf98708cb02e0772a46496ef8720657253e1ce.zip
Fix Declarative support for Slider (#17196)
Change-Id: I5cc390566af38115939416591a549f06e39d3153
Diffstat (limited to 'server')
-rw-r--r--server/src/com/vaadin/ui/Slider.java38
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java66
2 files changed, 104 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/Slider.java b/server/src/com/vaadin/ui/Slider.java
index 99e1e8d5e9..40a4047d53 100644
--- a/server/src/com/vaadin/ui/Slider.java
+++ b/server/src/com/vaadin/ui/Slider.java
@@ -16,9 +16,16 @@
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
index 0000000000..9ef28afb82
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/slider/SliderDeclarativeTest.java
@@ -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);
+ }
+}