]> source.dussan.org Git - vaadin-framework.git/commitdiff
extracted helper to detect previous itemId (in children list) of the actual target...
authorMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 5 Mar 2010 15:12:46 +0000 (15:12 +0000)
committerMatti Tahvonen <matti.tahvonen@itmill.com>
Fri, 5 Mar 2010 15:12:46 +0000 (15:12 +0000)
svn changeset:11671/svn branch:6.3

src/com/vaadin/ui/Tree.java
tests/src/com/vaadin/tests/dd/DDTest1.java

index d28d02216c2cfb31db131d6a876f1c992b9b406e..4c1c7136fb7b3d5269fede431d1fc798dc445354 100644 (file)
@@ -1154,6 +1154,41 @@ public class Tree extends AbstractSelect implements Container.Hierarchical,
             return getParent(itemIdOver);
         }
 
+        /**
+         * If drop is targeted into "folder node" (see {@link #getItemIdInto()}
+         * ), this method returns the item id after the drag was targeted. TODO
+         * could this be said any more difficult :-)
+         * 
+         * @return
+         */
+        public Object getItemIdAfter() {
+            Object itemIdOver = getItemIdOver();
+            Object itemIdInto2 = getItemIdInto();
+            if (itemIdOver.equals(itemIdInto2)) {
+                return null;
+            }
+            VerticalDropLocation dropLocation = getDropLocation();
+            if (VerticalDropLocation.TOP == dropLocation) {
+                // if on top of the caption area, add before
+                Collection children;
+                Object itemIdInto = getItemIdInto();
+                if (itemIdInto != null) {
+                    // seek the previous from child list
+                    children = getChildren(itemIdInto);
+                } else {
+                    children = rootItemIds();
+                }
+                Object ref = null;
+                for (Object object : children) {
+                    if (object.equals(itemIdOver)) {
+                        return ref;
+                    }
+                    ref = object;
+                }
+            }
+            return itemIdOver;
+        }
+
     }
 
     /**
index 55ef48e5e647ba6ee4b6b4e8ae6c3c019e53661e..324f770b9a378c5a14daf51eb8e116fadbefd932 100644 (file)
@@ -206,28 +206,13 @@ public class DDTest1 extends TestBase {
                     VerticalDropLocation dropLocation = details
                             .getDropLocation();
 
-                    Object itemIdAfter = itemIdOver;
-                    if (dropLocation == VerticalDropLocation.MIDDLE) {
+                    Object itemIdAfter = details.getItemIdAfter();
+
+                    if (itemIdOver.equals(itemIdInto)) { // directly on a node
                         t.setParent(itemId, itemIdOver);
                         return;
-                    } else if (VerticalDropLocation.TOP == dropLocation) {
-                        // if on top of the caption area, add before
-                        Collection children;
-                        if (itemIdInto != null) {
-                            // seek the previous from child list
-                            children = idx.getChildren(itemIdInto);
-                        } else {
-                            children = idx.rootItemIds();
-                        }
-                        Object ref = null;
-                        for (Object object : children) {
-                            if (object.equals(itemIdOver)) {
-                                itemIdAfter = ref;
-                                break;
-                            }
-                            ref = object;
-                        }
                     }
+
                     idx.setParent(itemId, itemIdInto);
 
                     if (dropLocation == null) {