summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Ahlroos <john@vaadin.com>2013-02-28 09:31:32 +0200
committerVaadin Code Review <review@vaadin.com>2013-03-04 13:30:08 +0000
commit718b7dea773fddc47a316d82989e0759af6df67b (patch)
tree50dd5a04e5e02f63da72620633830d4a6724922e
parentda5a55ccdf3c5a1732ae246c43370051633c9265 (diff)
downloadvaadin-framework-718b7dea773fddc47a316d82989e0759af6df67b.tar.gz
vaadin-framework-718b7dea773fddc47a316d82989e0759af6df67b.zip
Fixed scrolling jumping up to first row when adding rows and adjusting the currentPageFirstItem in the same UIDL request #10970
Change-Id: I54562e7e0c5429f3493892cf3a14380b0d15bbfd
-rw-r--r--client/src/com/vaadin/client/ui/VScrollTable.java16
-rw-r--r--uitest/src/com/vaadin/tests/components/table/TableRowScrolledBottom.html52
-rw-r--r--uitest/src/com/vaadin/tests/components/table/TableRowScrolledBottom.java55
3 files changed, 121 insertions, 2 deletions
diff --git a/client/src/com/vaadin/client/ui/VScrollTable.java b/client/src/com/vaadin/client/ui/VScrollTable.java
index c76dd38d8f..6f9fd6da88 100644
--- a/client/src/com/vaadin/client/ui/VScrollTable.java
+++ b/client/src/com/vaadin/client/ui/VScrollTable.java
@@ -1098,6 +1098,14 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
}
}
+ private ScheduledCommand lazyScroller = new ScheduledCommand() {
+ @Override
+ public void execute() {
+ int offsetTop = measureRowHeightOffset(firstvisible);
+ scrollBodyPanel.setScrollPosition(offsetTop);
+ }
+ };
+
/** For internal use only. May be removed or replaced in the future. */
public void updateFirstVisibleAndScrollIfNeeded(UIDL uidl) {
firstvisible = uidl.hasVariable("firstvisible") ? uidl
@@ -1105,8 +1113,12 @@ public class VScrollTable extends FlowPanel implements HasWidgets,
if (firstvisible != lastRequestedFirstvisible && scrollBody != null) {
// received 'surprising' firstvisible from server: scroll there
firstRowInViewPort = firstvisible;
- scrollBodyPanel
- .setScrollPosition(measureRowHeightOffset(firstvisible));
+
+ /*
+ * Schedule the scrolling to be executed last so no updates to the rows
+ * affect scrolling measurements.
+ */
+ Scheduler.get().scheduleFinally(lazyScroller);
}
}
diff --git a/uitest/src/com/vaadin/tests/components/table/TableRowScrolledBottom.html b/uitest/src/com/vaadin/tests/components/table/TableRowScrolledBottom.html
new file mode 100644
index 0000000000..e5b1f47f2d
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/TableRowScrolledBottom.html
@@ -0,0 +1,52 @@
+<?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.table.TableRowScrolledBottom?restartApplication</td>
+ <td></td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentstableTableRowScrolledBottom::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VButton[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>pause</td>
+ <td>500</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentstableTableRowScrolledBottom::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VScrollTable[0]/FocusableScrollPanel[0]/VScrollTable$VScrollTableBody[0]/VScrollTable$VScrollTableBody$VScrollTableRow[44]/VLabel[0]</td>
+ <td>This is a test item with long text so that there is something to see Nr. 100. This text must be long otherwise the timing issue on Firefox does not occur. This works fine in IE</td>
+</tr>
+<tr>
+ <td>click</td>
+ <td>vaadin=runcomvaadintestscomponentstableTableRowScrolledBottom::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]</td>
+ <td></td>
+</tr>
+<tr>
+ <td>pause</td>
+ <td>500</td>
+ <td></td>
+</tr>
+<tr>
+ <td>assertText</td>
+ <td>vaadin=runcomvaadintestscomponentstableTableRowScrolledBottom::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VScrollTable[0]/FocusableScrollPanel[0]/VScrollTable$VScrollTableBody[0]/VScrollTable$VScrollTableBody$VScrollTableRow[44]/VLabel[0]</td>
+ <td>This is a test item with long text so that there is something to see Nr. 200. This text must be long otherwise the timing issue on Firefox does not occur. This works fine in IE</td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/table/TableRowScrolledBottom.java b/uitest/src/com/vaadin/tests/components/table/TableRowScrolledBottom.java
new file mode 100644
index 0000000000..9823fc1859
--- /dev/null
+++ b/uitest/src/com/vaadin/tests/components/table/TableRowScrolledBottom.java
@@ -0,0 +1,55 @@
+package com.vaadin.tests.components.table;
+
+import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.tests.components.TestBase;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.VerticalLayout;
+
+public class TableRowScrolledBottom extends TestBase {
+
+ @Override
+ protected void setup() {
+
+ final Table table = new Table();
+ table.setSizeFull();
+ table.addContainerProperty("Test", Label.class, null);
+ table.setHeight("100%");
+
+ Button button = new Button("Add 100 items");
+ button.addClickListener(new Button.ClickListener() {
+ int i = 0;
+
+ @Override
+ public void buttonClick(Button.ClickEvent event) {
+ for (int j = 0; j < 100; j++) {
+ ++i;
+ table.addItem(
+ new Object[] { new Label(
+ "This is a test item with long text so that there is something to see Nr. <b>"
+ + i
+ + "</b>. This text must be long otherwise the timing issue on Firefox does not occur. This works fine in IE",
+ ContentMode.HTML) }, i);
+ table.setCurrentPageFirstItemIndex(table
+ .getContainerDataSource().size() - 1);
+ }
+ }
+ });
+
+ addComponent(table);
+ addComponent(button);
+ getLayout().setExpandRatio(table, 1f);
+ }
+
+ @Override
+ protected String getDescription() {
+ return "Table should be scrolled to bottom when adding rows and updating currentPageFirstItemIndex to last item";
+ }
+
+ @Override
+ protected Integer getTicketNumber() {
+ return 10970;
+ }
+
+}