diff options
author | Teppo Kurki <teppo.kurki@vaadin.com> | 2015-06-11 13:40:30 +0300 |
---|---|---|
committer | Johannes Dahlström <johannesd@vaadin.com> | 2015-06-11 17:36:51 +0300 |
commit | 589d40758d0ee5182a8c217d60993fad2b79d6e0 (patch) | |
tree | 5e8d25061ec7e97eab09903fef108c714f8a4a19 | |
parent | 5518f840da8ee64a075a9f3f6ae4333ae43a2322 (diff) | |
download | vaadin-framework-589d40758d0ee5182a8c217d60993fad2b79d6e0.tar.gz vaadin-framework-589d40758d0ee5182a8c217d60993fad2b79d6e0.zip |
Adds margin support to GridLayout declarative format (#18238)
Change-Id: I5561ccf38f6bac3a304f6e8ab6262cb8bd391021
-rw-r--r-- | server/src/com/vaadin/ui/GridLayout.java | 5 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTestBase.java (renamed from server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTest.java) | 16 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java | 9 | ||||
-rw-r--r-- | server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java | 10 |
4 files changed, 26 insertions, 14 deletions
diff --git a/server/src/com/vaadin/ui/GridLayout.java b/server/src/com/vaadin/ui/GridLayout.java index 96b58d7e67..6ccb272704 100644 --- a/server/src/com/vaadin/ui/GridLayout.java +++ b/server/src/com/vaadin/ui/GridLayout.java @@ -1317,6 +1317,8 @@ public class GridLayout extends AbstractLayout implements public void readDesign(Element design, DesignContext designContext) { super.readDesign(design, designContext); + setMargin(readMargin(design, getMargin(), designContext)); + // Prepare a 2D map for reading column contents Elements rowElements = design.getElementsByTag("row"); List<Map<Integer, Component>> rows = new ArrayList<Map<Integer, Component>>(); @@ -1447,6 +1449,9 @@ public class GridLayout extends AbstractLayout implements super.writeDesign(design, designContext); GridLayout def = designContext.getDefaultInstance(this); + + writeMargin(design, getMargin(), def.getMargin(), designContext); + if (components.isEmpty() || !designContext.shouldWriteChildren(this, def)) { return; diff --git a/server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTest.java b/server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTestBase.java index d31a93a68b..9fcb64acca 100644 --- a/server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTestBase.java @@ -16,20 +16,16 @@ package com.vaadin.tests.server.component; import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; import com.vaadin.shared.ui.MarginInfo; import com.vaadin.tests.design.DeclarativeTestBase; import com.vaadin.ui.Layout; import com.vaadin.ui.Layout.MarginHandler; -@Ignore -public abstract class DeclarativeMarginTest<L extends Layout & MarginHandler> +public abstract class DeclarativeMarginTestBase<L extends Layout & MarginHandler> extends DeclarativeTestBase<L> { - @Test - public void testMargins() { + protected void testMargins(String componentTag) { for (int i = 0; i < 16; ++i) { boolean top = (i & 1) == 1; @@ -39,7 +35,7 @@ public abstract class DeclarativeMarginTest<L extends Layout & MarginHandler> MarginInfo m = new MarginInfo(top, right, bottom, left); - String design = getMarginTag(top, right, bottom, left); + String design = getMarginTag(componentTag, top, right, bottom, left); // The assertEquals machinery in DeclarativeTestBase uses bean // introspection and MarginInfo is not a proper bean. It ends up @@ -51,9 +47,9 @@ public abstract class DeclarativeMarginTest<L extends Layout & MarginHandler> } } - private String getMarginTag(boolean top, boolean right, boolean bottom, - boolean left) { - String s = "<v-vertical-layout "; + private String getMarginTag(String componentTag, boolean top, + boolean right, boolean bottom, boolean left) { + String s = "<" + componentTag + " "; if (left && right && top && bottom) { s += "margin='true'"; diff --git a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java index 38bd68e6e1..28ccfa407c 100644 --- a/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java @@ -21,7 +21,7 @@ import java.util.List; import org.junit.Test; import com.vaadin.shared.ui.label.ContentMode; -import com.vaadin.tests.server.component.DeclarativeMarginTest; +import com.vaadin.tests.server.component.DeclarativeMarginTestBase; import com.vaadin.ui.AbstractOrderedLayout; import com.vaadin.ui.Alignment; import com.vaadin.ui.Button; @@ -35,12 +35,17 @@ import com.vaadin.ui.VerticalLayout; * @author Vaadin Ltd */ public class AbstractOrderedLayoutDeclarativeTest extends - DeclarativeMarginTest<AbstractOrderedLayout> { + DeclarativeMarginTestBase<AbstractOrderedLayout> { private List<String> defaultAlignments = Arrays.asList(new String[] { ":top", ":left" }); @Test + public void testMargins() { + testMargins("v-vertical-layout"); + } + + @Test public void testExpandRatio() { String design = getDesign(1); AbstractOrderedLayout layout = getLayout(1, null); diff --git a/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java b/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java index 7c9c126707..9d3b5001da 100644 --- a/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java +++ b/server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java @@ -18,13 +18,19 @@ package com.vaadin.tests.server.component.gridlayout; import org.junit.Assert; import org.junit.Test; -import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.tests.server.component.DeclarativeMarginTestBase; import com.vaadin.ui.Button; import com.vaadin.ui.Component; import com.vaadin.ui.GridLayout; import com.vaadin.ui.declarative.DesignContext; -public class GridLayoutDeclarativeTest extends DeclarativeTestBase<GridLayout> { +public class GridLayoutDeclarativeTest extends + DeclarativeMarginTestBase<GridLayout> { + + @Test + public void testMargins() { + testMargins("v-grid-layout"); + } @Test public void testSimpleGridLayout() { |