* 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
}
}
- 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;
--- /dev/null
+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;
+ }
+
+}
--- /dev/null
+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));
+ }
+}