Browse Source

More specific workaround for no rows in TreeTable with pagelenght = 0 (#9203)

svn changeset:25915/svn branch:6.8

Conflicts:
	client/src/com/vaadin/client/ui/VScrollTable.java

Change-Id: I3f5b9dc988f5911023f77f184f5bd6770bbd9f1b
tags/7.0.6
Leif Åstrand 11 years ago
parent
commit
55ea6dce33

+ 27
- 6
client/src/com/vaadin/client/ui/VScrollTable.java View File

@@ -1113,10 +1113,10 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
if (firstvisible != lastRequestedFirstvisible && scrollBody != null) {
// received 'surprising' firstvisible from server: scroll there
firstRowInViewPort = firstvisible;
/*
* Schedule the scrolling to be executed last so no updates to the rows
* affect scrolling measurements.
* Schedule the scrolling to be executed last so no updates to the
* rows affect scrolling measurements.
*/
Scheduler.get().scheduleFinally(lazyScroller);
}
@@ -2104,6 +2104,15 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
* might have been (incorrectly) calculated earlier
*/

/*
* TreeTable updates stuff in a funky order, so we must set the
* height as zero here before doing the real update to make it
* realize that there is no content,
*/
if (pageLength == totalRows && pageLength == 0) {
scrollBody.setHeight("0px");
}

int bodyHeight;
if (pageLength == totalRows) {
/*
@@ -3056,7 +3065,7 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
.hasNext(); columnIndex++) {
if (it.next() == this) {
break;
}
}
}
}
final int cw = scrollBody.getColWidth(columnIndex);
@@ -4796,8 +4805,20 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
prepx = 0;
}
preSpacer.getStyle().setPropertyPx("height", prepx);
int postpx = measureRowHeightOffset(totalRows - 1)
- measureRowHeightOffset(lastRendered);
int postpx;
if (pageLength == 0 && totalRows == pageLength) {
/*
* TreeTable depends on having lastRendered out of sync in some
* situations, which makes this method miss the special
* situation in which one row worth of post spacer to be added
* if there are no rows in the table. #9203
*/
postpx = measureRowHeightOffset(1);
} else {
postpx = measureRowHeightOffset(totalRows - 1)
- measureRowHeightOffset(lastRendered);
}

if (postpx < 0) {
postpx = 0;
}

+ 47
- 0
tests/testbench/com/vaadin/tests/components/treetable/RowHeightWithoutRows.html View File

@@ -0,0 +1,47 @@
<?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="http://localhost:8888/" />
<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.treetable.RowHeightWithoutRows?restartApplication=</td>
<td></td>
</tr>
<tr>
<td>screenCapture</td>
<td></td>
<td>two</td>
</tr>
<tr>
<td>click</td>
<td>vaadin=runcomvaadintestscomponentstreetableRowHeightWithoutRows::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]</td>
<td></td>
</tr>
<tr>
<td>screenCapture</td>
<td></td>
<td>empty</td>
</tr>
<tr>
<td>click</td>
<td>vaadin=runcomvaadintestscomponentstreetableRowHeightWithoutRows::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]</td>
<td></td>
</tr>
<tr>
<td>screenCapture</td>
<td></td>
<td>five</td>
</tr>

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

+ 87
- 0
tests/testbench/com/vaadin/tests/components/treetable/RowHeightWithoutRows.java View File

@@ -0,0 +1,87 @@
package com.vaadin.tests.components.treetable;

import com.vaadin.data.util.BeanItemContainer;
import com.vaadin.tests.components.TestBase;
import com.vaadin.ui.Button;
import com.vaadin.ui.Button.ClickEvent;
import com.vaadin.ui.Button.ClickListener;
import com.vaadin.ui.TreeTable;

public class RowHeightWithoutRows extends TestBase {

private TreeTable treeTable = new TreeTable();

private BeanItemContainer<User> container = new BeanItemContainer<User>(
User.class);

@Override
public void setup() {
treeTable.setContainerDataSource(container);
treeTable.setPageLength(0);

addComponent(treeTable);

Button refresh = new Button("Add two elements");
addComponent(refresh);
refresh.addListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
addTwoElements();
}
});

Button reset = new Button("Reset");
addComponent(reset);
reset.addListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
container.removeAllItems();
}
});

Button refresh5 = new Button("Add five elements");
addComponent(refresh5);
refresh5.addListener(new ClickListener() {
public void buttonClick(ClickEvent event) {
container.addBean(new User("John", "Doe"));
container.addBean(new User("Mark", "Twain"));
container.addBean(new User("M", "T"));
container.addBean(new User("J", "D"));
container.addBean(new User("J", "T"));
}
});
addTwoElements();
}

private void addTwoElements() {
container.addBean(new User("John", "Doe"));
container.addBean(new User("Mark", "Twain"));
}

public static class User {
private String firstName;

private String lastName;

public User(String firstName, String lastName) {
this.firstName = firstName;
this.lastName = lastName;
}

public String getFirstName() {
return firstName;
}

public String getLastName() {
return lastName;
}
}

@Override
protected String getDescription() {
return "Reseting the tree table and then adding five elements should properly update the height of the TreeTable";
}

@Override
protected Integer getTicketNumber() {
return Integer.valueOf(9203);
}
}

Loading…
Cancel
Save