]> source.dussan.org Git - vaadin-framework.git/commitdiff
Preserve scroll position of ListSelect after server round-trip if the 69/569/1
authorAnna Koskinen <anna@vaadin.com>
Thu, 3 Jan 2013 15:42:02 +0000 (17:42 +0200)
committerAnna Koskinen <anna@vaadin.com>
Thu, 3 Jan 2013 15:45:12 +0000 (17:45 +0200)
contents haven't changed (#10416)

Change-Id: I7effba1a4551c9c42996d9ca677afb43f16b51a4

client/src/com/vaadin/client/ui/VListSelect.java
uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.html [new file with mode: 0644]
uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.java [new file with mode: 0644]

index 2215906af6e385a16e83cf2d097cbd603cfed447..5fab520883ac4a45c3dbf7b3b623501294127a0e 100644 (file)
@@ -67,6 +67,8 @@ public class VListSelect extends VOptionGroupBase {
 
     @Override
     public void buildOptions(UIDL uidl) {
+        int scrollTop = select.getElement().getScrollTop();
+        int rowCount = getRows();
         select.setMultipleSelect(isMultiselect());
         select.clear();
         if (!isMultiselect() && isNullSelectionAllowed()
@@ -87,6 +89,12 @@ public class VListSelect extends VOptionGroupBase {
         if (getRows() > 0) {
             select.setVisibleItemCount(getRows());
         }
+        // FIXME: temporary hack for preserving the scroll state when the
+        // contents haven't been changed obviously. This should be dealt with in
+        // the rewrite.
+        if (rowCount == getRows()) {
+            select.getElement().setScrollTop(scrollTop);
+        }
     }
 
     @Override
diff --git a/uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.html b/uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.html
new file mode 100644 (file)
index 0000000..f066d48
--- /dev/null
@@ -0,0 +1,64 @@
+<?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="" />
+<title>ListSelectJump</title>
+</head>
+<body>
+<table cellpadding="1" cellspacing="1" border="1">
+<thead>
+<tr><td rowspan="1" colspan="3">ListSelectJump</td></tr>
+</thead><tbody>
+<tr>
+       <td>open</td>
+       <td>/run/com.vaadin.tests.components.listselect.ListSelectJump?restartApplication</td>
+       <td></td>
+</tr>
+<tr>
+       <td>addSelection</td>
+       <td>vaadin=runcomvaadintestscomponentslistselectListSelectJump::PID_Slistselect/domChild[0]</td>
+       <td>label=Option #1</td>
+</tr>
+<tr>
+       <td>scroll</td>
+       <td>vaadin=runcomvaadintestscomponentslistselectListSelectJump::PID_Slistselect/domChild[0]</td>
+       <td>135</td>
+</tr>
+<tr>
+       <td>pause</td>
+       <td>300</td>
+       <td></td>
+</tr>
+<tr>
+       <td>addSelection</td>
+       <td>vaadin=runcomvaadintestscomponentslistselectListSelectJump::PID_Slistselect/domChild[0]</td>
+       <td>label=Option #10</td>
+</tr>
+
+<!-- hack to get Chrome and Safari back to where they are supposed to be since addSelection breaks this for them -->
+<tr>
+       <td>scroll</td>
+       <td>vaadin=runcomvaadintestscomponentslistselectListSelectJump::PID_Slistselect/domChild[0]</td>
+       <td>135</td>
+</tr>
+<tr>
+       <td>pause</td>
+       <td>300</td>
+       <td></td>
+</tr>
+<tr>
+       <td>click</td>
+       <td>vaadin=runcomvaadintestscomponentslistselectListSelectJump::PID_Sbutton/domChild[0]/domChild[0]</td>
+       <td></td>
+</tr>
+<tr>
+       <td>screenCapture</td>
+       <td></td>
+       <td></td>
+</tr>
+
+</tbody></table>
+</body>
+</html>
diff --git a/uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.java b/uitest/src/com/vaadin/tests/components/listselect/ListSelectJump.java
new file mode 100644 (file)
index 0000000..47f6f33
--- /dev/null
@@ -0,0 +1,52 @@
+package com.vaadin.tests.components.listselect;
+
+import java.util.ArrayList;
+
+import com.vaadin.server.VaadinRequest;
+import com.vaadin.shared.ui.MarginInfo;
+import com.vaadin.shared.ui.label.ContentMode;
+import com.vaadin.tests.components.AbstractTestUI;
+import com.vaadin.ui.AbstractSelect;
+import com.vaadin.ui.Button;
+import com.vaadin.ui.Label;
+import com.vaadin.ui.ListSelect;
+
+public class ListSelectJump extends AbstractTestUI {
+
+    @Override
+    public void setup(VaadinRequest request) {
+        getLayout().setMargin(new MarginInfo(true, false, false, false));
+
+        addComponent(new Label(
+                "Instructions:<ol><li>Select Option #1</li><li><b>Also</b> select Option #10 (use meta-click)</li>"
+                        + "<li>Leave the Option #10 visible in the scroll window</li><li>Press the button</li></ol>"
+                        + "You will see the <code>ListSelect</code> scroll window jump back to the top.",
+                ContentMode.HTML));
+        ArrayList<String> list = new ArrayList<String>();
+        for (int i = 1; i <= 25; i++) {
+            list.add("Option #" + i);
+        }
+        ListSelect listSelect = new ListSelect(null, list);
+        listSelect.setNullSelectionAllowed(false);
+        listSelect.setMultiSelect(true);
+        listSelect.setImmediate(false);
+        listSelect.setRows(5);
+        listSelect.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID);
+        listSelect.setId("listselect");
+        addComponent(listSelect);
+        Button button = new Button("Press Me");
+        button.setId("button");
+        addComponent(button);
+    }
+
+    @Override
+    protected String getTestDescription() {
+        return "ListSelect jumps to top row after each client -> server contact";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 10416;
+    }
+
+}