Results 1 to 6 of 6

Thread: Check for invalid drop using TreeDropTarget

  1. #1
    Sencha User
    Join Date
    Nov 2012
    Posts
    14
    Answers
    1
    Vote Rating
    0
      0  

    Default Check for invalid drop using TreeDropTarget

    I am using a TreeDropTarget to provide reordering capability. I do not want the dragged tree node to be dropped outside of its parent node. How can I prevent that?


    I added a DndDrpHandler to the TreeDropTarget object but I'm not exactly sure what I need to check for from the DndDropEvent. Any help would be much appreciated.

  2. #2
    Sencha User
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,737
    Answers
    109
    Vote Rating
    93
      0  

    Default

    I've deleted my reply and moved this back to Q/A - I responded and moved the wrong thread. My apoligies, and sorry for the confusion.

  3. #3
    Sencha User
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,737
    Answers
    109
    Vote Rating
    93
      0  

    Default

    Overriding showFeedback is probably your best bet. Take a look at the existing implementation of TreeDropTarget.showFeedback for how to find out what node the user is over, then call event.getStatusProxy.setStatus(boolean) to tell the user that they are or are not allowed to drop.

  4. #4
    Sencha User
    Join Date
    Nov 2012
    Posts
    14
    Answers
    1
    Vote Rating
    0
      0  

    Default

    I tried overriding the showFeedback method but it's not doing what I want it to do. I want the user to only re-order nodes within the same parent node and not be dragged into its siblings' node. I also don't want it to become a new node outside of its parent node. How would I accomplish this?

  5. #5
    Sencha User
    Join Date
    Feb 2009
    Location
    Minnesota
    Posts
    2,737
    Answers
    109
    Vote Rating
    93
      0  

    Default

    What did you try, specifically?

    What did it do that you didn't want it to do? Were you unable to _stop_ them from dropping in some areas, or were you unable to _define_ those areas (i.e. check if they may drop in the current area)?

  6. #6
    Sencha User
    Join Date
    Nov 2012
    Posts
    14
    Answers
    1
    Vote Rating
    0
      0  

    Default

    I basically check to see if the item being dragged has the same parentId as the target so the reordering takes places within the same level nodes. When I do this, the only valid drop area was the area between the parent node and the first child in the node. After the drop, the node is moved as a new node outside of the parent node. It basically becomes a sibling of the parent. Any help would be much appreciated.

    Code:
    TreeDropTarget<BaseDto> target = new TreeDropTarget<BaseDto>(tree) {        
                    @Override
                    public void showFeedback(DndDragMoveEvent event) {
                        final com.sencha.gxt.widget.core.client.tree.Tree.TreeNode item = getWidget().findNode(event.getDragMoveEvent().getNativeEvent().getEventTarget().<Element> cast());
                            if (item == null && activeItem != null) {
                              clearStyle(activeItem);
                            }
                            BaseDto dragged = (BaseDto)tree.getSelectionModel().getSelectedItem();
                            BaseDto newLocation = ((com.sencha.gxt.widget.core.client.tree.Tree.TreeNode<BaseDto>) item).getModel();
                            String newParentId = newLocation.getId();
                            String draggedParentId = ((SchoolNode)dragged).getParentID();
                            String oldParentId = ((SchoolNode)dragged).getParentID();
                            if (newParentId != oldParentId) {
                                Insert.get().hide();
                                event.getStatusProxy().setStatus(false);
                                System.out.println("Bad drop");
                                return;
                            }
                            else
                                System.out.println("Good drop");
                            
                            
                            boolean append = feedback == Feedback.APPEND || feedback == Feedback.BOTH;
                            boolean insert = feedback == Feedback.INSERT || feedback == Feedback.BOTH;
    
    
                            if (item == null) {
                              handleAppend(event, item);
                            } else if (insert) {
                              handleInsert(event, item);
                            } else if ((!getWidget().isLeaf((BaseDto) item.getModel()) || this.isAllowDropOnLeaf()) && append) {
                              handleAppend(event, item);
                            } else {
                              if (activeItem != null) {
                                clearStyle(activeItem);
                              }
                              status = -1;
                              activeItem = null;
                              appendItem = null;
    
    
                              Insert.get().hide();
                              event.getStatusProxy().setStatus(false);
                            }
                        
                    }
                };

Tags for this Thread

Posting Permissions

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