]> source.dussan.org Git - vaadin-framework.git/commitdiff
Test case and fix for #2214 - Filterselect navigation problem when moving up to first...
authorArtur Signell <artur.signell@itmill.com>
Mon, 16 Feb 2009 07:50:19 +0000 (07:50 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 16 Feb 2009 07:50:19 +0000 (07:50 +0000)
svn changeset:6843/svn branch:trunk

src/com/itmill/toolkit/terminal/gwt/client/ui/IFilterSelect.java
src/com/itmill/toolkit/tests/components/combobox/ComboBoxNavigation.java [new file with mode: 0644]

index c7d224c70ebf51f54f630c1782593b15bf295b27..450db45620e019744e1d0239bc4a34baa0ccc0f7 100644 (file)
@@ -8,6 +8,7 @@ import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Date;
 import java.util.Iterator;
+import java.util.List;
 
 import com.google.gwt.user.client.Command;
 import com.google.gwt.user.client.DOM;
@@ -713,9 +714,17 @@ public class IFilterSelect extends Composite implements Paintable, Field,
                 // we're paging w/ arrows
                 if (lastIndex == 0) {
                     // going up, select last item
-                    suggestionPopup.menu
-                            .selectItem((MenuItem) suggestionPopup.menu
-                                    .getItems().get(PAGELENTH - 1));
+                    int lastItem = PAGELENTH - 1;
+                    List items = suggestionPopup.menu.getItems();
+                    /*
+                     * The first page can contain less than 10 items if the null
+                     * selection item is filtered away
+                     */
+                    if (lastItem >= items.size()) {
+                        lastItem = items.size() - 1;
+                    }
+                    suggestionPopup.menu.selectItem((MenuItem) items
+                            .get(lastItem));
                 } else {
                     // going down, select first item
                     suggestionPopup.menu
diff --git a/src/com/itmill/toolkit/tests/components/combobox/ComboBoxNavigation.java b/src/com/itmill/toolkit/tests/components/combobox/ComboBoxNavigation.java
new file mode 100644 (file)
index 0000000..85b1bb1
--- /dev/null
@@ -0,0 +1,30 @@
+package com.itmill.toolkit.tests.components.combobox;
+
+import com.itmill.toolkit.tests.components.TestBase;
+import com.itmill.toolkit.ui.ComboBox;
+
+public class ComboBoxNavigation extends TestBase {
+
+    @Override
+    protected String getDescription() {
+        return "Entering e in the field and scrolling down with the arrow keys should always select the next item, also when the page changes. Scrolling back up should always select the previous item, also when changing pages.";
+    }
+
+    @Override
+    protected Integer getTicketNumber() {
+        return 2214;
+    }
+
+    @Override
+    protected void setup() {
+        ComboBox cb = new ComboBox();
+        for (int i = 1; i < 100; i++) {
+            cb.addItem("Item " + i);
+        }
+
+        cb.setFilteringMode(ComboBox.FILTERINGMODE_CONTAINS);
+        addComponent(cb);
+
+    }
+
+}