]> source.dussan.org Git - vaadin-framework.git/commitdiff
#7129 Properly clean up "filteredParent" when removing an item from a filtered container
authorArtur Signell <artur.signell@itmill.com>
Mon, 6 Jun 2011 15:13:14 +0000 (15:13 +0000)
committerArtur Signell <artur.signell@itmill.com>
Mon, 6 Jun 2011 15:13:14 +0000 (15:13 +0000)
svn changeset:19245/svn branch:6.6

src/com/vaadin/data/util/HierarchicalContainer.java
tests/src/com/vaadin/tests/server/container/TestHierarchicalContainer.java

index d671dbc833d63c26579adf9c012b00160184b960..e208d07dc68cdd06a32a0b0e46c8fe7817e17ae5 100644 (file)
@@ -471,6 +471,9 @@ public class HierarchicalContainer extends IndexedContainer implements
             if (filteredChildren != null) {
                 filteredChildren = null;
             }
+            if (filteredParent != null) {
+                filteredParent = null;
+            }
         }
         enableAndFireContentsChangeEvents();
         return success;
@@ -528,6 +531,11 @@ public class HierarchicalContainer extends IndexedContainer implements
                 }
             }
             parent.remove(itemId);
+            if (filteredParent != null) {
+                // Item id no longer has a parent as the item id is not in the
+                // container.
+                filteredParent.remove(itemId);
+            }
             noChildrenAllowed.remove(itemId);
         }
 
index 67ad4fe45f6e85caec04fa95ecd76e2945696ca4..12255ad83547548e05f9855ea7764e47453aaf99 100644 (file)
@@ -29,6 +29,26 @@ public class TestHierarchicalContainer extends
         testContainerSortingAndFiltering(new HierarchicalContainer());\r
     }\r
 \r
+    public void testRemovingItemsFromFilteredContainer() {\r
+        HierarchicalContainer container = new HierarchicalContainer();\r
+        initializeContainer(container);\r
+        container.setIncludeParentsWhenFiltering(true);\r
+        container.addContainerFilter(FULLY_QUALIFIED_NAME, "ab", false, false);\r
+        Object p1 = container.getParent("com.vaadin.ui.TabSheet");\r
+        assertEquals("com.vaadin.ui", p1);\r
+\r
+        container.removeItem("com.vaadin.ui.TabSheet");\r
+        // Parent for the removed item must be null because the item is no\r
+        // longer in the container\r
+        p1 = container.getParent("com.vaadin.ui.TabSheet");\r
+        assertNull("Parent should be null, is " + p1, p1);\r
+\r
+        container.removeAllItems();\r
+        p1 = container.getParent("com.vaadin.terminal.gwt.client.Focusable");\r
+        assertNull("Parent should be null, is " + p1, p1);\r
+\r
+    }\r
+\r
     public void testHierarchicalFilteringWithParents() {\r
         HierarchicalContainer container = new HierarchicalContainer();\r
         initializeContainer(container);\r