Remove uneeded parameters to prevent redundant invocations to scheduling algorithm.

When a task is potentially modified is not needed to change the start
and the end date. This was causing two invokations of the
"dependencies" algorithm. Now only one is done.
This commit is contained in:
Óscar González Fernández 2012-03-01 12:10:19 +01:00 committed by Jacobo Aragunde Pérez
parent bc8da4d84a
commit ee88157afb
7 changed files with 51 additions and 37 deletions

View file

@ -79,6 +79,10 @@ public class GanttDiagramGraph<V, D extends IDependency<V>> implements
public void setStartDate(GanttDate previousStart,
GanttDate previousEnd, GanttDate newStart) {
}
@Override
public void positionPotentiallyModified() {
}
};
}
@ -555,13 +559,17 @@ public class GanttDiagramGraph<V, D extends IDependency<V>> implements
}
}
public interface IDependenciesEnforcerHook {
private interface IDependenciesEnforcer {
public void setStartDate(GanttDate previousStart,
GanttDate previousEnd, GanttDate newStart);
public void setNewEnd(GanttDate previousEnd, GanttDate newEnd);
}
public interface IDependenciesEnforcerHook extends IDependenciesEnforcer {
public void positionPotentiallyModified();
}
public interface IDependenciesEnforcerHookFactory<T> {
public IDependenciesEnforcerHook create(T task,
INotificationAfterDependenciesEnforcement notification);
@ -708,8 +716,10 @@ public class GanttDiagramGraph<V, D extends IDependency<V>> implements
@Override
public IDependenciesEnforcerHook create(V task,
INotificationAfterDependenciesEnforcement notificator) {
return onlyEnforceDependenciesOnEntrance(onEntrance(task),
onNotification(task, notificator));
return withPositionPotentiallyModified(
task,
onlyEnforceDependenciesOnEntrance(onEntrance(task),
onNotification(task, notificator)));
}
@Override
@ -717,8 +727,8 @@ public class GanttDiagramGraph<V, D extends IDependency<V>> implements
return create(task, EMPTY_NOTIFICATOR);
}
private IDependenciesEnforcerHook onEntrance(final V task) {
return new IDependenciesEnforcerHook() {
private IDependenciesEnforcer onEntrance(final V task) {
return new IDependenciesEnforcer() {
public void setStartDate(GanttDate previousStart,
GanttDate previousEnd, GanttDate newStart) {
@ -733,9 +743,9 @@ public class GanttDiagramGraph<V, D extends IDependency<V>> implements
};
}
private IDependenciesEnforcerHook onNotification(final V task,
private IDependenciesEnforcer onNotification(final V task,
final INotificationAfterDependenciesEnforcement notification) {
return new IDependenciesEnforcerHook() {
return new IDependenciesEnforcer() {
@Override
public void setStartDate(GanttDate previousStart,
@ -757,11 +767,33 @@ public class GanttDiagramGraph<V, D extends IDependency<V>> implements
}
private IDependenciesEnforcerHook onlyEnforceDependenciesOnEntrance(
final IDependenciesEnforcerHook onEntrance,
final IDependenciesEnforcerHook notification) {
private IDependenciesEnforcerHook withPositionPotentiallyModified(
final V task, final IDependenciesEnforcer enforcer) {
return new IDependenciesEnforcerHook() {
@Override
public void setStartDate(GanttDate previousStart,
GanttDate previousEnd, GanttDate newStart) {
enforcer.setStartDate(previousStart, previousEnd, newStart);
}
@Override
public void setNewEnd(GanttDate previousEnd, GanttDate newEnd) {
enforcer.setNewEnd(previousEnd, newEnd);
}
@Override
public void positionPotentiallyModified() {
taskPositionModified(task);
}
};
}
private IDependenciesEnforcer onlyEnforceDependenciesOnEntrance(
final IDependenciesEnforcer onEntrance,
final IDependenciesEnforcer notification) {
return new IDependenciesEnforcer() {
@Override
public void setStartDate(final GanttDate previousStart,
final GanttDate previousEnd, final GanttDate newStart) {

View file

@ -85,7 +85,8 @@ public abstract class Task implements ITaskFundamentalProperties {
private ConstraintViolationNotificator<GanttDate> violationNotificator = ConstraintViolationNotificator
.create();
private IDependenciesEnforcerHook dependenciesEnforcerHook = GanttDiagramGraph.doNothingHook();
private IDependenciesEnforcerHook dependenciesEnforcerHook = GanttDiagramGraph
.doNothingHook();
private final INotificationAfterDependenciesEnforcement notifyDates = new INotificationAfterDependenciesEnforcement() {
@ -258,11 +259,8 @@ public abstract class Task implements ITaskFundamentalProperties {
Validate.notNull(dependenciesEnforcerHook);
}
public void fireChangesForPreviousValues(GanttDate previousStart,
GanttDate previousEnd) {
dependenciesEnforcerHook.setStartDate(previousStart, previousStart,
fundamentalProperties.getBeginDate());
dependenciesEnforcerHook.setNewEnd(previousEnd, getEndDate());
public void enforceDependenciesDueToPositionPotentiallyModified() {
dependenciesEnforcerHook.positionPotentiallyModified();
}
public GanttDate getBeginDate() {

View file

@ -188,12 +188,9 @@ public class ResourceAllocationModel implements IResourceAllocationModel {
private <V, T extends Flagged<V, ?>> T applyDateChangesNotificationIfNoFlags(
IOnTransaction<T> allocationDoer) {
org.zkoss.ganttz.data.Task ganttTask = context.getTask();
GanttDate previousStartDate = ganttTask.getBeginDate();
GanttDate previousEnd = ganttTask.getEndDate();
T result = transactionService.runOnReadOnlyTransaction(allocationDoer);
if (!result.isFlagged()) {
ganttTask.fireChangesForPreviousValues(previousStartDate,
previousEnd);
ganttTask.enforceDependenciesDueToPositionPotentiallyModified();
}
return result;
}

View file

@ -138,8 +138,6 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel {
public void accept() {
if (context != null && orderElement != null && isVisibleAdvances()) {
org.zkoss.ganttz.data.Task ganttTask = context.getTask();
GanttDate previousStartDate = ganttTask.getBeginDate();
GanttDate previousEnd = ganttTask.getEndDate();
createConsolidationIfNeeded();
@ -153,8 +151,7 @@ public class AdvanceConsolidationModel implements IAdvanceConsolidationModel {
updateConsolidationInAdvanceIfIsNeeded();
ganttTask.fireChangesForPreviousValues(previousStartDate,
previousEnd);
ganttTask.enforceDependenciesDueToPositionPotentiallyModified();
ganttTask.reloadResourcesText();
context.reloadCharts();
}

View file

@ -383,11 +383,8 @@ public class LimitingResourceAllocationModel implements ILimitingResourceAllocat
IOnTransaction<?> allocationDoer) {
if (context != null) {
org.zkoss.ganttz.data.Task ganttTask = context.getTask();
GanttDate previousStartDate = ganttTask.getBeginDate();
GanttDate previousEnd = ganttTask.getEndDate();
transactionService.runOnReadOnlyTransaction(allocationDoer);
ganttTask.fireChangesForPreviousValues(previousStartDate,
previousEnd);
ganttTask.enforceDependenciesDueToPositionPotentiallyModified();
} else {
// Update hours of a Task from Limiting Resource view
transactionService.runOnReadOnlyTransaction(allocationDoer);

View file

@ -115,13 +115,10 @@ public class SubcontractModel implements ISubcontractModel {
}
private void recalculateTaskLength() {
GanttDate previousStartDate = ganttTask.getBeginDate();
GanttDate previousEnd = ganttTask.getEndDate();
task.setStartDate(startDate);
task.setEndDate(endDate);
ganttTask.fireChangesForPreviousValues(previousStartDate, previousEnd);
ganttTask.enforceDependenciesDueToPositionPotentiallyModified();
}
@Override

View file

@ -167,15 +167,11 @@ public class ReassignCommand implements IReassignCommand {
final int total = reassignations.size();
for (final WithAssociatedEntity each : reassignations) {
Task ganttTask = each.ganntTask;
final GanttDate previousBeginDate = ganttTask
.getBeginDate();
final GanttDate previousEnd = ganttTask.getEndDate();
transactionService
.runOnReadOnlyTransaction(reassignmentTransaction(each));
diagramGraph.enforceRestrictions(each.ganntTask);
ganttTask.fireChangesForPreviousValues(previousBeginDate,
previousEnd);
ganttTask.enforceDependenciesDueToPositionPotentiallyModified();
updater.doUpdate(showCompleted(i, total));
i++;
}