I found this code
/*
* Creates a new iteration with the given name, id, parent, and development
* line. If the given parent is not null
, it must be a working copy
* because the newly created iteration will be added to it as a child.
* Otherwise, the given development line must be a working copy because the
* iteration will be added to it instead. The returned iteration is a working
* copy which has not yet been saved.
/
protected IIteration createIteration(String name, String id, IIteration parent, IDevelopmentLine line)
throws TeamRepositoryException {
IProcessItemService processService = (IProcessItemService) ((ITeamRepository) line.getOrigin())
.getClientLibrary(IProcessItemService.class);
IIteration iteration = processService.createIteration();
iteration.setName(name);
iteration.setId(id);
iteration.setDevelopmentLine(line);
if (parent != null) {
iteration.setParent(parent);
List children = new ArrayList();
IIterationHandle[] currents = parent.getChildren();
for (int i = 0; i < currents.length; i++) {
children.add(currents[i]);
}
children.add(iteration);
parent.setChildren((IIterationHandle[]) children.toArray(new IIterationHandle[children.size()]));
} else {
List iterations = new ArrayList();
IIterationHandle[] currents = line.getIterations();
for (int i = 0; i < currents.length; i++) {
iterations.add(currents[i]);
}
iterations.add(iteration);
line.setIterations((IIterationHandle[]) iterations.toArray(new IIterationHandle[iterations.size()]));
}
return iteration;
}
</pre>
You have to make sure to have a workingcopy of the development line. You have to add all the process items that are changed to an array and finally save the items in that list. The order of items matter.
<pre>
private void createDevelopmentLines(IProjectArea projectArea, IProgressMonitor monitor) throws TeamRepositoryException {
projectArea = (IProjectArea) projectArea.getWorkingCopy();
ArrayList<iitem> modified = new ArrayList<iitem>();
for (int i = 0; i < 2050; i++) {
String nameID = NAME_PREFIX + NAMEANDID + i;
IDevelopmentLine devLine = createDevelopmentLine(nameID, nameID, projectArea);
modified.add(devLine);
if(i==0) { // add the project area the first time
modified.add(projectArea);
}
}
IProcessItemService processService = (IProcessItemService) ((ITeamRepository) projectArea.getOrigin())
.getClientLibrary(IProcessItemService.class);
processService.save(modified.toArray(new IProcessItem[0]), monitor);
System.out.println("Saved items (" + modified.size() + ")...");
}
</iitem></iitem>