]> source.dussan.org Git - vaadin-framework.git/commitdiff
fixes #3949
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 9 Mar 2010 10:20:01 +0000 (10:20 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Tue, 9 Mar 2010 10:20:01 +0000 (10:20 +0000)
svn changeset:11705/svn branch:6.3

src/com/vaadin/data/util/ContainerHierarchicalWrapper.java
src/com/vaadin/data/util/HierarchicalContainer.java
tests/src/com/vaadin/tests/dd/DDTest6.java

index 8b6fedb8e4b536e547736bf4a3b3c89868506e9d..e692f11498b9f2fefa6d236271c0a26810c311b9 100644 (file)
@@ -518,7 +518,7 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical,
 
     /**
      * Removes an Item specified by the itemId from the underlying container and
-     * from the hierarcy.
+     * from the hierarchy.
      * 
      * @param itemId
      *            the ID of the Item to be removed.
@@ -539,6 +539,18 @@ public class ContainerHierarchicalWrapper implements Container.Hierarchical,
         return success;
     }
 
+    /**
+     * Removes the Item identified by given itemId and all its children.
+     * 
+     * @see #removeItem(Object)
+     * @param itemId
+     *            the identifier of the Item to be removed
+     * @return true if the operation succeeded
+     */
+    public boolean removeItemRecursively(Object itemId) {
+        return HierarchicalContainer.removeItemRecursively(this, itemId);
+    }
+
     /**
      * Adds a new Property to all Items in the Container.
      * 
index a404d83eb1ae48d00cc0cf60f7ee4c280440191a..5d29283bcb2120cf881b274057b9ef736732b11f 100644 (file)
@@ -492,29 +492,44 @@ public class HierarchicalContainer extends IndexedContainer implements
     }
 
     /**
-     * Removes the Item identified by ItemId from the Container and all its
-     * children.
+     * Removes the Item identified by given itemId and all its children.
      * 
      * @see #removeItem(Object)
      * @param itemId
-     *            the identifier of the Item to remove
+     *            the identifier of the Item to be removed
      * @return true if the operation succeeded
      */
     public boolean removeItemRecursively(Object itemId) {
+        return removeItemRecursively(this, itemId);
+    }
+
+    /**
+     * Removes the Item identified by given itemId and all its children from the
+     * given Container.
+     * 
+     * @param container
+     *            the container where the item is to be removed
+     * @param itemId
+     *            the identifier of the Item to be removed
+     * @return true if the operation succeeded
+     */
+    public static boolean removeItemRecursively(
+            Container.Hierarchical container, Object itemId) {
         boolean success = true;
-        Collection<Object> children2 = getChildren(itemId);
+        Collection<?> children2 = container.getChildren(itemId);
         if (children2 != null) {
             Object[] array = children2.toArray();
             for (int i = 0; i < array.length; i++) {
-                boolean removeItemRecursively = removeItemRecursively(array[i]);
+                boolean removeItemRecursively = removeItemRecursively(
+                        container, array[i]);
                 if (!removeItemRecursively) {
                     success = false;
                 }
             }
         }
-        boolean removeItem = removeItem(itemId);
-        if (!removeItem) {
-            success = false;
+        // remove the root of subtree if children where succesfully removed
+        if (success) {
+            success = container.removeItem(itemId);
         }
         return success;
 
index 599fa113ffd5f15fb28d2cba4fb5282350b8671e..a00f4113345c1c60ac24dfcce987b6c3bc7015b9 100644 (file)
@@ -1,7 +1,10 @@
 package com.vaadin.tests.dd;
 
 import com.vaadin.data.util.BeanItemContainer;
+import com.vaadin.data.util.ContainerHierarchicalWrapper;
+import com.vaadin.event.Action;
 import com.vaadin.event.DataBoundTransferable;
+import com.vaadin.event.Action.Handler;
 import com.vaadin.event.dd.DragAndDropEvent;
 import com.vaadin.event.dd.DropHandler;
 import com.vaadin.event.dd.acceptCriteria.AcceptAll;
@@ -76,6 +79,22 @@ public class DDTest6 extends TestBase {
 
         tree1.setDropHandler(dropHandler);
 
+        Handler actionHandler = new Handler() {
+
+            private Action[] actions = new Action[] { new Action("Remove") };
+
+            public void handleAction(Action action, Object sender, Object target) {
+                ContainerHierarchicalWrapper containerDataSource = (ContainerHierarchicalWrapper) tree1
+                        .getContainerDataSource();
+                containerDataSource.removeItemRecursively(target);
+            }
+
+            public Action[] getActions(Object target, Object sender) {
+                return actions;
+            }
+        };
+        tree1.addActionHandler(actionHandler);
+
         l.addComponent(tree1);
 
         getLayout().setSizeFull();