From 589d40758d0ee5182a8c217d60993fad2b79d6e0 Mon Sep 17 00:00:00 2001 From: Teppo Kurki Date: Thu, 11 Jun 2015 13:40:30 +0300 Subject: Adds margin support to GridLayout declarative format (#18238) Change-Id: I5561ccf38f6bac3a304f6e8ab6262cb8bd391021 --- server/src/com/vaadin/ui/GridLayout.java | 5 ++ .../server/component/DeclarativeMarginTest.java | 76 ---------------------- .../component/DeclarativeMarginTestBase.java | 72 ++++++++++++++++++++ .../AbstractOrderedLayoutDeclarativeTest.java | 9 ++- .../gridlayout/GridLayoutDeclarativeTest.java | 10 ++- 5 files changed, 92 insertions(+), 80 deletions(-) delete mode 100644 server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTest.java create mode 100644 server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTestBase.java 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/DeclarativeMarginTest.java deleted file mode 100644 index d31a93a68b..0000000000 --- a/server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTest.java +++ /dev/null @@ -1,76 +0,0 @@ -/* - * 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; - -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 - extends DeclarativeTestBase { - - @Test - public void testMargins() { - - for (int i = 0; i < 16; ++i) { - boolean top = (i & 1) == 1; - boolean right = (i & 2) == 2; - boolean bottom = (i & 4) == 4; - boolean left = (i & 8) == 8; - - MarginInfo m = new MarginInfo(top, right, bottom, left); - - String design = getMarginTag(top, right, bottom, left); - - // The assertEquals machinery in DeclarativeTestBase uses bean - // introspection and MarginInfo is not a proper bean. It ends up - // considering *all* MarginInfo objects equal... (#18229) - L layout = read(design); - Assert.assertEquals(m, layout.getMargin()); - - testWrite(design, layout); - } - } - - private String getMarginTag(boolean top, boolean right, boolean bottom, - boolean left) { - String s = ""; - } -} diff --git a/server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTestBase.java b/server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTestBase.java new file mode 100644 index 0000000000..9fcb64acca --- /dev/null +++ b/server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTestBase.java @@ -0,0 +1,72 @@ +/* + * 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; + +import org.junit.Assert; + +import com.vaadin.shared.ui.MarginInfo; +import com.vaadin.tests.design.DeclarativeTestBase; +import com.vaadin.ui.Layout; +import com.vaadin.ui.Layout.MarginHandler; + +public abstract class DeclarativeMarginTestBase + extends DeclarativeTestBase { + + protected void testMargins(String componentTag) { + + for (int i = 0; i < 16; ++i) { + boolean top = (i & 1) == 1; + boolean right = (i & 2) == 2; + boolean bottom = (i & 4) == 4; + boolean left = (i & 8) == 8; + + MarginInfo m = new MarginInfo(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 + // considering *all* MarginInfo objects equal... (#18229) + L layout = read(design); + Assert.assertEquals(m, layout.getMargin()); + + testWrite(design, 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'"; + } else { + if (left) { + s += "margin-left='true' "; + } + if (right) { + s += "margin-right='true' "; + } + if (top) { + s += "margin-top='true' "; + } + if (bottom) { + s += "margin-bottom='true' "; + } + } + return s + " />"; + } +} 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,11 +35,16 @@ import com.vaadin.ui.VerticalLayout; * @author Vaadin Ltd */ public class AbstractOrderedLayoutDeclarativeTest extends - DeclarativeMarginTest { + 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() { -- cgit v1.2.3