// resolve drag destination attributes
UITreeNode destNode = (dropEvent.getSource() instanceof UITreeNode) ? (UITreeNode) dropEvent.getSource() : null;
UITree destTree = destNode != null ? destNode.getUITree() : null;
TreeRowKey dropNodeKey = (dropEvent.getDropValue() instanceof TreeRowKey) ? (TreeRowKey) dropEvent.getDropValue() : null;
TreeNode droppedInNode = dropNodeKey != null ? destTree.getTreeNode(dropNodeKey) : null;
// resolve drag source attributes
UITreeNode srcNode = (dropEvent.getDraggableSource() instanceof UITreeNode) ? (UITreeNode) dropEvent.getDraggableSource() : null;
UITree srcTree = srcNode != null ? srcNode.getUITree() : null;
TreeRowKey dragNodeKey = (dropEvent.getDragValue() instanceof TreeRowKey) ? (TreeRowKey) dropEvent.getDragValue() : null;
TreeNode draggedNode = dragNodeKey != null ? srcTree.getTreeNode(dragNodeKey) : null;
if (dropEvent.getDraggableSource() instanceof UIDragSupport && srcTree == null && draggedNode == null && dropEvent.getDragValue() instanceof TreeNode) {
srcTree = destTree;
draggedNode = (TreeNode) dropEvent.getDragValue();
dragNodeKey = srcTree.getTreeNodeRowKey(draggedNode) instanceof TreeRowKey ? (TreeRowKey) srcTree.getTreeNodeRowKey(draggedNode) : null;
}
// Note: check if we dropped node on to itself or to item instead of
// folder here
if (droppedInNode != null && (droppedInNode.equals(draggedNode) || droppedInNode.getParent().getParent() != null || draggedNode.getParent().getParent() == null)) {
return;
}
FacesContext context = FacesContext.getCurrentInstance();
if (dropNodeKey != null) {
// add destination node for rerender
destTree.addRequestKey(dropNodeKey);
Object state = null;
if (dragNodeKey != null) { // Drag from this or other tree
TreeNode parentNode = draggedNode.getParent();
// 1. remove node from tree
state = srcTree.removeNode(dragNodeKey);
// 2. add parent for rerender
Object rowKey = srcTree.getTreeNodeRowKey(parentNode);
srcTree.addRequestKey(rowKey);