From 40bfdbf83d2e622aa826c8b66f3e2ad7d29ddb6b Mon Sep 17 00:00:00 2001 From: Teppo Kurki Date: Thu, 11 Jun 2015 13:40:30 +0300 Subject: [PATCH] Adds margin support to GridLayout declarative format (#18238) Change-Id: I5561ccf38f6bac3a304f6e8ab6262cb8bd391021 --- server/src/com/vaadin/ui/GridLayout.java | 5 +++++ ...nTest.java => DeclarativeMarginTestBase.java} | 16 ++++++---------- .../AbstractOrderedLayoutDeclarativeTest.java | 9 +++++++-- .../gridlayout/GridLayoutDeclarativeTest.java | 10 ++++++++-- 4 files changed, 26 insertions(+), 14 deletions(-) rename server/tests/src/com/vaadin/tests/server/component/{DeclarativeMarginTest.java => DeclarativeMarginTestBase.java} (83%) 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> rows = new ArrayList>(); @@ -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 similarity index 83% rename from server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTest.java rename to 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 +public abstract class DeclarativeMarginTestBase extends DeclarativeTestBase { - @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 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 } } - private String getMarginTag(boolean top, boolean right, boolean bottom, - boolean left) { - String s = " { + DeclarativeMarginTestBase { private List defaultAlignments = Arrays.asList(new String[] { ":top", ":left" }); + @Test + public void testMargins() { + testMargins("v-vertical-layout"); + } + @Test public void testExpandRatio() { String design = getDesign(1); 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 { +public class GridLayoutDeclarativeTest extends + DeclarativeMarginTestBase { + + @Test + public void testMargins() { + testMargins("v-grid-layout"); + } @Test public void testSimpleGridLayout() { -- 2.39.5