summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatti Hosio <mhosio@vaadin.com>2014-12-10 12:42:41 +0200
committerVaadin Code Review <review@vaadin.com>2014-12-10 15:20:55 +0000
commita0e1fe4b61ff2b2bf1e35f983e1926b6fa694020 (patch)
tree2120d2fe0ecd044c673e15ebe24ce6c0e18370f3
parent5d6271489b2ce52f3c4eb3ce40cc1148c1092501 (diff)
downloadvaadin-framework-a0e1fe4b61ff2b2bf1e35f983e1926b6fa694020.tar.gz
vaadin-framework-a0e1fe4b61ff2b2bf1e35f983e1926b6fa694020.zip
Add support for margins in AbstractOrderedLayout (#7749)
Change-Id: I9793d37998549c410e9e17dc14402acc3b85f4f0
-rw-r--r--server/src/com/vaadin/ui/AbstractOrderedLayout.java30
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java32
-rw-r--r--server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeToDesign.java10
3 files changed, 62 insertions, 10 deletions
diff --git a/server/src/com/vaadin/ui/AbstractOrderedLayout.java b/server/src/com/vaadin/ui/AbstractOrderedLayout.java
index 87b2ff6f48..afe7a65d67 100644
--- a/server/src/com/vaadin/ui/AbstractOrderedLayout.java
+++ b/server/src/com/vaadin/ui/AbstractOrderedLayout.java
@@ -16,6 +16,7 @@
package com.vaadin.ui;
+import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.logging.Logger;
@@ -481,6 +482,17 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
super.synchronizeFromDesign(design, designContext);
// remove current children
removeAllComponents();
+ // handle margin
+ AbstractOrderedLayout def = designContext.getDefaultInstance(this
+ .getClass());
+ if (design.hasAttr("margin")) {
+ String value = design.attr("margin");
+ setMargin(value.isEmpty() || value.equalsIgnoreCase("true"));
+
+ } else {
+ // we currently support only on-off margins
+ setMargin(def.getMargin().getBitMask() != 0);
+ }
// handle children
for (Node childComponent : design.childNodes()) {
if (childComponent instanceof Element) {
@@ -535,6 +547,12 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
public void synchronizeToDesign(Element design, DesignContext designContext) {
// synchronize default attributes
super.synchronizeToDesign(design, designContext);
+ // handle margin
+ AbstractOrderedLayout def = designContext.getDefaultInstance(this
+ .getClass());
+ if (getMargin().getBitMask() != def.getMargin().getBitMask()) {
+ design.attr("margin", "");
+ }
// handle children
Element designElement = design;
for (Component child : this) {
@@ -564,6 +582,18 @@ public abstract class AbstractOrderedLayout extends AbstractLayout implements
}
}
+ /*
+ * (non-Javadoc)
+ *
+ * @see com.vaadin.ui.AbstractComponent#getCustomAttributes()
+ */
+ @Override
+ protected Collection<String> getCustomAttributes() {
+ Collection<String> customAttributes = super.getCustomAttributes();
+ customAttributes.add("margin");
+ return customAttributes;
+ }
+
private static Logger getLogger() {
return Logger.getLogger(AbstractOrderedLayout.class.getName());
}
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java
index 028578e8ea..6e57aac95b 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeFromDesign.java
@@ -35,51 +35,63 @@ import com.vaadin.ui.declarative.DesignContext;
public class TestSynchronizeFromDesign extends TestCase {
public void testChildCount() {
- VerticalLayout root = createLayout(0f);
+ VerticalLayout root = createLayout(0f, false);
assertEquals(2, root.getComponentCount());
}
+ public void testMargin() {
+ VerticalLayout root = createLayout(0f, true);
+ assertTrue(root.getMargin().getBitMask() != 0);
+ root = createLayout(0f, false);
+ assertTrue(root.getMargin().getBitMask() == 0);
+ }
+
public void testAttributes() {
- VerticalLayout root = createLayout(0f);
+ VerticalLayout root = createLayout(0f, false);
assertEquals("test-layout", root.getCaption());
assertEquals("test-label", root.getComponent(0).getCaption());
assertEquals("test-button", root.getComponent(1).getCaption());
}
public void testExpandRatio() {
- VerticalLayout root = createLayout(1f);
+ VerticalLayout root = createLayout(1f, false);
assertEquals(1f, root.getExpandRatio(root.getComponent(0)));
assertEquals(1f, root.getExpandRatio(root.getComponent(1)));
- root = createLayout(0f);
+ root = createLayout(0f, false);
assertEquals(0f, root.getExpandRatio(root.getComponent(0)));
assertEquals(0f, root.getExpandRatio(root.getComponent(1)));
}
public void testAlignment() {
- VerticalLayout root = createLayout(0f, ":top", ":left");
+ VerticalLayout root = createLayout(0f, false, ":top", ":left");
assertEquals(Alignment.TOP_LEFT,
root.getComponentAlignment(root.getComponent(0)));
- root = createLayout(0f, ":middle", ":center");
+ root = createLayout(0f, false, ":middle", ":center");
assertEquals(Alignment.MIDDLE_CENTER,
root.getComponentAlignment(root.getComponent(0)));
- root = createLayout(0f, ":bottom", ":right");
+ root = createLayout(0f, false, ":bottom", ":right");
assertEquals(Alignment.BOTTOM_RIGHT,
root.getComponentAlignment(root.getComponent(0)));
}
- private VerticalLayout createLayout(float expandRatio, String... alignments) {
+ private VerticalLayout createLayout(float expandRatio, boolean margin,
+ String... alignments) {
DesignContext ctx = new DesignContext();
- Element design = createDesign(expandRatio, alignments);
+ Element design = createDesign(expandRatio, margin, alignments);
DesignSynchronizable child = ctx.createChild(design);
return (VerticalLayout) child;
}
- private Element createDesign(float expandRatio, String... alignments) {
+ private Element createDesign(float expandRatio, boolean margin,
+ String... alignments) {
Attributes rootAttributes = new Attributes();
rootAttributes.put("caption", "test-layout");
+ if (margin) {
+ rootAttributes.put("margin", "");
+ }
Element node = new Element(Tag.valueOf("v-vertical-layout"), "",
rootAttributes);
diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeToDesign.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeToDesign.java
index 55f1763397..23cf15cd13 100644
--- a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeToDesign.java
+++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/TestSynchronizeToDesign.java
@@ -34,6 +34,16 @@ import com.vaadin.ui.declarative.DesignContext;
*/
public class TestSynchronizeToDesign extends TestCase {
+ public void testSynchronizeMargin() {
+ VerticalLayout layout = new VerticalLayout();
+ layout.setMargin(true);
+ Element design = createDesign();
+ layout.synchronizeToDesign(design, createDesignContext());
+ assertTrue("The margin must be written", design.hasAttr("margin"));
+ assertTrue("The margin must be empty or true", design.attr("margin")
+ .equals("") || design.attr("margin").equalsIgnoreCase("true"));
+ }
+
public void testSynchronizeEmptyLayout() {
VerticalLayout layout = new VerticalLayout();
layout.setCaption("changed-caption");