public void doAction(ActionEvent e) {
String action = e.getActionCommand();
ReportGuiPackage guiPackage = ReportGuiPackage.getInstance();
ReportTreeNode[] draggedNodes = guiPackage.getTreeListener().getDraggedNodes();
ReportTreeListener treeListener = guiPackage.getTreeListener();
ReportTreeNode currentNode = treeListener.getCurrentNode();
ReportTreeNode parentNode = (ReportTreeNode) currentNode.getParent();
TestElement te = currentNode.getTestElement();
if (te instanceof TestPlan || te instanceof WorkBench) {
parentNode = null; // So elements can only be added as children
}
// System.out.println(action+" "+te.getClass().getName());
if (ADD.equals(action) && canAddTo(currentNode)) {
removeNodesFromParents(draggedNodes);
for (int i = 0; i < draggedNodes.length; i++) {
ReportGuiPackage.getInstance().getTreeModel().insertNodeInto(draggedNodes[i], currentNode,
currentNode.getChildCount());
}
} else if (INSERT_BEFORE.equals(action) && canAddTo(parentNode)) {
removeNodesFromParents(draggedNodes);
for (int i = 0; i < draggedNodes.length; i++) {
int index = parentNode.getIndex(currentNode);
ReportGuiPackage.getInstance().getTreeModel().insertNodeInto(draggedNodes[i], parentNode, index);
}
} else if (INSERT_AFTER.equals(action) && canAddTo(parentNode)) {
removeNodesFromParents(draggedNodes);
for (int i = 0; i < draggedNodes.length; i++) {
int index = parentNode.getIndex(currentNode) + 1;
ReportGuiPackage.getInstance().getTreeModel().insertNodeInto(draggedNodes[i], parentNode, index);
}
}
ReportGuiPackage.getInstance().getMainFrame().repaint();
}