From 718b7dea773fddc47a316d82989e0759af6df67b Mon Sep 17 00:00:00 2001 From: John Ahlroos Date: Thu, 28 Feb 2013 09:31:32 +0200 Subject: Fixed scrolling jumping up to first row when adding rows and adjusting the currentPageFirstItem in the same UIDL request #10970 Change-Id: I54562e7e0c5429f3493892cf3a14380b0d15bbfd --- client/src/com/vaadin/client/ui/VScrollTable.java | 16 ++++++- .../components/table/TableRowScrolledBottom.html | 52 ++++++++++++++++++++ .../components/table/TableRowScrolledBottom.java | 55 ++++++++++++++++++++++ 3 files changed, 121 insertions(+), 2 deletions(-) create mode 100644 uitest/src/com/vaadin/tests/components/table/TableRowScrolledBottom.html create mode 100644 uitest/src/com/vaadin/tests/components/table/TableRowScrolledBottom.java 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 @@ + + + + + + +New Test + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
New Test
open/run/com.vaadin.tests.components.table.TableRowScrolledBottom?restartApplication
clickvaadin=runcomvaadintestscomponentstableTableRowScrolledBottom::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VButton[0]/domChild[0]
pause500
assertTextvaadin=runcomvaadintestscomponentstableTableRowScrolledBottom::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VScrollTable[0]/FocusableScrollPanel[0]/VScrollTable$VScrollTableBody[0]/VScrollTable$VScrollTableBody$VScrollTableRow[44]/VLabel[0]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
clickvaadin=runcomvaadintestscomponentstableTableRowScrolledBottom::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[1]/VButton[0]/domChild[0]/domChild[0]
pause500
assertTextvaadin=runcomvaadintestscomponentstableTableRowScrolledBottom::/VVerticalLayout[0]/Slot[1]/VVerticalLayout[0]/Slot[0]/VScrollTable[0]/FocusableScrollPanel[0]/VScrollTable$VScrollTableBody[0]/VScrollTable$VScrollTableBody$VScrollTableRow[44]/VLabel[0]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
+ + 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. " + + i + + ". 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; + } + +} -- cgit v1.2.3