Browse Source

Remember previous row height to maintain table size when all rows are removed (#9132)

svn changeset:24041/svn branch:6.8
tags/7.0.0.beta1
Leif Åstrand 12 years ago
parent
commit
85c03155dc

+ 30
- 2
src/com/vaadin/terminal/gwt/client/ui/VScrollTable.java View File

@@ -216,6 +216,19 @@ public class VScrollTable extends FlowPanel implements Table, ScrollHandler,

private Set<String> 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;
}

+ 122
- 0
tests/testbench/com/vaadin/tests/components/table/TableRowNoHeightNoRows.html View File

@@ -0,0 +1,122 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head profile="http://selenium-ide.openqa.org/profiles/test-case">
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link rel="selenium.base" href="" />
<title>New Test</title>
</head>
<body>
<table cellpadding="1" cellspacing="1" border="1">
<thead>
<tr><td rowspan="1" colspan="3">New Test</td></tr>
</thead><tbody>
<tr>
<td>open</td>
<td>/run/com.vaadin.tests.components.table.Tables?restartApplication</td>
<td></td>
</tr>
<!--Remove all rows-->
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item0</td>
<td>29,11</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item5</td>
<td>40,5</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[1]/VMenuBar[0]#item1</td>
<td>53,9</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[2]/VMenuBar[0]#item0</td>
<td>4,6</td>
</tr>
<!--Add generated column-->
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item0</td>
<td>34,8</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item8</td>
<td>40,6</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[1]/VMenuBar[0]#item4</td>
<td>97,5</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[2]/VMenuBar[0]#item0</td>
<td>55,6</td>
</tr>
<!--Screenshot of initial state-->
<tr>
<td>screenCapture</td>
<td></td>
<td>1-no-rows-small</td>
</tr>
<!--Add a row to make the row height increase-->
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item0</td>
<td>23,5</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item5</td>
<td>26,1</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[1]/VMenuBar[0]#item1</td>
<td>68,10</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[2]/VMenuBar[0]#item1</td>
<td>18,13</td>
</tr>
<tr>
<td>screenCapture</td>
<td></td>
<td>2-one-row-big</td>
</tr>
<!--Remove the row - height should be retained-->
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::PID_Smenu#item0</td>
<td>28,10</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[0]/VMenuBar[0]#item5</td>
<td>34,6</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[1]/VMenuBar[0]#item1</td>
<td>62,4</td>
</tr>
<tr>
<td>mouseClick</td>
<td>vaadin=runcomvaadintestscomponentstableTables::Root/VOverlay[2]/VMenuBar[0]#item0</td>
<td>25,4</td>
</tr>
<tr>
<td>screenCapture</td>
<td></td>
<td>3-no-rows-big</td>
</tr>

</tbody></table>
</body>
</html>

Loading…
Cancel
Save