aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--server/src/com/vaadin/ui/CheckBox.java50
-rw-r--r--server/tests/src/com/vaadin/tests/design/all-components.html3
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/checkbox/TestReadDesign.java67
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/checkbox/TestWriteDesign.java57
4 files changed, 177 insertions, 0 deletions
diff --git a/server/src/com/vaadin/ui/CheckBox.java b/server/src/com/vaadin/ui/CheckBox.java
index 7d9da30f29..e26e5c4750 100644
--- a/server/src/com/vaadin/ui/CheckBox.java
+++ b/server/src/com/vaadin/ui/CheckBox.java
@@ -16,6 +16,11 @@
package com.vaadin.ui;
+import java.util.Collection;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+
import com.vaadin.data.Property;
import com.vaadin.event.FieldEvents.BlurEvent;
import com.vaadin.event.FieldEvents.BlurListener;
@@ -25,6 +30,8 @@ import com.vaadin.event.FieldEvents.FocusListener;
import com.vaadin.shared.MouseEventDetails;
import com.vaadin.shared.ui.checkbox.CheckBoxServerRpc;
import com.vaadin.shared.ui.checkbox.CheckBoxState;
+import com.vaadin.ui.declarative.DesignAttributeHandler;
+import com.vaadin.ui.declarative.DesignContext;
public class CheckBox extends AbstractField<Boolean> {
@@ -203,4 +210,47 @@ public class CheckBox extends AbstractField<Boolean> {
Boolean value = getValue();
return (null == value) ? false : value.booleanValue();
}
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.ui.AbstractField#readDesign(org.jsoup.nodes.Element,
+ * com.vaadin.ui.declarative.DesignContext)
+ */
+ @Override
+ public void readDesign(Element design, DesignContext designContext) {
+ super.readDesign(design, designContext);
+ if (design.hasAttr("checked")) {
+ this.setValue(DesignAttributeHandler.readAttribute("checked",
+ design.attributes(), Boolean.class));
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.ui.AbstractField#getCustomAttributes()
+ */
+ @Override
+ protected Collection<String> getCustomAttributes() {
+ Collection<String> attributes = super.getCustomAttributes();
+ attributes.add("checked");
+ return attributes;
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.ui.AbstractField#writeDesign(org.jsoup.nodes.Element,
+ * com.vaadin.ui.declarative.DesignContext)
+ */
+ @Override
+ public void writeDesign(Element design, DesignContext designContext) {
+ super.writeDesign(design, designContext);
+ CheckBox def = (CheckBox) designContext.getDefaultInstance(this);
+ Attributes attr = design.attributes();
+ DesignAttributeHandler.writeAttribute("checked", attr, getValue(),
+ def.getValue(), Boolean.class);
+ }
+
}
diff --git a/server/tests/src/com/vaadin/tests/design/all-components.html b/server/tests/src/com/vaadin/tests/design/all-components.html
index 683fafcf05..0f16ea9363 100644
--- a/server/tests/src/com/vaadin/tests/design/all-components.html
+++ b/server/tests/src/com/vaadin/tests/design/all-components.html
@@ -102,6 +102,9 @@
<v-label>Hello world!</v-label>
<v-label>This is <b><u>Rich</u></b> content!</v-label>
<v-label plain-text>This is only <b>text</b> and will contain visible tags</v-label>
+
+ <!-- checkbox -->
+ <v-check-box checked/>
</v-vertical-layout>
</body>
</html>
diff --git a/server/tests/src/com/vaadin/tests/server/component/checkbox/TestReadDesign.java b/server/tests/src/com/vaadin/tests/server/component/checkbox/TestReadDesign.java
new file mode 100644
index 0000000000..529dd911e9
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/checkbox/TestReadDesign.java
@@ -0,0 +1,67 @@
+/*
+ * 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.checkbox;
+
+import junit.framework.TestCase;
+
+import org.jsoup.nodes.Attributes;
+import org.jsoup.nodes.Element;
+import org.jsoup.parser.Tag;
+import org.junit.Test;
+
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ *
+ * Test cases for reading the contents of a Checkbox from a design.
+ *
+ */
+public class TestReadDesign extends TestCase {
+
+ private DesignContext ctx;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ ctx = new DesignContext();
+ }
+
+ @Test
+ public void testChecked() {
+ Element e = createElement(true);
+ CheckBox box = (CheckBox) ctx.createChild(e);
+ assertEquals("The checkbox must be checked", Boolean.TRUE,
+ box.getValue());
+ }
+
+ @Test
+ public void testUnchecked() {
+ Element e = createElement(false);
+ CheckBox box = (CheckBox) ctx.createChild(e);
+ assertEquals("The checkbox must be unchecked", Boolean.FALSE,
+ box.getValue());
+ }
+
+ private Element createElement(boolean checked) {
+ Attributes attributes = new Attributes();
+ if (checked) {
+ attributes.put("checked", "");
+ }
+ Element node = new Element(Tag.valueOf("v-check-box"), "", attributes);
+ return node;
+ }
+} \ No newline at end of file
diff --git a/server/tests/src/com/vaadin/tests/server/component/checkbox/TestWriteDesign.java b/server/tests/src/com/vaadin/tests/server/component/checkbox/TestWriteDesign.java
new file mode 100644
index 0000000000..d187371db6
--- /dev/null
+++ b/server/tests/src/com/vaadin/tests/server/component/checkbox/TestWriteDesign.java
@@ -0,0 +1,57 @@
+/*
+ * 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.checkbox;
+
+import junit.framework.TestCase;
+
+import org.jsoup.nodes.Element;
+import org.junit.Test;
+
+import com.vaadin.ui.CheckBox;
+import com.vaadin.ui.declarative.DesignContext;
+
+/**
+ * Tests generating html tree nodes corresponding to the contents of a Checkbox
+ */
+public class TestWriteDesign extends TestCase {
+
+ private DesignContext ctx;
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ ctx = new DesignContext();
+ }
+
+ @Test
+ public void testChecked() {
+ CheckBox box = new CheckBox();
+ box.setValue(true);
+ Element e = ctx.createElement(box);
+ assertTrue("element must have checked attribute", e.hasAttr("checked"));
+ assertTrue("the checked attribute must be true", e.attr("checked")
+ .equals("true") || e.attr("checked").equals(""));
+ }
+
+ @Test
+ public void testUnchecked() {
+ CheckBox box = new CheckBox();
+ box.setValue(false);
+ Element e = ctx.createElement(box);
+ assertFalse("the element must not have checked attribute",
+ e.hasAttr("checked"));
+ }
+} \ No newline at end of file