From 55ea6dce33bec44140984633a6d3aee7910b89da Mon Sep 17 00:00:00 2001 From: =?utf8?q?Leif=20=C3=85strand?= Date: Tue, 7 May 2013 13:06:34 +0000 Subject: [PATCH] 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 --- .../com/vaadin/client/ui/VScrollTable.java | 33 +++++-- .../treetable/RowHeightWithoutRows.html | 47 ++++++++++ .../treetable/RowHeightWithoutRows.java | 87 +++++++++++++++++++ 3 files changed, 161 insertions(+), 6 deletions(-) create mode 100644 tests/testbench/com/vaadin/tests/components/treetable/RowHeightWithoutRows.html create mode 100644 tests/testbench/com/vaadin/tests/components/treetable/RowHeightWithoutRows.java diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java index 4d61fba429..b03fa945cd 100644 --- a/client/src/com/vaadin/client/ui/VScrollTable.java +++ b/client/src/com/vaadin/client/ui/VScrollTable.java @@ -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; } diff --git a/tests/testbench/com/vaadin/tests/components/treetable/RowHeightWithoutRows.html b/tests/testbench/com/vaadin/tests/components/treetable/RowHeightWithoutRows.html new file mode 100644 index 0000000000..e8cb0ccfe6 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/treetable/RowHeightWithoutRows.html @@ -0,0 +1,47 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.treetable.RowHeightWithoutRows?restartApplication=
screenCapturetwo
clickvaadin=runcomvaadintestscomponentstreetableRowHeightWithoutRows::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[2]/VButton[0]/domChild[0]/domChild[0]
screenCaptureempty
clickvaadin=runcomvaadintestscomponentstreetableRowHeightWithoutRows::/VVerticalLayout[0]/ChildComponentContainer[1]/VVerticalLayout[0]/ChildComponentContainer[3]/VButton[0]/domChild[0]/domChild[0]
screenCapturefive
+ + diff --git a/tests/testbench/com/vaadin/tests/components/treetable/RowHeightWithoutRows.java b/tests/testbench/com/vaadin/tests/components/treetable/RowHeightWithoutRows.java new file mode 100644 index 0000000000..5e94fc1270 --- /dev/null +++ b/tests/testbench/com/vaadin/tests/components/treetable/RowHeightWithoutRows.java @@ -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 container = new BeanItemContainer( + 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); + } +} \ No newline at end of file -- 2.39.5