diff options
3 files changed, 107 insertions, 8 deletions
diff --git a/client/src/main/java/com/vaadin/client/widgets/Escalator.java b/client/src/main/java/com/vaadin/client/widgets/Escalator.java index 7d5cd8981b..898379106e 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -888,8 +888,8 @@ public class Escalator extends Widget if (position instanceof AbsolutePosition) { /* * we don't want to put "top: 0" on the footer, since it'll - * render wrong, as we already have - * "bottom: $footer-height". + * render wrong, as we already have "bottom: $footer-height" + * . */ footElem.getStyle().setLeft(-scrollLeft, Unit.PX); } else { @@ -1225,9 +1225,6 @@ public class Escalator extends Widget assertArgumentsAreValidAndWithinRange(index, numberOfRows); rows -= numberOfRows; - if (heightMode == HeightMode.UNDEFINED) { - heightByRows = rows; - } if (!isAttached()) { return; @@ -1351,9 +1348,6 @@ public class Escalator extends Widget } rows += numberOfRows; - if (heightMode == HeightMode.UNDEFINED) { - heightByRows = rows; - } /* * only add items in the DOM if the widget itself is attached to the @@ -2531,6 +2525,24 @@ public class Escalator extends Widget } @Override + public void insertRows(int index, int numberOfRows) { + super.insertRows(index, numberOfRows); + + if (heightMode == HeightMode.UNDEFINED) { + heightByRows = getRowCount(); + } + } + + @Override + public void removeRows(int index, int numberOfRows) { + super.removeRows(index, numberOfRows); + + if (heightMode == HeightMode.UNDEFINED) { + heightByRows = getRowCount(); + } + } + + @Override public void setStylePrimaryName(String primaryStyleName) { super.setStylePrimaryName(primaryStyleName); UIObject.setStylePrimaryName(root, primaryStyleName + "-body"); diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridUndefinedHeight.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridUndefinedHeight.java new file mode 100644 index 0000000000..5043729a2a --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridUndefinedHeight.java @@ -0,0 +1,40 @@ +package com.vaadin.tests.components.grid; + +import com.vaadin.annotations.Theme; +import com.vaadin.server.VaadinRequest; +import com.vaadin.shared.ui.grid.HeightMode; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Button.ClickEvent; +import com.vaadin.ui.Grid; +import com.vaadin.ui.VerticalLayout; + +@Theme("valo") +public class GridUndefinedHeight extends AbstractTestUI { + + @Override + protected void setup(VaadinRequest request) { + VerticalLayout layout = new VerticalLayout(); + + final Grid grid = new Grid(); + grid.addColumn("toString", String.class); + grid.addRow("Foo"); + grid.addRow("Bar"); + grid.addRow("Baz"); + grid.setHeightMode(HeightMode.UNDEFINED); + + layout.addComponents(grid, + new Button("Add header row", new Button.ClickListener() { + + @Override + public void buttonClick(ClickEvent event) { + grid.appendHeaderRow(); + } + })); + layout.setHeight("600px"); + layout.setExpandRatio(grid, 1.0f); + + addComponent(layout); + } + +}
\ No newline at end of file diff --git a/uitest/src/test/java/com/vaadin/tests/components/grid/GridUndefinedHeightTest.java b/uitest/src/test/java/com/vaadin/tests/components/grid/GridUndefinedHeightTest.java new file mode 100644 index 0000000000..19ca8c9f88 --- /dev/null +++ b/uitest/src/test/java/com/vaadin/tests/components/grid/GridUndefinedHeightTest.java @@ -0,0 +1,47 @@ +package com.vaadin.tests.components.grid; + +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import com.vaadin.testbench.elements.ButtonElement; +import com.vaadin.testbench.elements.GridElement; +import com.vaadin.testbench.parallel.TestCategory; +import com.vaadin.tests.tb3.SingleBrowserTest; + +@TestCategory("grid") +public class GridUndefinedHeightTest extends SingleBrowserTest { + + @Before + public void before() { + setDebug(true); + openTestURL(); + } + + @Test + public void grid_undefined_height() { + GridElement grid = $(GridElement.class).first(); + int oneRow = grid.getRow(0).getSize().getHeight(); + int gridHeight = grid.getSize().getHeight(); + int rows = 4; // Header Row + 3 Body Rows + + Assert.assertEquals("Grid height mismatch", oneRow * rows, gridHeight, 1); + + assertNoErrorNotifications(); + } + + @Test + public void grid_undefined_height_add_header() { + // Add header row to Grid + $(ButtonElement.class).first().click(); + + GridElement grid = $(GridElement.class).first(); + int oneRow = grid.getRow(0).getSize().getHeight(); + int gridHeight = grid.getSize().getHeight(); + int rows = 5; // 2 Header Rows + 3 Body Rows + + Assert.assertEquals("Grid height mismatch", oneRow * rows, gridHeight); + + assertNoErrorNotifications(); + } +}
\ No newline at end of file |