From: Leif Åstrand Date: Wed, 1 Aug 2012 12:20:21 +0000 (+0000) Subject: Remember previous row height to maintain table size when all rows are removed (#9132) X-Git-Tag: 7.0.0.beta1~79^2~55 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=85c03155dc02e61dd10a9c861b064204bdeaca9f;p=vaadin-framework.git Remember previous row height to maintain table size when all rows are removed (#9132) svn changeset:24041/svn branch:6.8 --- diff --git a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java index fa7621e512..c1f90b0157 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java +++ b/src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java @@ -216,6 +216,19 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, private Set noncollapsibleColumns; + /** + * The last known row height used to preserve the height of a table with + * custom row heights and a fixed page length after removing the last row + * from the table. + * + * A new VScrollTableBody instance is created every time the number of rows + * changes causing {@link VScrollTableBody#rowHeight} to be discarded and + * the height recalculated by {@link VScrollTableBody#getRowHeight(boolean)} + * to avoid some rounding problems, e.g. round(2 * 19.8) / 2 = 20 but + * round(3 * 19.8) / 3 = 19.66. + */ + private double lastKnownRowHeight = Double.NaN; + /** * Represents a select range of rows */ @@ -4455,13 +4468,27 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, if (tBodyMeasurementsDone && !forceUpdate) { return rowHeight; } else { - if (tBodyElement.getRows().getLength() > 0) { int tableHeight = getTableHeight(); int rowCount = tBodyElement.getRows().getLength(); rowHeight = tableHeight / (double) rowCount; } else { - if (isAttached()) { + // Special cases if we can't just measure the current rows + if (!Double.isNaN(lastKnownRowHeight)) { + // Use previous value if available + if (BrowserInfo.get().isIE()) { + /* + * IE needs to reflow the table element at this + * point to work correctly (e.g. + * com.vaadin.tests.components.table. + * ContainerSizeChange) - the other code paths + * already trigger reflows, but here it must be done + * explicitly. + */ + getTableHeight(); + } + rowHeight = lastKnownRowHeight; + } else if (isAttached()) { // measure row height by adding a dummy row VScrollTableRow scrollTableRow = new VScrollTableRow(); tBodyElement.appendChild(scrollTableRow.getElement()); @@ -4472,6 +4499,7 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler, return DEFAULT_ROW_HEIGHT; } } + lastKnownRowHeight = rowHeight; tBodyMeasurementsDone = true; return rowHeight; } diff --git a/tests/testbench/com/vaadin/tests/components/table/TableRowNoHeightNoRows.html b/tests/testbench/com/vaadin/tests/components/table/TableRowNoHeightNoRows.html new file mode 100644 index 0000000000..35d64c3a0c --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/table/TableRowNoHeightNoRows.html @@ -0,0 +1,122 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.table.Tables?restartApplication
mouseClickvaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item029,11
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item540,5
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[1]/VMenuBar[0]#item153,9
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[2]/VMenuBar[0]#item04,6
mouseClickvaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item034,8
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item840,6
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[1]/VMenuBar[0]#item497,5
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[2]/VMenuBar[0]#item055,6
screenCapture1-no-rows-small
mouseClickvaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item023,5
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item526,1
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[1]/VMenuBar[0]#item168,10
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[2]/VMenuBar[0]#item118,13
screenCapture2-one-row-big
mouseClickvaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item028,10
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item534,6
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[1]/VMenuBar[0]#item162,4
mouseClickvaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[2]/VMenuBar[0]#item025,4
screenCapture3-no-rows-big
+ +