]> source.dussan.org Git - vaadin-framework.git/commitdiff
Forget GridLayout row expand ratios for removed rows (#18166)
authorTeppo Kurki <teppo.kurki@vaadin.com>
Sun, 7 Jun 2015 20:54:37 +0000 (23:54 +0300)
committerVaadin Code Review <review@vaadin.com>
Mon, 8 Jun 2015 07:19:06 +0000 (07:19 +0000)
Change-Id: I90a28fbc9c7eadac56a1d505d7cc80bb67342aae

server/src/com/vaadin/ui/GridLayout.java
server/tests/src/com/vaadin/ui/GridLayoutExpandRatioTest.java

index e510fa09fbcb2a7efbdcf8ef3ea09b3d56f99504..96b58d7e67f712b737b3bf5fdbab293987e9be25 100644 (file)
@@ -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;
     }
index 685befaab4411fbfe79301a09b8d3d084c23efff..617c7f54ed70775d5bc7af45987d1ce7e75aeb14 100644 (file)
@@ -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) {