Results 1 to 2 of 2

Thread: Drag and drop cancelled event

  1. #1
    Ext GWT Premium Member
    Join Date
    Jun 2010
    Location
    Kyrksterra, Norway
    Posts
    71

    Default Drag and drop cancelled event

    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:

    Code:
        @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.

  2. #2
    Sencha Sr Product Manager
    Join Date
    Jan 2012
    Location
    Arlington, WA
    Posts
    1,178

    Default

    Could you provide a screenshot to go along with that issue?

    Thanks,
    Brandon

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •