Handling Drag and Drop Events in Gxt TreeGrids
The Ext GWT framework offers some rather sophisticated support for drag and drop in GWT applications. However dealings with drag and drop in TreeGrids can be complicated at times, since only limited documentation apart from the examples in the showcase is provided.
Here some information, how it can be controlled, where an item can be inserted in a TreeGrid.
Element | Description |
Class TreeGridDropTarget | This class can be utilized to handle drop events on a TreeGrid. It can be assigned to a TreeGrid through its constructor new TreeGridDropTarget(treeGrid). |
Method showFeedback(...) | This method can be overridden in TreeGridDropTarget to achieve custom rules for where a 'drop' is allowed. |
DNDEvent event | This is the parameter of the showFeedback method. Its attributes can be used to determine an appropriate feedback. |
event.getDragSource() | Can be cast to TreeGridDragSource. Points to the source tree grid for the drop. |
event.getDropTarget() | Can be cast to TreeGridDropTarget. This should point to the drop target triggering the method. |
source.getData() | Can be cast to List<?>. Points to the items, which are to be dropped. |
((List<?>) source.getData()).get(..) | Can be cast to TreeStoreModel. Points to a specific item, which is to be dropped. Through the method getModel(..) of the TreeStoreModel the actual item in the drag source can be accessed (As a BaseTreeModel). |
event.getTarget() | Points to a dom element where the drag is to take place. If it's currently over a TreeNode, it can be found through: TreeNode n = this.getTreeGrid().findNode(event.getTarget()); |
Finally, if the user feedback should be delivered, that it is illegal to drop the node at the current location, the following commands can be added to the overridden showFeedback(..) method:
Insert.get().hide();
event.getStatus().setStatus(false);
return;
If the default feedback shall be delivered, the overridden method should be called through calling super.showFeedback(event);.
Resources
Source Code of Source of TreeGridDropTarget
Sibling Reordering DND Tree (Sencha Forum) Check here for methods to override for TreeGridDropTarget