willAcceptDrop event handler

For my TreeGrid I need to define custom behavior of drag&drop functionality. Node depending on its type can be dropped to specific list of locations but not others).
This custom logic I decided to put into willAcceptDrop() handler since it allows user to see if node can be dropped on chosen location before he actually drops it.

Indeed I am not able to find in documentation the list of arguments to this method: TreeGrid.willAcceptDrop().

Could you please let me know where should I take from such information as:

  1. nodes that are dragged by user
  2. folder to which user intends to drop nodes
  3. index
  4. sourceWidget

Thank you,
Volodymyr

P.S. I am using SmartClient Version: 6.0 (built 2007-11-07).

Hi Volodymyr,

There are no arguments to willAcceptDrop(). It’s a method on Canvas and hence there aren’t really any appropriate arguments.

The sourceWidget is available at any time via EventHandler.getDragTarget(), and you can use getEventRow() to figure out the folder and index, and getDragData allows you to see the data being dragged.

Greetings, thank you for reply.

As you probably noticed all four parameters listed above are same as in folderDrop function.
Here are functions I have added to my TreeGrid component:

willAcceptDrop: function() {
    if (!this.Super("willAcceptDrop", arguments)) {
        return false;
    }
							
    if (this.willAcceptFolderDrop) {
        var sourceWidget = isc.EventHandler.getDragTarget();
        var nodes = sourceWidget.getDragData();
        var eventRow = this.getEventRow();
        var folder = this.getRecord(eventRow);
        var index = this.getRecordIndex(folder);
        return this.willAcceptFolderDrop(nodes, folder, index, sourceWidget);
    } else {
        return true;
    }
},
						

willAcceptFolderDrop: function(nodes, folder, index, sourceWidget) {
    var _0 = nodes.get(0).id + "[" + nodes.get(0).displayName + "]";
    var _1 = folder.id + "[" + folder.displayName + "]";
    var _3 = (this == sourceWidget ? "this" : "outside");
    myLabel.setContents("_0:" + _0 + "; _1:" + _1 + "; _2:" + index + "; _3:" + _3);
    return true;//custom validation goes here
},

folderDrop: function(nodes, folder, index, sourceWidget) {
    var _0 = nodes.get(0).id + "[" + nodes.get(0).displayName + "]";
    var _1 = folder.id + "[" + folder.displayName + "]";
    var _3 = (this == sourceWidget ? "this" : "outside");
    myLabel2.setContents("_0:" + _0 + "; _1:" + _1 + "; _2:" + index + "; _3:" + _3);
    /// Drop code goes here
},

I expect that function willAcceptFolderDrop receives the same parameters as the folderDrop function. However I came across that:

  • index is not correct (I believe that there is some other function to get index, hovewer I can’t find it)
  • folder at corner cases is not the same (try to drop in between two nodes)

Hi Volodymyr,

The eventRow is just the row the mouse is over - you need to use treeGrid.data, which is an instance of the Tree data modal, to find it’s parent folder, via getParent. Once you have the parent, you find the index within that parent by locating the eventRow within the parent’s children.

Make sense?

Hi again!

I was able to retireve index of the row:

var index = this.data.getChildren(this.data.getParent(folder)).indexOf(folder);

However as I mentioned before in many cases folder and index parameters are not the same as they will be after user releases mouse button.

As I understand the problem here is that folder retrieved by this code:

var folder = this.getRecord(eventRow);

is actually the node mouse is over at current time. Hovewer Drop functionality of TreeGrid is much more complicated.
For example we have tree like this:

<root>
   |
   +-- Node1
   |
   +-- Node2
            |
            +--- Node2.1
            |
            +--- Node2.2
  1. When you drag Node1 and drop in between Node2.1 and Node2.2 you will actually attach Node1 to the Node2.
  2. However you may want to attach Node1 to Node2.1, so you will drag a little bit higher as in first case and it will be attached to Node2.1.

In those two cases in willAcceptFolderDrop(…) we will have:
folder: Node2.1
index: 0

However this is not true!

With Best Regards,
Volodymyr

Hi Volodymyr,
There is a TreeGrid method ‘getDropFolder()’ which, if called while the user is dragging data into a TreeGrid, will return a pointer to the folder in which the data will be dropped
This is not exposed in the 6.0 release but has been documented for SmartClient 6.1

Let us know if you can’t get it working

Thanks
Isomorphic Software