PDA

View Full Version : Drag and drop cancelled event



stigrv
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:



@UiFactory
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.setAllowSelfAsSource(true);
dropTarget.setFeedback(Feedback.BOTH);
dropTarget.addDragMoveHandler(new DndDragMoveHandler() {
@Override
public void onDragMove(final DndDragMoveEvent event) {
MenuEditorSection.this.onDragMove(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) {
event.setCancelled(true);
event.getStatusProxy().setStatus(false);
}
}
}


private int getDepth(final IntraMenuItemProxy item) {
int depth = 0;
IntraMenuItemProxy current = item;
while (current != null) {
current = current.getParent();
depth++;
}
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.

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

Thanks,
Brandon