PDA

View Full Version : DnD on TreePanel



chalu
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){
@Override
protected void onDragEnter(DNDEvent evt) {
super.onDragEnter(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.

A.Rothe
28 Nov 2011, 2:21 AM
http://www.sencha.com/forum/showthread.php?154421-Check-valid-targets-during-DnD

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
André

ganesh vyas
27 Jun 2014, 1:00 AM
Hi Andre,

Could you please explain, with an example, how can group be used to select valid drop tragets in tree panel. I am using GXT 3.1. How can i assign group to partiular node of a tree? There is a setGroup() method with TreeDragSource and TreeDropTarget object but that will assign same group to full tree. Any help will be truely appricated.

Thanks
Ganesh

A.Rothe
27 Jun 2014, 2:29 AM
This has nothing to do with the Groups, I guessed, that you use a base class within your Tree and you have to check its subclass instances with instanceof. So you have always nodes of the type of the baseclass, but you could check the subclass type, whether or not it is a valid target (i.e. Folder subclass is allowed, File subclass is not allowed, Folder/File are subclasses of FileSystemObject).

Best regards
Andre

ganesh vyas
2 Jul 2014, 1:48 AM
Thanks Andre, for your prompt reply. I was not able to get the target tree element to compare their objects instance. Now the problem is resolved with the following code.

Tree target = (Tree) event.getDropTarget().getWidget();
final TreeNode item = (TreeNode)target.findNode(event.getDragMoveEvent().getNativeEvent().getEventTarget(). cast());

Above lines provide the target tree node(on which currently mouse is placed).
Regards,
Ganesh