]> source.dussan.org Git - vaadin-framework.git/commitdiff
Test case and fix for #3987 - DefaultItemSorter fails for a filtered container
authorArtur Signell <artur.signell@itmill.com>
Thu, 14 Jan 2010 11:31:20 +0000 (11:31 +0000)
committerArtur Signell <artur.signell@itmill.com>
Thu, 14 Jan 2010 11:31:20 +0000 (11:31 +0000)
svn changeset:10712/svn branch:6.2

src/com/vaadin/data/util/DefaultItemSorter.java
tests/src/com/vaadin/tests/server/container/TestContainerSorting.java

index 5cec2dc461971876d62f2efa083eef346834a864..aefdbf1cc91dd9fd65db1a40f3e056a705d7aea7 100644 (file)
@@ -62,6 +62,20 @@ public class DefaultItemSorter implements ItemSorter {
         Item item1 = container.getItem(o1);
         Item item2 = container.getItem(o2);
 
+        /*
+         * Items can be null if the container is filtered. Null is considered
+         * "less" than not-null.
+         */
+        if (item1 == null) {
+            if (item2 == null) {
+                return 0;
+            } else {
+                return 1;
+            }
+        } else if (item2 == null) {
+            return -1;
+        }
+
         for (int i = 0; i < sortPropertyIds.length; i++) {
 
             int result = compareProperty(sortPropertyIds[i], sortDirections[i],
index e51bb25072b434e179fd17a1335d6cf1111faea2..1c05b5068e01713f84883e31c32d2f1b49d2dba7 100644 (file)
@@ -32,6 +32,20 @@ public class TestContainerSorting extends TestCase {
         super.setUp();\r
     }\r
 \r
+    public void testFilteredIndexedContainer() {\r
+        IndexedContainer ic = new IndexedContainer();\r
+\r
+        addProperties(ic);\r
+        populate(ic);\r
+\r
+        ic.addContainerFilter(PROPERTY_STRING_ID, "a", true, false);\r
+        ic.sort(new Object[] { PROPERTY_STRING_ID }, new boolean[] { true });\r
+        verifyOrder(ic,\r
+                new String[] { ITEM_ANOTHER_NULL, ITEM_DATA_MINUS1,\r
+                        ITEM_DATA_MINUS1_NULL, ITEM_DATA_MINUS2,\r
+                        ITEM_DATA_MINUS2_NULL, });\r
+    }\r
+\r
     public void testIndexedContainer() {\r
         IndexedContainer ic = new IndexedContainer();\r
 \r