public void pasteNode() {
if (cpNodesArrayList != null) {
final GanttTree2 gt2 = this;
getUndoManager().undoableEdit("Paste", new Runnable() {
public void run() {
TaskNode current = (TaskNode) treetable.getTree()
.getLastSelectedPathComponent();
List tasksList = new ArrayList();
if (current == null) {
current = rootNode;
}
boolean isAProjectTaskChild = false;
DefaultMutableTreeNode father = (DefaultMutableTreeNode) current
.getParent();
// if the task as a projectTask parent
while (father != null) {
if (((Task) father.getUserObject()).isProjectTask()) {
isAProjectTaskChild = true;
}
father = (DefaultMutableTreeNode) father.getParent();
}
mapOriginalIDCopyID = new HashMap();
// copyID = new ArrayList ();
// pasteID = new ArrayList ();
TaskManagerImpl tmi = (TaskManagerImpl) getTaskManager();
int MaxID = tmi.getMaxID();
// for(int i=0; i < cpNodesArrayList.size(); i++) {
for (int i = cpNodesArrayList.size() - 1; i >= 0; i--) {
if (isAProjectTaskChild)
((Task) ((TaskNode) cpNodesArrayList.get(i))
.getUserObject()).setProjectTask(false);
/*
* this will add new custom columns to the newly
* created task.
*/
TreeNode sel = getSelectedTaskNode();
TreeNode parent = null;
if (sel != null) {
parent = sel.getParent();
if (parent != null)
where = parent.getIndex(sel);
}
tasksList.add((Task) insertClonedNode(
current == rootNode ? current
: (DefaultMutableTreeNode) current
.getParent(),
(DefaultMutableTreeNode) cpNodesArrayList
.get(i), where + 1, true)
.getUserObject());
nbTasks++;