Search code examples
javagwtgxt

Detect drop target node in a sencha ext-gwt 3.0 tree


Context: sencha ext-gwt 3.0 (beta3). I am using dnd to let the user re-arrange a tree, one element at a time. I can easily get the dragged element but didn't find how to get the drop target. Here is my code:

final TreeDropTarget<IMyModel> target = new TreeDropTarget<IMyModel>(mytree);
target.setAllowSelfAsSource(true);
target.setAllowDropOnLeaf(true);
target.setFeedback(DND.Feedback.BOTH);
target.addDropHandler(new DndDropEvent.DndDropHandler()
{
  @Override
  public void onDrop(final DndDropEvent event)
  {
    IMyModel dragged = mytree.getSelectionModel().getSelectedItem();

    // TODO get the drop target element!
  }
});

Solution

  • This is what worked for me:

    target.addDropHandler(new DndDropHandler() {
        @Override
        public void onDrop(DndDropEvent event) {
            final TreeNode<MyModel> item = source.getWidget().findNode(event.getDragEndEvent().getNativeEvent().getEventTarget().<Element> cast());
            MyModel newParent = item.getModel();
        }
    });