]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix table scrolling up on select (#10106)
authorJuuso Valli <juuso@vaadin.com>
Tue, 29 Apr 2014 09:48:07 +0000 (12:48 +0300)
committerVaadin Code Review <review@vaadin.com>
Wed, 14 May 2014 07:34:28 +0000 (07:34 +0000)
Change-Id: I4d13bee983817ce299d1f7e52ddd6cdc725fee6f

client/src/com/vaadin/client/ui/orderedlayout/AbstractOrderedLayoutConnector.java
uitest/src/com/vaadin/tests/components/table/TableScrollUpOnSelect.java [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/table/TableScrollUpOnSelectTest.java [new file with mode: 0644]

index 449665a72ecc4efcc6c5b72ce8972a9e450fde80..918b7fbdaae5a5d9fa759dfe655f5e254081611a 100644 (file)
@@ -17,6 +17,8 @@ package com.vaadin.client.ui.orderedlayout;
 
 import java.util.List;
 
+import com.google.gwt.core.client.Scheduler;
+import com.google.gwt.core.client.Scheduler.ScheduledCommand;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.Style.Unit;
 import com.google.gwt.user.client.ui.Widget;
@@ -493,7 +495,15 @@ public abstract class AbstractOrderedLayoutConnector extends
         updateLayoutHeight();
         if (needsExpand()) {
             getWidget().updateExpandedSizes();
-            getWidget().updateExpandCompensation();
+            // updateExpandedSizes causes fixed size components to temporarily
+            // lose their size. updateExpandCompensation must be delayed until
+            // the browser has a chance to measure them.
+            Scheduler.get().scheduleFinally(new ScheduledCommand() {
+                @Override
+                public void execute() {
+                    getWidget().updateExpandCompensation();
+                }
+            });
         } else {
             getWidget().clearExpand();
         }
diff --git a/uitest/src/com/vaadin/tests/components/table/TableScrollUpOnSelect.java b/uitest/src/com/vaadin/tests/components/table/TableScrollUpOnSelect.java
new file mode 100644 (file)
index 0000000..0e2e1b7
--- /dev/null
@@ -0,0 +1,89 @@
+/*
+ * Copyright 2000-2014 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.table;
+
+import com.vaadin.data.Property.ValueChangeEvent;
+import com.vaadin.data.Property.ValueChangeListener;
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.Table;
+import com.vaadin.ui.TextField;
+import com.vaadin.ui.VerticalLayout;
+import com.vaadin.ui.Window;
+
+/**
+ * Test to see if Table appears to scroll up under an obscure set of conditions
+ * (Scrolled down, set to expand, selecting updates a TextField that precedes
+ * the Table in a VerticalLayout.) (#10106)
+ * 
+ * @author Vaadin Ltd
+ */
+public class TableScrollUpOnSelect extends AbstractTestUI {
+    public TextField text = null;
+
+    @Override
+    protected void setup(VaadinRequest request) {
+        text = new TextField();
+        text.setImmediate(true);
+
+        final Table table = new Table(null);
+        table.addContainerProperty("value", Integer.class, 0);
+        for (int i = 0; i < 50; ++i) {
+            table.addItem(new Object[] { i }, i);
+        }
+        table.setSizeFull();
+        table.setSelectable(true);
+        table.setImmediate(true);
+        table.setEditable(false);
+
+        final VerticalLayout layout = new VerticalLayout();
+
+        table.addValueChangeListener(new ValueChangeListener() {
+
+            @Override
+            public void valueChange(ValueChangeEvent event) {
+                if (table.getValue() != null) {
+                    text.setValue(table.getValue().toString());
+                }
+            }
+
+        });
+
+        table.setCurrentPageFirstItemIndex(49);
+
+        layout.setSizeFull();
+        layout.addComponent(text);
+        layout.addComponent(table);
+        layout.setExpandRatio(table, 1.0f);
+        Window window = new Window();
+        window.setHeight("600px");
+        window.setWidth("400px");
+        window.setModal(true);
+        window.setContent(layout);
+        getUI().addWindow(window);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "Table scrolls up when selecting a row";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 13358;
+    }
+
+}
diff --git a/uitest/src/com/vaadin/tests/components/table/TableScrollUpOnSelectTest.java b/uitest/src/com/vaadin/tests/components/table/TableScrollUpOnSelectTest.java
new file mode 100644 (file)
index 0000000..b2fde31
--- /dev/null
@@ -0,0 +1,59 @@
+/*
+ * Copyright 2000-2013 Vaadin Ltd.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.vaadin.tests.components.table;
+
+import org.junit.Assert;
+import org.junit.Test;
+import org.openqa.selenium.WebDriver;
+import org.openqa.selenium.WebElement;
+import org.openqa.selenium.support.ui.ExpectedCondition;
+
+import com.vaadin.testbench.By;
+import com.vaadin.testbench.elements.TableElement;
+import com.vaadin.tests.tb3.MultiBrowserTest;
+
+/**
+ * Test to see if Table appears to scroll up under an obscure set of conditions
+ * (Scrolled down, set to expand, selecting updates a TextField that precedes
+ * the Table in a VerticalLayout.) (#10106)
+ * 
+ * @author Vaadin Ltd
+ */
+public class TableScrollUpOnSelectTest extends MultiBrowserTest {
+
+    @Test
+    public void TestThatSelectingDoesntScroll() {
+        openTestURL();
+
+        // WebElement table = driver.findElement(By.vaadin("//Table"));
+        WebElement row = $(TableElement.class).first().getCell(49, 0);
+        final WebElement scrollPositionDisplay = getDriver().findElement(
+                By.className("v-table-scrollposition"));
+        waitUntilNot(new ExpectedCondition<Boolean>() {
+
+            @Override
+            public Boolean apply(WebDriver input) {
+                return scrollPositionDisplay.isDisplayed();
+            }
+        }, 10);
+
+        int rowLocation = row.getLocation().getY();
+        row.click();
+        int newRowLocation = row.getLocation().getY();
+
+        Assert.assertTrue("Table has scrolled.", rowLocation == newRowLocation);
+    }
+}