View Full Version : Drag and drop cancelled event

5 Mar 2014, 4:37 AM
I use drag and drop in a tree in order to reorganize its content. I then add a drag move event which restricts the number of levels within the tree as follows:

protected final Tree<IntraMenuItemProxy, String> createTree() {
final Tree<IntraMenuItemProxy, String> tree = new Tree<IntraMenuItemProxy, String>(
this.treeStore, new IntraMenuItemValueProvider());

final TreeDragSource<IntraMenuItemProxy> dragSource = new TreeDragSource<>(tree);

final TreeDropTarget<IntraMenuItemProxy> dropTarget = new TreeDropTarget<>(tree);
dropTarget.addDragMoveHandler(new DndDragMoveHandler() {
public void onDragMove(final DndDragMoveEvent event) {

return tree;

private void onDragMove(final DndDragMoveEvent event) {
// http://www.sencha.com/forum/showthread.php?256816
final Element element = event.getDragMoveEvent().getNativeEvent().getEventTarget().cast();
final Tree.TreeNode<IntraMenuItemProxy> node = this.tree.findNode(element);
if (node != null) {
// Max two levels depth
final int depth = this.getDepth(node.getModel());
if (depth > 1) {

private int getDepth(final IntraMenuItemProxy item) {
int depth = 0;
IntraMenuItemProxy current = item;
while (current != null) {
current = current.getParent();
return depth;

I've removed a lot of code from this example, but the essence should be there.

The problem is that when I drop the node onto an element for which I've cancelled the event, the source node retains its selected style no matter which node I select. The second time I drag a node to a cancelled position, the first dragged node retains its selected style, but the second node I dragged does not.

7 Mar 2014, 3:59 PM
Could you provide a screenshot to go along with that issue?