TreePath path = getPathForLocation (dropPoint.x, dropPoint.y);
Object targetNode = path.getLastPathComponent();
if (targetNode instanceof TCTreeNode) {
// rename the dragged dir into the new target one
TCTreeNode tcTargetNode = (TCTreeNode)targetNode;
FileNode fn = (FileNode)tcTargetNode.getUserObject();
if (fn.isTestcaseDir())
{
dtde.rejectDrop();
return;
}
FileNode draggedFileNode = (FileNode)tcTreeNode.getUserObject();
draggedFileNode.getFile().renameTo(new File(fn.getFile() + "/" + draggedFileNode.getFile().getName()));
// update target tree
testCasePane.parent.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
TCTreeNode parentTreeNode = (TCTreeNode)tcTargetNode.getParent();
if (parentTreeNode!=null) {
parentTreeNode.removeAllChildren();
FileNode parentFileNode = (FileNode)parentTreeNode.getUserObject();
addTreeToDir(parentFileNode.getFile(), parentTreeNode);
((DefaultTreeModel) getModel()).reload(parentTreeNode);
}
else
{
tcTargetNode.removeAllChildren();
FileNode targetFileNode = (FileNode)tcTargetNode.getUserObject();
addTreeToDir(targetFileNode.getFile(), tcTargetNode);
((DefaultTreeModel) getModel()).reload(tcTargetNode);
}
// update source tree
parentTreeNode = (TCTreeNode)tcTreeNode.getParent();
if (parentTreeNode!=null) {
parentTreeNode.removeAllChildren();
FileNode parentFileNode = (FileNode)parentTreeNode.getUserObject();
addTreeToDir(parentFileNode.getFile(), parentTreeNode);
((DefaultTreeModel) getModel()).reload(parentTreeNode);
}
else
{
tcTreeNode.removeAllChildren();
FileNode targetFileNode = (FileNode)tcTreeNode.getUserObject();
addTreeToDir(targetFileNode.getFile(), tcTreeNode);
((DefaultTreeModel) getModel()).reload(tcTreeNode);
}
testCasePane.parent.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
dtde.getDropTargetContext().dropComplete(true);
}