1. #1
    Sencha User
    Join Date
    Sep 2011
    Location
    Leipzig, Germany
    Posts
    75
    Vote Rating
    1
    A.Rothe is on a distinguished road

      0  

    Default Check valid targets during DnD

    Check valid targets during DnD


    Hi,

    how I can check, whether or not the user moves the cursor over a valid target during DnD? I would like forbid to use some ModelData as drop zones within a TreeGrid. I have set TreeGridDropTarget.setAllowDropOnLeaf(false), but I need such a behavior also on some nodes.

    Thanks
    Andre

  2. #2
    Sencha User
    Join Date
    Sep 2011
    Location
    Leipzig, Germany
    Posts
    75
    Vote Rating
    1
    A.Rothe is on a distinguished road

      0  

    Default Check valid targets during DnD

    Check valid targets during DnD


    I have found the method DropTarget.showFeedback(DNDEvent event), which displays the feedback on a drop node. It is possible to override this method like:

    Code:
    @Override
        protected void showFeedback(DNDEvent event) {
            if (!isValidDropTarget(event)) {
                Insert.get().hide();
                event.getStatus().setStatus(false);
                return;
            }
            super.showFeedback(event);
        }
    The new method isValidDropTarget() can be implemented like:

    Code:
    @SuppressWarnings("unchecked")
        private boolean isValidDropTarget(DNDEvent event) {
            TreeGrid<ModelData> target = (TreeGrid<ModelData>) event.getDropTarget().getComponent();
            TreeGrid<ModelData>.TreeNode zone = target.findNode(event.getTarget());
            if (zone == null) {
                return true; // let it check from super-class
            }
    
            TreeGrid<ModelData> source = (TreeGrid<ModelData>) event.getDragSource().getComponent();
            List<ModelData> selection = source.getSelectionModel().getSelection();
    
            for (ModelData model : selection) {
                    // check the "model" against "zone" and return false
                    // if "zone" is not a valid drop target for "model", otherwise check the next "model"
                    // example:
                    // if (source.getTreeStore().getParent(model) == zone.getModel()) return false;
            }
    
            return true;
        }
    ~Andre

Tags for this Thread