View Full Version : How to find the target node after a drop in a treepanel

10 Dec 2009, 7:54 AM
I have been reading the doc and searching through the forum but haven't find a way to retrieve the target node after a drag and drop occurred.
I thought the following snippet would gave me what I wanted but it displays the result only if I drag the selected file(s) directly on top of an existing node.
If the node is expanded, I get the target name of the file (leaf?) inside this node.
If I try to display the parent node for the leaf, I get the source node instead of the target node.

What is the correct way to find the target node?

Thanks a lot.

public void dragDrop(DNDEvent e) {
for (final Object c : (List<?>) e.getData()) {
if (c instanceof TreeStoreModel) {
Folder folder = (Folder) ((TreeStoreModel) c).getModel();
System.out.println("Dragged report: " + folder.getName());

//Find node ID
TreeNode treenode = tree.findNode(e.getTarget());
if (treenode!=null) {
System.out.println("Target: " + ((Folder)treenode.getModel()).getName());
Folder targetFolder = (Folder)treenode.getModel();
if (targetFolder.isLeaf()) {
System.out.println("TargetParent: " + targetFolder.getParent().get("name"));
}else {
System.out.println("Target: " + targetFolder.get("name"));

10 Dec 2009, 8:47 AM
i dont know an answer, but i missing in your code a prepareDropData like in the super.dragDrop
List<ModelData> models = prepareDropData(data, true);

10 Dec 2009, 11:54 AM
Thanks for your answer, but could you be more explicit?

Could anybody please post a snippet explaining how to get the drop target node info in a treePanel?

Thx in advance.