for (int i = 0; i < visibleTasks.size(); i++) {
Task task = (Task) visibleTasks.get(i);
int index = getPreviousStateTaskIndex(task);
GPCalendar calendar = myModel.getTaskManager().getCalendar();
if (index != -1) {
GanttPreviousStateTask previousStateTask = (GanttPreviousStateTask) myPreviousStateTasks
.get(index);
previousStateTask.setState(task, calendar);
if (previousStateTask.getStart().after(unitFinish)) {
myPreviousStateCurrentlyProcessed.add(null);
} else if (previousStateTask.getStart().getTime()
.compareTo(unitStart) >= 0
&& previousStateTask.getStart().getTime()
.compareTo(unitFinish) < 0)
// )|| previousStateTask.getEnd(
// calendar)
// .getTime().compareTo(unitStart) > 0
// && previousStateTask.getEnd(
// calendar)
// .getTime().compareTo(unitFinish) < 0)
{
myPreviousStateCurrentlyProcessed
.add(previousStateTask);
myPreviousStateTasks.remove(index);
}
// if just a part of the previous task is visible
else if (previousStateTask.getStart().getTime().compareTo(
unitStart) < 0
&& (previousStateTask.getEnd(calendar).getTime()
.compareTo(unitStart) > 0)) {
GanttCalendar newStart = new GanttCalendar(unitStart);
int id = previousStateTask.getId();
int duration = previousStateTask.getDuration()
- newStart.diff(previousStateTask.getStart());
int diff = newStart.diff(previousStateTask.getStart());
for (int j = 0; j < diff; j++) {
if (calendar.isNonWorkingDay(previousStateTask
.getStart().newAdd(j).getTime())) {
duration++;
}
}
boolean isMilestone = previousStateTask.isMilestone();
boolean hasNested = previousStateTask.hasNested();
GanttPreviousStateTask partOfPreviousTask = new GanttPreviousStateTask(
id, newStart, duration, isMilestone, hasNested);
partOfPreviousTask.setState(task, calendar);
partOfPreviousTask.setIsAPart(true);
myPreviousStateCurrentlyProcessed
.add(partOfPreviousTask);
myPreviousStateTasks.remove(index);
} else
myPreviousStateCurrentlyProcessed.add(null);