]> source.dussan.org Git - vaadin-framework.git/commitdiff
Keep expand ratio for last row/column when reducing grid layout size (#20297)
authorArtur Signell <artur@vaadin.com>
Fri, 14 Oct 2016 19:11:59 +0000 (22:11 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 16 Nov 2016 07:31:08 +0000 (07:31 +0000)
Change-Id: Iff53a803596f4fc1eae8e4bfa307b9c1f4df961a

server/src/main/java/com/vaadin/ui/GridLayout.java
server/src/test/java/com/vaadin/tests/server/component/gridlayout/GridLayoutTest.java

index 66195c4a6fd0b4efc9c0008bb99ccde2b5ac489e..e0ad4408ca1c604151cc8ad8380eeb22188b2d87 100644 (file)
@@ -36,8 +36,6 @@ import org.jsoup.select.Elements;
 import com.vaadin.event.LayoutEvents.LayoutClickEvent;
 import com.vaadin.event.LayoutEvents.LayoutClickListener;
 import com.vaadin.event.LayoutEvents.LayoutClickNotifier;
-import com.vaadin.server.PaintException;
-import com.vaadin.server.PaintTarget;
 import com.vaadin.shared.Connector;
 import com.vaadin.shared.EventId;
 import com.vaadin.shared.MouseEventDetails;
@@ -447,6 +445,7 @@ public class GridLayout extends AbstractLayout
         return components.size();
     }
 
+    @Override
     public void beforeClientResponse(boolean initial) {
         super.beforeClientResponse(initial);
 
@@ -748,7 +747,7 @@ public class GridLayout extends AbstractLayout
 
         // Forget expands for removed columns
         if (columns < getColumns()) {
-            for (int i = columns - 1; i < getColumns(); i++) {
+            for (int i = columns; i < getColumns(); i++) {
                 columnExpandRatio.remove(i);
                 getState().explicitColRatios.remove(i);
             }
@@ -798,7 +797,7 @@ public class GridLayout extends AbstractLayout
         }
         // Forget expands for removed rows
         if (rows < getRows()) {
-            for (int i = rows - 1; i < getRows(); i++) {
+            for (int i = rows; i < getRows(); i++) {
                 rowExpandRatio.remove(i);
                 getState().explicitRowRatios.remove(i);
             }
index 1eabf2fb6250a93fa410d7fa59cb91612d73fe42..64b466612f9aeb299c3b8508b84d193ead3209ac 100644 (file)
@@ -75,6 +75,30 @@ public class GridLayoutTest {
         assertOrder(grid, new int[] { 0, 1, 2, 3 });
     }
 
+    @Test
+    public void removeRowsExpandRatiosPreserved() {
+        GridLayout gl = new GridLayout(3, 3);
+        gl.setRowExpandRatio(0, 0);
+        gl.setRowExpandRatio(1, 1);
+        gl.setRowExpandRatio(2, 2);
+
+        gl.setRows(2);
+        assertEquals(0, gl.getRowExpandRatio(0), 0);
+        assertEquals(1, gl.getRowExpandRatio(1), 0);
+    }
+
+    @Test
+    public void removeColsExpandRatiosPreserved() {
+        GridLayout gl = new GridLayout(3, 3);
+        gl.setColumnExpandRatio(0, 0);
+        gl.setColumnExpandRatio(1, 1);
+        gl.setColumnExpandRatio(2, 2);
+
+        gl.setColumns(2);
+        assertEquals(0, gl.getColumnExpandRatio(0), 0);
+        assertEquals(1, gl.getColumnExpandRatio(1), 0);
+    }
+
     private void assertContentPositions(GridLayout grid) {
         assertEquals(grid.getComponentCount(), children.length);
         int c = 0;