aboutsummaryrefslogtreecommitdiffstats
path: root/server/src
diff options
context:
space:
mode:
authorTien Nguyen <nqtien.dev@gmail.com>2017-04-04 17:39:24 +0300
committerIlia Motornyi <elmot@vaadin.com>2017-04-04 16:39:24 +0200
commit1a30320913e8b9ea851af3ed4a659f969aa92ee6 (patch)
tree195bbd2c65d79ae4cd50824b411ab42b9548ce03 /server/src
parent973564d475617298e5cb9c7e9286d5d3e40dcf66 (diff)
downloadvaadin-framework-1a30320913e8b9ea851af3ed4a659f969aa92ee6.tar.gz
vaadin-framework-1a30320913e8b9ea851af3ed4a659f969aa92ee6.zip
Fix bug column and row expand ratio are not persisted
Fixes #9009
Diffstat (limited to 'server/src')
-rw-r--r--server/src/main/java/com/vaadin/ui/GridLayout.java16
-rw-r--r--server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java29
2 files changed, 31 insertions, 14 deletions
diff --git a/server/src/main/java/com/vaadin/ui/GridLayout.java b/server/src/main/java/com/vaadin/ui/GridLayout.java
index a9607ca96f..5a02f49fb8 100644
--- a/server/src/main/java/com/vaadin/ui/GridLayout.java
+++ b/server/src/main/java/com/vaadin/ui/GridLayout.java
@@ -1277,14 +1277,14 @@ public class GridLayout extends AbstractLayout
}
setRows(Math.max(rows.size(), 1));
Map<Component, Alignment> alignments = new HashMap<>();
- List<Integer> columnExpandRatios = new ArrayList<>();
+ List<Float> columnExpandRatios = new ArrayList<>();
for (int row = 0; row < rowElements.size(); ++row) {
Element rowElement = rowElements.get(row);
// Row Expand
if (rowElement.hasAttr("expand")) {
- int expand = DesignAttributeHandler.readAttribute("expand",
- rowElement.attributes(), int.class);
+ float expand = DesignAttributeHandler.readAttribute("expand",
+ rowElement.attributes(), float.class);
setRowExpandRatio(row, expand);
}
@@ -1334,11 +1334,11 @@ public class GridLayout extends AbstractLayout
if (row == 0) {
if (col.hasAttr("expand")) {
for (String expand : col.attr("expand").split(",")) {
- columnExpandRatios.add(Integer.parseInt(expand));
+ columnExpandRatios.add(Float.parseFloat(expand));
}
} else {
for (int c = 0; c < colspan; ++c) {
- columnExpandRatios.add(0);
+ columnExpandRatios.add(0f);
}
}
}
@@ -1442,7 +1442,7 @@ public class GridLayout extends AbstractLayout
// Row Expand
DesignAttributeHandler.writeAttribute("expand", row.attributes(),
- (int) getRowExpandRatio(i), 0, int.class, designContext);
+ getRowExpandRatio(i), 0.0f, float.class, designContext);
int colspan = 1;
Element col;
@@ -1483,7 +1483,7 @@ public class GridLayout extends AbstractLayout
// A column with expand and no content in the end of
// first row needs to be present.
for (int c = j; c < componentMap[i].length; ++c) {
- if ((int) getColumnExpandRatio(c) > 0) {
+ if (getColumnExpandRatio(c) > 0) {
hasExpands = true;
}
}
@@ -1525,7 +1525,7 @@ public class GridLayout extends AbstractLayout
String expands = "";
boolean expandRatios = false;
for (int c = 0; c < colspan; ++c) {
- int colExpand = (int) getColumnExpandRatio(j + c);
+ float colExpand = getColumnExpandRatio(j + c);
if (colExpand > 0) {
expandRatios = true;
}
diff --git a/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java b/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java
index 146810d4bf..d1367f5349 100644
--- a/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java
+++ b/server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutDeclarativeTest.java
@@ -52,8 +52,8 @@ public class GridLayoutDeclarativeTest
b3.setCaptionAsHtml(true);
b4.setCaptionAsHtml(true);
String design = "<vaadin-grid-layout><row>" //
- + "<column expand=1>" + writeChild(b1) + "</column>" //
- + "<column expand=3>" + writeChild(b2) + "</column>" //
+ + "<column expand=1.0>" + writeChild(b1) + "</column>" //
+ + "<column expand=3.3>" + writeChild(b2) + "</column>" //
+ "</row><row>" //
+ "<column>" + writeChild(b3) + "</column>" //
+ "<column>" + writeChild(b4) + "</column>" //
@@ -63,13 +63,30 @@ public class GridLayoutDeclarativeTest
gl.addComponent(b2);
gl.addComponent(b3);
gl.addComponent(b4);
- gl.setColumnExpandRatio(0, 1.0f);
- gl.setColumnExpandRatio(1, 3.0f);
+ gl.setColumnExpandRatio(0, 1f);
+ gl.setColumnExpandRatio(1, 3.3f);
testWrite(design, gl);
testRead(design, gl);
}
@Test
+ public void testReadIntegerExpandRatioGridLayout() {
+ //To make sure that it can read from old declarative which use
+ // integer expand ratio
+ Button b1 = new Button("Button 0,0");
+ b1.setCaptionAsHtml(true);
+ String design = "<vaadin-grid-layout><row expand=3>" //
+ + "<column expand=1>" + writeChild(b1) + "</column>" //
+ + "</row>"//
+ + "</vaadin-grid-layout>";
+ GridLayout gl = new GridLayout(1, 1);
+ gl.addComponent(b1);
+ gl.setColumnExpandRatio(0, 1.0f);
+ gl.setRowExpandRatio(0, 3.0f);
+ testRead(design, gl);
+ }
+
+ @Test
public void testOneBigComponentGridLayout() {
Button b1 = new Button("Button 0,0 -&gt; 1,1");
b1.setCaptionAsHtml(true);
@@ -153,7 +170,7 @@ public class GridLayoutDeclarativeTest
gl.setColumnExpandRatio(2, 2.0f);
String design = "<vaadin-grid-layout><row>" //
- + "<column colspan=4 rowspan=5 expand='0,0,2,0' />" //
+ + "<column colspan=4 rowspan=5 expand='0.0,0.0,2.0,0.0' />" //
+ "<column rowspan=5>" + writeChild(b1) + "</column>" //
+ "</row><row>" //
+ "</row><row>" //
@@ -174,7 +191,7 @@ public class GridLayoutDeclarativeTest
String design = "<vaadin-grid-layout><row>" //
+ "<column rowspan=5>" + writeChild(b1) + "</column>" //
- + "<column colspan=4 rowspan=5 expand='0,0,0,2' />" //
+ + "<column colspan=4 rowspan=5 expand='0.0,0.0,0.0,2.0' />" //
+ "</row><row>" //
+ "</row><row>" //
+ "</row><row>" //