View Full Version : DnD on TreePanel

22 Nov 2011, 8:21 AM
I am trying to do DnD on a TreePanel, my intention is to inspect the object been dropped and the node on which it is about to be dropped, and then either allow or cancel the drop operation based on my choice. However I am finding it difficult to get the tree node on which the drop is about to occur, Ioverride onDragEnter() thus :

new TreePanelDropTarget(tree){
protected void onDragEnter(DNDEvent evt) {
List<BeanModel> sel = evt.getData(); // what is been dragged

// activeItem is NULL
ModelData nodeModel = activeItem.getModel();

// every node has a gender property
// so does every object been dragged here
// only allow drop if the values are same.
String nodeGrp = nodeModel.get("gender").toString();

Alternatively, is there a way to set a DnD group for a tree-node as can be done with TreePanelDropTarget. I just want to allow or reject drops on nodes if the node and the dragged model has the same value for a certain property. Thanks a bunch.

28 Nov 2011, 2:21 AM

This is a solution, how I check the valid drop zones. You can also "group" nodes if you use different instances of ModelData (like Folder extends ModelData, Leaf extends ModelData, SomethingElse extends ModelData). So it is possible to check the instance (for example you can forbid drop targets on instance SomethingElse). Another way is to prevent the selection of the nodes with a custom SelectionModel (Events.BeforeSelect). So you have only valid nodes within the selection and you have to check the target only.

Best regards