]> source.dussan.org Git - vaadin-framework.git/commitdiff
Adds margin support to GridLayout declarative format (#18238)
authorTeppo Kurki <teppo.kurki@vaadin.com>
Thu, 11 Jun 2015 10:40:30 +0000 (13:40 +0300)
committerJohannes Dahlström <johannesd@vaadin.com>
Thu, 11 Jun 2015 14:36:51 +0000 (17:36 +0300)
Change-Id: I5561ccf38f6bac3a304f6e8ab6262cb8bd391021

server/src/com/vaadin/ui/GridLayout.java
server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTest.java [deleted file]
server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTestBase.java [new file with mode: 0644]
server/tests/src/com/vaadin/tests/server/component/abstractorderedlayout/AbstractOrderedLayoutDeclarativeTest.java
server/tests/src/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java

index 96b58d7e67f712b737b3bf5fdbab293987e9be25..6ccb272704bc5a05ac84276845f0d958e491590b 100644 (file)
@@ -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/DeclarativeMarginTest.java
deleted file mode 100644 (file)
index d31a93a..0000000
+++ /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<L extends Layout & MarginHandler>
-        extends DeclarativeTestBase<L> {
-
-    @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 = "<v-vertical-layout ";
-
-        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/DeclarativeMarginTestBase.java b/server/tests/src/com/vaadin/tests/server/component/DeclarativeMarginTestBase.java
new file mode 100644 (file)
index 0000000..9fcb64a
--- /dev/null
@@ -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<L extends Layout & MarginHandler>
+        extends DeclarativeTestBase<L> {
+
+    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 + " />";
+    }
+}
index 38bd68e6e1ec26d21efc997bd60ee3451dd1e55d..28ccfa407c37c02b8995ae879d1da2d4e319e612 100644 (file)
@@ -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<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);
index 7c9c12670739e28817b2183550b13125e57b81de..9d3b5001dabe4f9e97d2eae78911564b5ba63a8b 100644 (file)
@@ -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() {