From: Teppo Kurki Date: Sun, 7 Jun 2015 20:54:37 +0000 (+0300) Subject: Forget GridLayout row expand ratios for removed rows (#18166) X-Git-Tag: 7.5.0.rc1~25 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=b0d5315e8ba95d099f93dc2d16339033a6525b59;p=vaadin-framework.git Forget GridLayout row expand ratios for removed rows (#18166) Change-Id: I90a28fbc9c7eadac56a1d505d7cc80bb67342aae --- diff --git a/server/src/com/vaadin/ui/GridLayout.java b/server/src/com/vaadin/ui/GridLayout.java index e510fa09fb..96b58d7e67 100644 --- a/server/src/com/vaadin/ui/GridLayout.java +++ b/server/src/com/vaadin/ui/GridLayout.java @@ -833,7 +833,13 @@ public class GridLayout extends AbstractLayout implements } } } - // TODO forget expands for removed rows + // Forget expands for removed rows + if (rows < getRows()) { + for (int i = rows - 1; i < getRows(); i++) { + rowExpandRatio.remove(i); + getState().explicitRowRatios.remove(i); + } + } getState().rows = rows; } diff --git a/server/tests/src/com/vaadin/ui/GridLayoutExpandRatioTest.java b/server/tests/src/com/vaadin/ui/GridLayoutExpandRatioTest.java index 685befaab4..617c7f54ed 100644 --- a/server/tests/src/com/vaadin/ui/GridLayoutExpandRatioTest.java +++ b/server/tests/src/com/vaadin/ui/GridLayoutExpandRatioTest.java @@ -30,6 +30,7 @@ public class GridLayoutExpandRatioTest { public void testColExpandRatioIsForgotten() { gridLayout = new GridLayout(4, 1); gridLayout.setWidth(100, Unit.PERCENTAGE); + gridLayout.setSizeFull(); gridLayout.setSpacing(true); addComponents(true); @@ -46,7 +47,9 @@ public class GridLayoutExpandRatioTest { assertFalse(gridLayout.getState().explicitColRatios.contains(2)); assertTrue(gridLayout.getState().explicitColRatios.contains(3)); - remove(); + gridLayout.removeAllComponents(); + gridLayout.setColumns(3); + addComponents(false); assertTrue(gridLayout.getColumnExpandRatio(0) == 0); assertTrue(gridLayout.getColumnExpandRatio(1) == 1); @@ -56,13 +59,41 @@ public class GridLayoutExpandRatioTest { assertTrue(gridLayout.getState().explicitColRatios.contains(1)); assertFalse(gridLayout.getState().explicitColRatios.contains(2)); assertFalse(gridLayout.getState().explicitColRatios.contains(3)); - } - private void remove() { + @Test + public void testRowExpandRatioIsForgotten() { + gridLayout = new GridLayout(1, 4); + gridLayout.setWidth(100, Unit.PERCENTAGE); + gridLayout.setSizeFull(); + gridLayout.setSpacing(true); + + addComponents(true); + + gridLayout.setRowExpandRatio(1, 1); + gridLayout.setRowExpandRatio(3, 1); + + assertTrue(gridLayout.getRowExpandRatio(0) == 0); + assertTrue(gridLayout.getRowExpandRatio(1) == 1); + assertTrue(gridLayout.getRowExpandRatio(2) == 0); + assertTrue(gridLayout.getRowExpandRatio(3) == 1); + assertFalse(gridLayout.getState().explicitRowRatios.contains(0)); + assertTrue(gridLayout.getState().explicitRowRatios.contains(1)); + assertFalse(gridLayout.getState().explicitRowRatios.contains(2)); + assertTrue(gridLayout.getState().explicitRowRatios.contains(3)); + gridLayout.removeAllComponents(); - gridLayout.setColumns(3); + gridLayout.setRows(3); addComponents(false); + + assertTrue(gridLayout.getRowExpandRatio(0) == 0); + assertTrue(gridLayout.getRowExpandRatio(1) == 1); + assertTrue(gridLayout.getRowExpandRatio(2) == 0); + assertTrue(gridLayout.getRowExpandRatio(3) == 0); + assertFalse(gridLayout.getState().explicitRowRatios.contains(0)); + assertTrue(gridLayout.getState().explicitRowRatios.contains(1)); + assertFalse(gridLayout.getState().explicitRowRatios.contains(2)); + assertFalse(gridLayout.getState().explicitRowRatios.contains(3)); } private void addComponents(boolean includeLastOne) {