]> source.dussan.org Git - vaadin-framework.git/commitdiff
Defer Grid scrolling to avoid issues with DataSource sizes (#16189)
authorTeemu Suo-Anttila <teemusa@vaadin.com>
Tue, 13 Jan 2015 12:58:26 +0000 (14:58 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 13 Jan 2015 20:20:45 +0000 (20:20 +0000)
Change-Id: I47868ff8b139ffc8c3c95ee6cafa95b76be67914

client/src/com/vaadin/client/connectors/GridConnector.java
uitest/src/com/vaadin/tests/components/grid/GridSingleColumn.java
uitest/src/com/vaadin/tests/components/grid/GridSingleColumnTest.java

index 593a8c85745697318db3e81feba4b985d34a0060..a2e63fc397c6c461b892f305d97106bd1c3a4856 100644 (file)
@@ -27,6 +27,8 @@ import java.util.Map;
 import java.util.Set;
 import java.util.logging.Logger;
 
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 import com.google.gwt.user.client.ui.Widget;
 import com.vaadin.client.ComponentConnector;
 import com.vaadin.client.ConnectorHierarchyChangeEvent;
@@ -363,17 +365,33 @@ public class GridConnector extends AbstractHasComponentsConnector implements
         registerRpc(GridClientRpc.class, new GridClientRpc() {
             @Override
             public void scrollToStart() {
-                getWidget().scrollToStart();
+                Scheduler.get().scheduleFinally(new ScheduledCommand() {
+                    @Override
+                    public void execute() {
+                        getWidget().scrollToStart();
+                    }
+                });
             }
 
             @Override
             public void scrollToEnd() {
-                getWidget().scrollToEnd();
+                Scheduler.get().scheduleFinally(new ScheduledCommand() {
+                    @Override
+                    public void execute() {
+                        getWidget().scrollToEnd();
+                    }
+                });
             }
 
             @Override
-            public void scrollToRow(int row, ScrollDestination destination) {
-                getWidget().scrollToRow(row, destination);
+            public void scrollToRow(final int row,
+                    final ScrollDestination destination) {
+                Scheduler.get().scheduleFinally(new ScheduledCommand() {
+                    @Override
+                    public void execute() {
+                        getWidget().scrollToRow(row, destination);
+                    }
+                });
             }
         });
 
index e9987db1a852ee3c8deb052bcb0d4f46df141c96..2ab02821026ef54556c85817a710c55d668d5eb1 100644 (file)
@@ -44,6 +44,7 @@ public class GridSingleColumn extends AbstractTestUI {
         column.setHeaderCaption("Header");
 
         addComponent(grid);
+        grid.scrollTo(grid.getContainerDataSource().getIdByIndex(50));
     }
 
     @Override
index 05f6b4b9f7aba7b2c9d47815974450448a8fe693..42eb2197bf00ad5896e85408c0ff0afa6233a32a 100644 (file)
@@ -20,6 +20,7 @@ import org.junit.Test;
 
 import com.vaadin.testbench.elements.GridElement;
 import com.vaadin.testbench.elements.GridElement.GridCellElement;
+import com.vaadin.testbench.elements.NotificationElement;
 import com.vaadin.tests.annotations.TestCategory;
 import com.vaadin.tests.tb3.MultiBrowserTest;
 
@@ -27,11 +28,20 @@ import com.vaadin.tests.tb3.MultiBrowserTest;
 public class GridSingleColumnTest extends MultiBrowserTest {
 
     @Test
-    public void headerIsVisible() {
+    public void testHeaderIsVisible() {
         openTestURL();
 
         GridCellElement cell = $(GridElement.class).first().getHeaderCell(0, 0);
         Assert.assertTrue("No header available", cell.getText()
                 .equalsIgnoreCase("header"));
     }
+
+    @Test
+    public void testScrollDidNotThrow() {
+        setDebug(true);
+        openTestURL();
+
+        Assert.assertFalse("Exception when scrolling on init",
+                isElementPresent(NotificationElement.class));
+    }
 }