From: Matti Tahvonen Date: Fri, 5 Mar 2010 15:12:46 +0000 (+0000) Subject: extracted helper to detect previous itemId (in children list) of the actual target... X-Git-Tag: 6.7.0.beta1~1987 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bc2514699433c8166053ee635e999dd8506b13cf;p=vaadin-framework.git extracted helper to detect previous itemId (in children list) of the actual target to Tree svn changeset:11671/svn branch:6.3 --- diff --git a/src/com/vaadin/ui/Tree.java b/src/com/vaadin/ui/Tree.java index d28d02216c..4c1c7136fb 100644 --- a/src/com/vaadin/ui/Tree.java +++ b/src/com/vaadin/ui/Tree.java @@ -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; + } + } /** diff --git a/tests/src/com/vaadin/tests/dd/DDTest1.java b/tests/src/com/vaadin/tests/dd/DDTest1.java index 55ef48e5e6..324f770b9a 100644 --- a/tests/src/com/vaadin/tests/dd/DDTest1.java +++ b/tests/src/com/vaadin/tests/dd/DDTest1.java @@ -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) {