]> source.dussan.org Git - vaadin-framework.git/commitdiff
#5053 Last ComboBox item may not be shown if null selection enabled: test case and fix
authorHenri Sara <henri.sara@itmill.com>
Wed, 26 May 2010 10:29:49 +0000 (10:29 +0000)
committerHenri Sara <henri.sara@itmill.com>
Wed, 26 May 2010 10:29:49 +0000 (10:29 +0000)
svn changeset:13371/svn branch:6.3

src/com/vaadin/terminal/gwt/client/ui/VFilterSelect.java
tests/src/com/vaadin/tests/tickets/Ticket5053.java [new file with mode: 0644]

index 32b2323f95a1f5096063979bf0e14e7950c6e4f2..66e712f4dac37e8b285c95f53a5fea4b3f4a33fb 100644 (file)
@@ -200,11 +200,13 @@ public class VFilterSelect extends Composite implements Paintable, Field,
             topPosition += tb.getOffsetHeight();
             setPopupPosition(x, topPosition);
 
-            final int first = currentPage * pageLength
-                    + (nullSelectionAllowed && currentPage > 0 ? 0 : 1);
-            final int last = first + currentSuggestions.size() - 1;
-            final int matches = totalSuggestions
-                    - (nullSelectionAllowed ? 1 : 0);
+            int nullOffset = (nullSelectionAllowed ? 1 : 0);
+            boolean firstPage = (currentPage == 0);
+            final int first = currentPage * pageLength + 1
+                    - (firstPage ? 0 : nullOffset);
+            final int last = first + currentSuggestions.size() - 1
+                    - (firstPage ? nullOffset : 0);
+            final int matches = totalSuggestions - nullOffset;
             if (last > 0) {
                 // nullsel not counted, as requested by user
                 DOM.setInnerText(status, (matches == 0 ? 0 : first)
@@ -217,7 +219,7 @@ public class VFilterSelect extends Composite implements Paintable, Field,
             }
             // We don't need to show arrows or statusbar if there is only one
             // page
-            if (matches <= pageLength) {
+            if (totalSuggestions <= pageLength) {
                 setPagingEnabled(false);
             } else {
                 setPagingEnabled(true);
diff --git a/tests/src/com/vaadin/tests/tickets/Ticket5053.java b/tests/src/com/vaadin/tests/tickets/Ticket5053.java
new file mode 100644 (file)
index 0000000..bbb9a1e
--- /dev/null
@@ -0,0 +1,35 @@
+package com.vaadin.tests.tickets;\r
+\r
+import com.vaadin.Application;\r
+import com.vaadin.ui.ComboBox;\r
+import com.vaadin.ui.Window;\r
+\r
+/**\r
+ * #5053: Last ComboBox item may not be shown if null selection enabled\r
+ */\r
+public class Ticket5053 extends Application {\r
+\r
+    @Override\r
+    public void init() {\r
+        Window main = new Window();\r
+        setMainWindow(main);\r
+\r
+        ComboBox combobox = new ComboBox("My ComboBox");\r
+\r
+        // Enable null selection\r
+        combobox.setNullSelectionAllowed(true);\r
+        // Add the item that marks 'null' value\r
+        String nullitem = "-- none --";\r
+        combobox.addItem(nullitem);\r
+        // Designate it was the 'null' value marker\r
+        combobox.setNullSelectionItemId(nullitem);\r
+\r
+        // Add some other items\r
+        for (int i = 0; i < 10; i++) {\r
+            combobox.addItem("Item " + i);\r
+        }\r
+\r
+        main.addComponent(combobox);\r
+    }\r
+\r
+}\r