PDA

View Full Version : Find TreeNode that is dropped on



AndreKR
7 May 2010, 6:11 PM
Hi,

I am trying to create a tree with only leaf nodes that can be dropped on. Because TreeDropZone seems to only support dropping on folders and besides leaf node (I found something about allowDropOnLeaf but that's related to ExtGWT), my approach is to create my own DropZone by new Ext.dd.DropZone(my_treepanel.getTreeEl(),overridden_methods);

I have to override the DropZone::getElementFromEvent method to find out which TreeNode is targeted by the mouse event. But how can I find the appropriate TreeNode?

Apparently the TreeDropZone's solution to this is to give the DOM nodes ids like "extdd-n" and registering them with Ext.dd.Registry. Unfortunately I don't know where this is done and whether that would be the best way in my case.

Regards,
André

eugs51
9 May 2010, 8:31 PM
I am not familiar with the dropzone, but I hope I can help. There are events in your TreePanel that you can use to cancel dragging depending on your requirements namely beforenodedrop and nodedragover,


var tree = new Ext.tree.TreePanel({
...
listeners:{
beforenodedrop:function(dropEvent){
if(!dropEvent.dropNode.isLeaf()){
dropEvent.cancel = true;
}
},
nodedragover:function(dragOverEvent){
if(!dragOverEvent.dropNode.isLeaf()){
dragOverEvent.cancel= true;
}
}
},
...
});

AndreKR
10 May 2010, 5:13 AM
That doesn't work at all:
http://kundenweb.creations.de/usenet/ext_layout/ext_sandbox2.htm

Error: dragOverEvent.dropNode is undefined

According to the docs it should be ok: dropNode - Drop node(s) provided by the source. (However I don't understand what "provided by the source" is supposed to mean.)

AndreKR
11 May 2010, 3:28 PM
I found a solution:



region: 'west',
xtype: 'treepanel',
ddGroup: 'GridDD', // not yet sure if necessary
listeners: {
render: function(tp) {
tp.dropZone = new Ext.dd.DropZone(tp.getTreeEl(),{
ddGroup: 'GridDD', // not yet sure if necessary
getTargetFromEvent: function(e) {
t = e.getTarget('li.x-tree-node');
i = 0;
c = tp.getRootNode().childNodes;
while (n = c[i++])
if (n.getUI().getEl() == t)
return n;

return null;
}