diff options
author | Anna Koskinen <Ansku@users.noreply.github.com> | 2019-05-14 15:05:12 +0300 |
---|---|---|
committer | Sun Zhe <31067185+ZheSun88@users.noreply.github.com> | 2019-05-16 13:32:54 +0300 |
commit | df3d68ec187b4fad87876b73e96d08713e2fd591 (patch) | |
tree | d2e7ecfb5fe97bfe80152cb100587b667565c125 | |
parent | 5cd93f9d5725e4b47129c11b7139d3653fe97ad0 (diff) | |
download | vaadin-framework-df3d68ec187b4fad87876b73e96d08713e2fd591.tar.gz vaadin-framework-df3d68ec187b4fad87876b73e96d08713e2fd591.zip |
Add handling for completely empty Grid's column width calculations. (#11569)
Fixes #11557
-rw-r--r-- | client/src/main/java/com/vaadin/client/widgets/Escalator.java | 8 | ||||
-rw-r--r-- | uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRowsOrHeaders.java | 60 |
2 files changed, 67 insertions, 1 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 c559c36c18..c60358e449 100644 --- a/client/src/main/java/com/vaadin/client/widgets/Escalator.java +++ b/client/src/main/java/com/vaadin/client/widgets/Escalator.java @@ -4669,6 +4669,9 @@ public class Escalator extends Widget double maxWidth = Math.max(headerWidth, Math.max(bodyWidth, footerWidth)); + if (maxWidth < 0 && header.getRowCount() == 0 && body.getRowCount() == 0 && footer.getRowCount() == 0) { + maxWidth = 0; + } assert maxWidth >= 0 : "Got a negative max width for a column, which should be impossible."; return maxWidth; } @@ -4681,7 +4684,10 @@ public class Escalator extends Widget double minWidth = Math.max(headerWidth, Math.max(bodyWidth, footerWidth)); - assert minWidth >= 0 : "Got a negative max width for a column, which should be impossible."; + if (minWidth < 0 && header.getRowCount() == 0 && body.getRowCount() == 0 && footer.getRowCount() == 0) { + minWidth = 0; + } + assert minWidth >= 0 : "Got a negative min width for a column, which should be impossible."; return minWidth; } diff --git a/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRowsOrHeaders.java b/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRowsOrHeaders.java new file mode 100644 index 0000000000..cc74696636 --- /dev/null +++ b/uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRowsOrHeaders.java @@ -0,0 +1,60 @@ +package com.vaadin.tests.components.grid; + +import java.util.ArrayList; +import java.util.List; + +import com.vaadin.server.VaadinRequest; +import com.vaadin.tests.components.AbstractTestUI; +import com.vaadin.ui.Button; +import com.vaadin.ui.Grid; +import com.vaadin.ui.Grid.SelectionMode; + +/** + * There is no corresponding TB test as this problem can only be reproduced + * using SuperDevMode. + */ +public class GridWithoutRowsOrHeaders extends AbstractTestUI { + + private int counter = 0; + + @Override + protected void setup(VaadinRequest request) { + List<Integer> data = new ArrayList<>(); + + Grid<Integer> grid = new Grid<>(); + grid.addColumn(Integer::valueOf).setCaption("ID").setId("id") + .setMaximumWidth(50d); + grid.addColumn(Integer::valueOf).setCaption("FOO").setId("foo") + .setMinimumWidth(50d); + grid.removeHeaderRow(grid.getHeaderRow(0)); + grid.setItems(data); + + grid.setSelectionMode(SelectionMode.NONE); + grid.setWidth("250px"); + grid.setHeightByRows(3); + addComponent(grid); + + addComponent(new Button("Add header row", e -> { + grid.addHeaderRowAt(0); + })); + addComponent(new Button("Add body row", e -> { + data.add(counter); + ++counter; + grid.getDataProvider().refreshAll(); + })); + addComponent(new Button("Add footer row", e -> { + grid.addFooterRowAt(0); + })); + } + + @Override + protected String getTestDescription() { + return "There should be no client-side assertion error from " + + "adding the Grid without contents (requires SuperDevMode)."; + } + + @Override + protected Integer getTicketNumber() { + return 11557; + } +} |