Browse Source

Add handling for completely empty Grid's column width calculations. (#11569)

Fixes #11557
tags/8.9.0.alpha1
Anna Koskinen 5 years ago
parent
commit
fb01d9a438

+ 7
- 1
client/src/main/java/com/vaadin/client/widgets/Escalator.java View File

@@ -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;
}


+ 60
- 0
uitest/src/main/java/com/vaadin/tests/components/grid/GridWithoutRowsOrHeaders.java View File

@@ -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;
}
}

Loading…
Cancel
Save