fireNodesInserted(this,addDescendants(children/*trees*/));
}
}
public void paste(Node parent,List children,int position,NodeModel model,int actionType){
Node p=(parent==null)?root:parent;
Project project=null;
ResourcePool resourcePool=null;
if (model.getDataFactory() instanceof Project)
project=(Project)model.getDataFactory();
else if(model.getDataFactory() instanceof ResourcePool)
resourcePool=(ResourcePool)model.getDataFactory();
int subprojectLevel=getChildrenSubprojectLevel(parent);
// ArrayList trees=new ArrayList();
// HierarchyUtils.extractParents(children,trees);
int childCount=p.getChildCount();
if (position>childCount){
NodeFactory nodeFactory=NodeFactory.getInstance();
Node node=nodeFactory.createVoidNode();
for (int i=childCount;i<position;i++){
setSubprojectLevel(node,subprojectLevel);
p.add(node);
}
}
int j=position;
for (Iterator i=/*trees*/children.iterator();i.hasNext();){
Node node=(Node)i.next();
if ((project!=null && node.getImpl() instanceof Task)||
(resourcePool!=null && node.getImpl() instanceof Resource)||
node.isVoid()){
//if (node.getImpl() instanceof Task) System.out.println("PASTE parent="+parent+":"+(parent==null?"X":parent.isInSubproject())+", node="+node+":"+node.isInSubproject());
setSubprojectLevel(node,subprojectLevel);
//if (node.getImpl() instanceof Task) System.out.println("PASTE node in sub="+node.isInSubproject());
if (position==-1) p.add(node);
else p.insert(node,j++);
}
}
Node[] descendants=addDescendants(/*trees*/children);
ArrayList<Dependency> dependencies=new ArrayList<Dependency>();
boolean doTransaction = model.getDocument() != null && descendants.length > 0;
int transactionId = 0;
if (doTransaction)
transactionId = model.getDocument().fireMultipleTransaction(0,true);
ArrayList<Node> insertedNodes=new ArrayList<Node>(descendants.length);
if (project!=null){
HashMap<Long,Resource> resourceMap=new HashMap<Long,Resource>();
for (Resource r: (Collection<Resource>)project.getResourcePool().getResourceList())
resourceMap.put(r.getUniqueId(),r);
HashMap<Long,Task> taskMap=null;
if (Environment.isKeepExternalLinks()){
taskMap=new HashMap<Long,Task>();
for (Task t: (Collection<Task>)project.getTasks()) //use model instead?
taskMap.put(t.getUniqueId(),t);
}
Project owningProject;
if (parent!=null && parent.getImpl() instanceof Task){
Task task=(Task)parent.getImpl();
if (task.isSubproject()) owningProject=((SubProj)task).getSubproject();
else owningProject=task.getOwningProject();
}else owningProject=(Project)model.getDataFactory();
for (int i=0;i<descendants.length;i++){
if (descendants[i].getImpl() instanceof Task){
Task task=(Task)descendants[i].getImpl();
Node parentSubproject=getParentSubproject((Node)descendants[i].getParent());
if (parentSubproject!=null) owningProject=((SubProj)parentSubproject.getImpl()).getSubproject();
if (!task.isExternal()) // fixes subproject bug with external links
task.setProjectId(owningProject.getUniqueId()); //useful?
owningProject.validateObject(task,model,this,null,false);
Set<Dependency> depsSet=new HashSet<Dependency>();