return;
}
solutionBusiness.doProblemFactChange(new ProblemFactChange() {
public void doChange(ScoreDirector scoreDirector) {
NurseRoster nurseRoster = (NurseRoster) scoreDirector.getWorkingSolution();
NurseRosterInfo nurseRosterInfo = nurseRoster.getNurseRosterInfo();
List<ShiftDate> shiftDateList = nurseRoster.getShiftDateList();
ShiftDate planningWindowStart = nurseRosterInfo.getPlanningWindowStart();
int windowStartIndex = shiftDateList.indexOf(planningWindowStart);
if (windowStartIndex < 0) {
throw new IllegalStateException("The planningWindowStart ("
+ planningWindowStart + ") must be in the shiftDateList ("
+ shiftDateList +").");
}
ShiftDate oldLastShiftDate = shiftDateList.get(shiftDateList.size() - 1);
ShiftDate newShiftDate = new ShiftDate();
newShiftDate.setId(oldLastShiftDate.getId() + 1L);
newShiftDate.setDayIndex(oldLastShiftDate.getDayIndex() + 1);
newShiftDate.setDateString(oldLastShiftDate.determineNextDateString());
newShiftDate.setDayOfWeek(oldLastShiftDate.getDayOfWeek().determineNextDayOfWeek());
List<Shift> refShiftList = planningWindowStart.getShiftList();
List<Shift> newShiftList = new ArrayList<Shift>(refShiftList.size());
newShiftDate.setShiftList(newShiftList);
nurseRoster.getShiftDateList().add(newShiftDate);
scoreDirector.afterProblemFactAdded(newShiftDate);
Shift oldLastShift = nurseRoster.getShiftList().get(nurseRoster.getShiftList().size() - 1);
long shiftId = oldLastShift.getId() + 1L;
int shiftIndex = oldLastShift.getIndex() + 1;
long shiftAssignmentId = nurseRoster.getShiftAssignmentList().get(
nurseRoster.getShiftAssignmentList().size() - 1).getId() + 1L;
for (Shift refShift : refShiftList) {
Shift newShift = new Shift();
newShift.setId(shiftId);
shiftId++;
newShift.setShiftDate(newShiftDate);
newShift.setShiftType(refShift.getShiftType());
newShift.setIndex(shiftIndex);
shiftIndex++;
newShift.setRequiredEmployeeSize(refShift.getRequiredEmployeeSize());
newShiftList.add(newShift);
nurseRoster.getShiftList().add(newShift);
scoreDirector.afterProblemFactAdded(newShift);
for (int indexInShift = 0; indexInShift < newShift.getRequiredEmployeeSize(); indexInShift++) {
ShiftAssignment newShiftAssignment = new ShiftAssignment();
newShiftAssignment.setId(shiftAssignmentId);
shiftAssignmentId++;
newShiftAssignment.setShift(newShift);
newShiftAssignment.setIndexInShift(indexInShift);
nurseRoster.getShiftAssignmentList().add(newShiftAssignment);
scoreDirector.afterEntityAdded(newShiftAssignment);
}
}
windowStartIndex++;
ShiftDate newPlanningWindowStart = shiftDateList.get(windowStartIndex);
nurseRosterInfo.setPlanningWindowStart(newPlanningWindowStart);
nurseRosterInfo.setLastShiftDate(newShiftDate);
scoreDirector.afterProblemFactChanged(nurseRosterInfo);
}
});
resetPanel(solutionBusiness.getSolution());
validate();