]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix for #4542 + JUnit test + Test Application
authorJohn Alhroos <john.ahlroos@itmill.com>
Wed, 19 May 2010 10:37:24 +0000 (10:37 +0000)
committerJohn Alhroos <john.ahlroos@itmill.com>
Wed, 19 May 2010 10:37:24 +0000 (10:37 +0000)
svn changeset:13251/svn branch:6.3

src/com/vaadin/ui/GridLayout.java
tests/src/com/vaadin/tests/layouts/GridLayoutRemoveFinalRow.java [new file with mode: 0644]
tests/src/com/vaadin/tests/server/components/TestGridLayoutLastRowRemoval.java [new file with mode: 0644]

index 19abe8d14213ee9b2c7f2930aecb3bf498be990b..1e31eb9b65b18e65648d854be1d3bdc9d4da8150 100644 (file)
@@ -1183,6 +1183,10 @@ public class GridLayout extends AbstractLayout implements
      * Removes row and all components in the row. Components which span over
      * several rows are removed if the selected row is the component's first
      * row.
+     * <p>
+     * If the last row is removed then all remaining components will be removed
+     * and the grid will be reduced to one row and one column.
+     * </p>
      * 
      * @param row
      *            The row number to remove
@@ -1210,9 +1214,18 @@ public class GridLayout extends AbstractLayout implements
             }
         }
 
-        setRows(rows - 1);
-        if (cursorY > row) {
-            cursorY--;
+        if (rows == 1) {
+            /*
+             * Removing the last row means that the dimensions of the Grid
+             * layout will be truncated to 1x1 and all components removed.
+             */
+            setColumns(1);
+            cursorY = 0;
+        } else {
+            setRows(rows - 1);
+            if (cursorY > row) {
+                cursorY--;
+            }
         }
 
         structuralChange = true;
diff --git a/tests/src/com/vaadin/tests/layouts/GridLayoutRemoveFinalRow.java b/tests/src/com/vaadin/tests/layouts/GridLayoutRemoveFinalRow.java
new file mode 100644 (file)
index 0000000..db765e0
--- /dev/null
@@ -0,0 +1,46 @@
+package com.vaadin.tests.layouts;
+
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Button.ClickEvent;
+
+/**
+ * Tests removing rows from a GridLayout
+ */
+@SuppressWarnings("serial")
+public class GridLayoutRemoveFinalRow extends TestBase {
+
+    @Override
+    protected void setup() {
+        getLayout().setSpacing(true);
+
+        final GridLayout layout = new GridLayout(2, 2);
+        layout.setSpacing(true);
+        layout.addComponent(new Label("Label1"));
+        layout.addComponent(new Label("Label2"));
+        layout.addComponent(new Label("Label3"));
+        layout.addComponent(new Label("Label4"));
+        addComponent(layout);
+
+        Button removeRowBtn = new Button("Remove row",
+                new Button.ClickListener() {
+                    public void buttonClick(ClickEvent event) {
+                        layout.removeRow(0);
+                    }
+                });
+        addComponent(removeRowBtn);
+    }
+
+    @Override
+    protected String getDescription() {
+        return "Removing last row of a GridLayout throws a IllegalArgumentException";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 4542;
+    }
+
+}
diff --git a/tests/src/com/vaadin/tests/server/components/TestGridLayoutLastRowRemoval.java b/tests/src/com/vaadin/tests/server/components/TestGridLayoutLastRowRemoval.java
new file mode 100644 (file)
index 0000000..8881b9e
--- /dev/null
@@ -0,0 +1,32 @@
+package com.vaadin.tests.server.components;
+
+import junit.framework.TestCase;
+
+import com.vaadin.ui.GridLayout;
+import com.vaadin.ui.Label;
+
+public class TestGridLayoutLastRowRemoval extends TestCase {
+
+    public void testRemovingLastRow() {
+        GridLayout grid = new GridLayout(2, 1);
+        grid.addComponent(new Label("Col1"));
+        grid.addComponent(new Label("Col2"));
+
+        try {
+            // Removing the last row in the grid
+            grid.removeRow(0);
+        } catch (IllegalArgumentException iae) {
+            // Removing the last row should not throw an
+            // IllegalArgumentException
+            fail("removeRow(0) threw an IllegalArgumentExcetion when removing the last row");
+        }
+
+        // The grid should now be empty with one row and one column
+        assertEquals(1, grid.getColumns());
+        assertEquals(1, grid.getRows());
+
+        // There should be no component left in the grid layout
+        assertNull("A component should not be left in the layout", grid
+                .getComponent(0, 0));
+    }
+}