Notify end dates events instead of length

FEA: ItEr61S08TimeUnitConfigurablePlanning
This commit is contained in:
Óscar González Fernández 2010-09-28 18:16:52 +02:00
parent 749bf03981
commit 88ee2d8231
8 changed files with 103 additions and 117 deletions

View file

@ -61,12 +61,11 @@ public class GanttDiagramGraph<V, D> {
return new IDependenciesEnforcerHook() {
@Override
public void setLengthMilliseconds(long previousLengthMilliseconds,
long lengthMilliseconds) {
public void setNewEnd(Date previousEnd, Date newEnd) {
}
@Override
public void setStartDate(Date previousStart, long previousLength,
public void setStartDate(Date previousStart, Date previousEnd,
Date newStart) {
}
};
@ -408,11 +407,10 @@ public class GanttDiagramGraph<V, D> {
}
public interface IDependenciesEnforcerHook {
public void setStartDate(Date previousStart, long previousLength,
public void setStartDate(Date previousStart, Date previousEnd,
Date newStart);
public void setLengthMilliseconds(long previousLengthMilliseconds,
long newLengthMilliseconds);
public void setNewEnd(Date previousEnd, Date newEnd);
}
public interface IDependenciesEnforcerHookFactory<T> {
@ -423,21 +421,21 @@ public class GanttDiagramGraph<V, D> {
}
public interface INotificationAfterDependenciesEnforcement {
public void onStartDateChange(Date previousStart, long previousLength,
public void onStartDateChange(Date previousStart, Date previousEnd,
Date newStart);
public void onLengthChange(long previousLength, long newLength);
public void onEndDateChange(Date previousEnd, Date newEnd);
}
private static final INotificationAfterDependenciesEnforcement EMPTY_NOTIFICATOR = new INotificationAfterDependenciesEnforcement() {
@Override
public void onStartDateChange(Date previousStart, long previousLength,
public void onStartDateChange(Date previousStart, Date previousEnd,
Date newStart) {
}
@Override
public void onLengthChange(long previousLength, long newLength) {
public void onEndDateChange(Date previousEnd, Date newEnd) {
}
};
@ -503,54 +501,52 @@ public class GanttDiagramGraph<V, D> {
private final INotificationAfterDependenciesEnforcement notification;
private final Date previousStart;
private final long previousLength;
private final Date previousEnd;
private final Date newStart;
public StartDateNofitication(
INotificationAfterDependenciesEnforcement notification,
Date previousStart, long previousLength, Date newStart) {
Date previousStart, Date previousEnd, Date newStart) {
this.notification = notification;
this.previousStart = previousStart;
this.previousLength = previousLength;
this.previousEnd = previousEnd;
this.newStart = newStart;
}
public StartDateNofitication coalesce(
StartDateNofitication startDateNofitication) {
return new StartDateNofitication(notification, previousStart,
previousLength, startDateNofitication.newStart);
previousEnd, startDateNofitication.newStart);
}
void doNotification() {
notification.onStartDateChange(previousStart, previousLength,
newStart);
notification
.onStartDateChange(previousStart, previousEnd, newStart);
}
}
private class LengthNotification {
private final INotificationAfterDependenciesEnforcement notification;
private final long previousLengthMilliseconds;
private final long newLengthMilliseconds;
private final Date previousEnd;
private final Date newEnd;
public LengthNotification(
INotificationAfterDependenciesEnforcement notification,
long previousLengthMilliseconds, long lengthMilliseconds) {
Date previousEnd, Date newEnd) {
this.notification = notification;
this.previousLengthMilliseconds = previousLengthMilliseconds;
this.newLengthMilliseconds = lengthMilliseconds;
this.previousEnd = previousEnd;
this.newEnd = newEnd;
}
public LengthNotification coalesce(LengthNotification lengthNofitication) {
return new LengthNotification(notification,
previousLengthMilliseconds,
lengthNofitication.newLengthMilliseconds);
return new LengthNotification(notification, previousEnd,
lengthNofitication.newEnd);
}
void doNotification() {
notification.onLengthChange(previousLengthMilliseconds,
newLengthMilliseconds);
notification.onEndDateChange(previousEnd, newEnd);
}
}
@ -574,17 +570,16 @@ public class GanttDiagramGraph<V, D> {
private IDependenciesEnforcerHook onEntrance(final V task) {
return new IDependenciesEnforcerHook() {
@Override
public void setStartDate(Date previousStart,
long previousLength, Date newStart) {
public void setStartDate(Date previousStart, Date previousEnd,
Date newStart) {
taskPositionModified(task);
}
@Override
public void setLengthMilliseconds(
long previousLengthMilliseconds, long lengthMilliseconds) {
public void setNewEnd(Date previousEnd, Date newEnd) {
taskPositionModified(task);
}
};
}
@ -593,22 +588,19 @@ public class GanttDiagramGraph<V, D> {
return new IDependenciesEnforcerHook() {
@Override
public void setStartDate(Date previousStart,
long previousLength, Date newStart) {
public void setStartDate(Date previousStart, Date previousEnd,
Date newStart) {
StartDateNofitication startDateNotification = new StartDateNofitication(
notification,
previousStart, previousLength, newStart);
notification, previousStart, previousEnd,
newStart);
deferedNotifier.get().add(task, startDateNotification);
}
@Override
public void setLengthMilliseconds(
long previousLengthMilliseconds,
long newLengthMilliseconds) {
public void setNewEnd(Date previousEnd, Date newEnd) {
LengthNotification lengthNotification = new LengthNotification(
notification, previousLengthMilliseconds,
newLengthMilliseconds);
notification, previousEnd, newEnd);
deferedNotifier.get().add(task, lengthNotification);
}
};
@ -622,7 +614,7 @@ public class GanttDiagramGraph<V, D> {
@Override
public void setStartDate(final Date previousStart,
final long previousLength, final Date newStart) {
final Date previousEnd, final Date newStart) {
positionsUpdatingGuard
.entranceRequested(new IReentranceCases() {
@ -634,10 +626,10 @@ public class GanttDiagramGraph<V, D> {
public void doAction() {
notification.setStartDate(
previousStart,
previousLength, newStart);
previousEnd, newStart);
onEntrance.setStartDate(
previousStart,
previousLength, newStart);
previousStart, previousEnd,
newStart);
}
});
}
@ -645,16 +637,14 @@ public class GanttDiagramGraph<V, D> {
@Override
public void ifAlreadyInside() {
notification.setStartDate(previousStart,
previousLength, newStart);
previousEnd, newStart);
}
});
}
@Override
public void setLengthMilliseconds(
final long previousLengthMilliseconds,
final long lengthMilliseconds) {
public void setNewEnd(final Date previousEnd, final Date newEnd) {
positionsUpdatingGuard
.entranceRequested(new IReentranceCases() {
@ -664,21 +654,17 @@ public class GanttDiagramGraph<V, D> {
@Override
public void doAction() {
notification.setLengthMilliseconds(
previousLengthMilliseconds,
lengthMilliseconds);
onEntrance.setLengthMilliseconds(
previousLengthMilliseconds,
lengthMilliseconds);
notification.setNewEnd(previousEnd,
newEnd);
onEntrance.setNewEnd(previousEnd,
newEnd);
}
});
}
@Override
public void ifAlreadyInside() {
notification.setLengthMilliseconds(
previousLengthMilliseconds,
lengthMilliseconds);
notification.setNewEnd(previousEnd, newEnd);
}
});
}

View file

@ -74,23 +74,22 @@ public abstract class Task implements ITaskFundamentalProperties {
private final INotificationAfterDependenciesEnforcement notifyDates = new INotificationAfterDependenciesEnforcement() {
@Override
public void onStartDateChange(Date previousStart, long oldLength,
public void onStartDateChange(Date previousStart, Date previousEnd,
Date newStart) {
fundamentalPropertiesListeners.firePropertyChange("beginDate",
previousStart, fundamentalProperties.getBeginDate());
fireLengthMilliseconds(oldLength);
fireEndDate(previousEnd);
reloadResourcesTextIfChange(newStart, previousStart);
}
@Override
public void onLengthChange(long previousLength, long newLength) {
fireLengthMilliseconds(previousLength);
public void onEndDateChange(Date previousEnd, Date newEnd) {
fireEndDate(previousEnd);
}
private void fireLengthMilliseconds(long previousValue) {
fundamentalPropertiesListeners.firePropertyChange(
"lengthMilliseconds", previousValue, fundamentalProperties
.getLengthMilliseconds());
private void fireEndDate(Date previousEnd) {
fundamentalPropertiesListeners.firePropertyChange("endDate",
previousEnd, fundamentalProperties.getEndDate());
}
};
@ -177,9 +176,9 @@ public abstract class Task implements ITaskFundamentalProperties {
public long setBeginDate(Date newStart) {
Date previousValue = fundamentalProperties.getBeginDate();
long previousLength = fundamentalProperties.getLengthMilliseconds();
Date previousEnd = fundamentalProperties.getEndDate();
fundamentalProperties.setBeginDate(newStart);
dependenciesEnforcerHook.setStartDate(previousValue, previousLength,
dependenciesEnforcerHook.setStartDate(previousValue, previousEnd,
newStart);
return fundamentalProperties.getLengthMilliseconds();
}
@ -191,11 +190,10 @@ public abstract class Task implements ITaskFundamentalProperties {
}
public void fireChangesForPreviousValues(Date previousStart,
long previousLength) {
dependenciesEnforcerHook.setStartDate(previousStart, previousLength,
Date previousEnd) {
dependenciesEnforcerHook.setStartDate(previousStart, previousEnd,
fundamentalProperties.getBeginDate());
dependenciesEnforcerHook.setLengthMilliseconds(previousLength,
fundamentalProperties.getLengthMilliseconds());
dependenciesEnforcerHook.setNewEnd(previousEnd, getEndDate());
}
public Date getBeginDate() {
@ -203,14 +201,11 @@ public abstract class Task implements ITaskFundamentalProperties {
}
public void setLengthMilliseconds(long lengthMilliseconds) {
long previousValue = fundamentalProperties.getLengthMilliseconds();
fundamentalProperties.setLengthMilliseconds(lengthMilliseconds);
dependenciesEnforcerHook.setLengthMilliseconds(previousValue,
lengthMilliseconds);
setEndDate(new Date(getBeginDate().getTime() + lengthMilliseconds));
}
public long getLengthMilliseconds() {
return fundamentalProperties.getLengthMilliseconds();
return getEndDate().getTime() - getBeginDate().getTime();
}
public void addVisibilityPropertiesChangeListener(
@ -235,7 +230,7 @@ public abstract class Task implements ITaskFundamentalProperties {
@Override
public Date getEndDate() {
return new Date(getBeginDate().getTime() + getLengthMilliseconds());
return fundamentalProperties.getEndDate();
}
public Constraint<Date> getCurrentLengthConstraint() {
@ -267,7 +262,10 @@ public abstract class Task implements ITaskFundamentalProperties {
if (value == null) {
return;
}
setLengthMilliseconds(value.getTime() - getBeginDate().getTime());
Date previousEnd = fundamentalProperties.getEndDate();
fundamentalProperties.setEndDate(value);
dependenciesEnforcerHook.setNewEnd(previousEnd,
fundamentalProperties.getEndDate());
}
public void removed() {
@ -312,9 +310,9 @@ public abstract class Task implements ITaskFundamentalProperties {
public void moveTo(Date date) {
Date previousStart = getBeginDate();
long previousLength = getLengthMilliseconds();
Date previousEnd = getEndDate();
fundamentalProperties.moveTo(date);
dependenciesEnforcerHook.setStartDate(previousStart, previousLength, date);
dependenciesEnforcerHook.setStartDate(previousStart, previousEnd, date);
}
@Override

View file

@ -54,24 +54,23 @@ import org.navalplanner.business.workingday.ResourcesPerDay;
public abstract class TaskElement extends BaseEntity {
public interface IDatesInterceptor {
public void setStartDate(Date previousStart, long previousLength,
Date newStart);
public void setStartDate(IntraDayDate previousStart,
IntraDayDate previousEnd, IntraDayDate newStart);
public void setLengthMilliseconds(long previousLengthMilliseconds,
long newLengthMilliseconds);
public void setNewEnd(IntraDayDate previousEnd, IntraDayDate newEnd);
}
private static final IDatesInterceptor EMPTY_INTERCEPTOR = new IDatesInterceptor() {
@Override
public void setStartDate(Date previousStart, long previousLength,
Date newStart) {
public void setStartDate(IntraDayDate previousStart,
IntraDayDate previousEnd, IntraDayDate newStart) {
}
@Override
public void setLengthMilliseconds(long previousLengthMilliseconds,
long newLengthMilliseconds) {
public void setNewEnd(IntraDayDate previousEnd, IntraDayDate newEnd) {
}
};
public static Comparator<TaskElement> getByStartDateComparator() {
@ -252,11 +251,11 @@ public abstract class TaskElement extends BaseEntity {
}
public void setIntraDayStartDate(IntraDayDate startDate) {
Date previousDate = getStartDate();
long previousLenghtMilliseconds = getLengthMilliseconds();
IntraDayDate previousStart = getIntraDayStartDate();
IntraDayDate previousEnd = getIntraDayEndDate();
this.startDate = startDate;
datesInterceptor.setStartDate(previousDate, previousLenghtMilliseconds,
getStartDate());
datesInterceptor.setStartDate(previousStart, previousEnd,
getIntraDayStartDate());
}
/**
@ -294,10 +293,9 @@ public abstract class TaskElement extends BaseEntity {
}
public void setIntraDayEndDate(IntraDayDate endDate) {
long previousLength = getLengthMilliseconds();
IntraDayDate previousEnd = getIntraDayEndDate();
this.endDate = endDate;
datesInterceptor.setLengthMilliseconds(previousLength,
getLengthMilliseconds());
datesInterceptor.setNewEnd(previousEnd, this.endDate);
}
public IntraDayDate getIntraDayEndDate() {

View file

@ -27,10 +27,11 @@ import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.Map.Entry;
import java.util.Set;
import org.apache.commons.lang.Validate;
import org.joda.time.LocalDate;
import org.navalplanner.business.common.IAdHocTransactionService;
import org.navalplanner.business.common.IOnTransaction;
import org.navalplanner.business.common.exceptions.InstanceNotFoundException;
@ -38,11 +39,11 @@ import org.navalplanner.business.orders.entities.Order;
import org.navalplanner.business.orders.entities.TaskSource;
import org.navalplanner.business.planner.daos.ITaskSourceDAO;
import org.navalplanner.business.planner.entities.Dependency;
import org.navalplanner.business.planner.entities.Dependency.Type;
import org.navalplanner.business.planner.entities.Task;
import org.navalplanner.business.planner.entities.TaskElement;
import org.navalplanner.business.planner.entities.TaskGroup;
import org.navalplanner.business.planner.entities.Dependency.Type;
import org.navalplanner.business.planner.entities.TaskElement.IDatesInterceptor;
import org.navalplanner.business.planner.entities.TaskGroup;
import org.navalplanner.business.resources.daos.IResourceDAO;
import org.navalplanner.business.scenarios.daos.IOrderVersionDAO;
import org.navalplanner.business.scenarios.daos.IScenarioDAO;
@ -50,6 +51,7 @@ import org.navalplanner.business.scenarios.entities.OrderVersion;
import org.navalplanner.business.scenarios.entities.Scenario;
import org.navalplanner.business.users.daos.IUserDAO;
import org.navalplanner.business.users.entities.User;
import org.navalplanner.business.workingday.IntraDayDate;
import org.navalplanner.web.planner.TaskElementAdapter;
import org.navalplanner.web.users.services.CustomUser;
import org.springframework.beans.factory.annotation.Autowired;
@ -186,20 +188,25 @@ public class TemplateModel implements ITemplateModel {
return new IDatesInterceptor() {
@Override
public void setStartDate(Date previousStart, long previousLength,
Date newStart) {
hook.setStartDate(previousStart, previousLength, newStart);
public void setStartDate(IntraDayDate previousStart,
IntraDayDate previousEnd, IntraDayDate newStart) {
hook.setStartDate(convert(previousStart.getDate()),
convert(previousEnd.asExclusiveEnd()),
convert(newStart.getDate()));
}
@Override
public void setLengthMilliseconds(long previousLengthMilliseconds,
long newLengthMilliseconds) {
hook.setLengthMilliseconds(previousLengthMilliseconds,
newLengthMilliseconds);
public void setNewEnd(IntraDayDate previousEnd, IntraDayDate newEnd) {
hook.setNewEnd(convert(previousEnd.getDate()),
convert(newEnd.asExclusiveEnd()));
}
};
}
private static Date convert(LocalDate date) {
return date.toDateTimeAtStartOfDay().toDate();
}
public class Adapter implements
IAdapter<TaskElement, DependencyWithVisibility> {

View file

@ -196,10 +196,9 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
IOnTransaction<?> allocationDoer) {
org.zkoss.ganttz.data.Task ganttTask = context.getTask();
Date previousStartDate = ganttTask.getBeginDate();
long previousLength = ganttTask.getLengthMilliseconds();
Date previousEnd = ganttTask.getEndDate();
transactionService.runOnReadOnlyTransaction(allocationDoer);
ganttTask.fireChangesForPreviousValues(previousStartDate,
previousLength);
ganttTask.fireChangesForPreviousValues(previousStartDate, previousEnd);
}
private void stepsBeforeDoingAllocation() {

View file

@ -143,7 +143,7 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel {
if (context != null && orderElement != null && isVisibleAdvances()) {
org.zkoss.ganttz.data.Task ganttTask = context.getTask();
Date previousStartDate = ganttTask.getBeginDate();
long previousLength = ganttTask.getLengthMilliseconds();
Date previousEnd = ganttTask.getEndDate();
createConsolidationIfNeeded();
@ -158,7 +158,7 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel {
updateConsolidationInAdvanceIfIsNeeded();
ganttTask.fireChangesForPreviousValues(previousStartDate,
previousLength);
previousEnd);
ganttTask.reloadResourcesText();
context.reloadCharts();
}

View file

@ -125,13 +125,12 @@ public class SubcontractModel implements ISubcontractModel {
private void recalculateTaskLength() {
Date previousStartDate = ganttTask.getBeginDate();
long previousLength = ganttTask.getLengthMilliseconds();
Date previousEnd = ganttTask.getEndDate();
task.setStartDate(startDate);
task.setEndDate(endDate);
ganttTask.fireChangesForPreviousValues(previousStartDate,
previousLength);
ganttTask.fireChangesForPreviousValues(previousStartDate, previousEnd);
}
@Override

View file

@ -46,8 +46,8 @@ import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;
import org.zkoss.ganttz.adapters.IDomainAndBeansMapper;
import org.zkoss.ganttz.data.GanttDiagramGraph;
import org.zkoss.ganttz.data.Task;
import org.zkoss.ganttz.data.GanttDiagramGraph.DeferedNotifier;
import org.zkoss.ganttz.data.Task;
import org.zkoss.ganttz.extensions.IContext;
import org.zkoss.ganttz.util.IAction;
import org.zkoss.ganttz.util.LongOperationFeedback;
@ -146,14 +146,13 @@ public class ReassignCommand implements IReassignCommand {
for (final WithAssociatedEntity each : reassignations) {
Task ganttTask = each.ganntTask;
final Date previousBeginDate = ganttTask.getBeginDate();
final long previousLength = ganttTask
.getLengthMilliseconds();
final Date previousEnd = ganttTask.getEndDate();
transactionService
.runOnReadOnlyTransaction(reassignmentTransaction(each));
diagramGraph.enforceRestrictions(each.ganntTask);
ganttTask.fireChangesForPreviousValues(previousBeginDate,
previousLength);
previousEnd);
updater.doUpdate(showCompleted(i, total));
i++;
}