From 175f785f9192e00e448269e5dabfe22d71551a0d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=93scar=20Gonz=C3=A1lez=20Fern=C3=A1ndez?= Date: Fri, 22 Apr 2011 18:01:19 +0200 Subject: [PATCH] AllocationRow tracks the current calculated value FEA: ItEr74S04BugFixing --- .../web/planner/allocation/AllocationRow.java | 26 +++++++++++----- .../allocation/AllocationRowsHandler.java | 5 +-- .../allocation/GenericAllocationRow.java | 26 +++++++++++----- .../allocation/SpecificAllocationRow.java | 31 ++++++++++++++----- 4 files changed, 64 insertions(+), 24 deletions(-) diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRow.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRow.java index 12617ba31..2c0c3dde2 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRow.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRow.java @@ -210,7 +210,9 @@ public abstract class AllocationRow { return result; } - private ResourceAllocation origin; + private final ResourceAllocation origin; + + private CalculatedValue currentCalculatedValue; private ResourceAllocation temporal; @@ -245,12 +247,24 @@ public abstract class AllocationRow { }); } - public AllocationRow() { + public AllocationRow(CalculatedValue calculatedValue) { + this.currentCalculatedValue = calculatedValue; + this.origin = null; + initialize(); + } + + public AllocationRow(ResourceAllocation origin) { + this.origin = origin; + this.currentCalculatedValue = origin.getTask().getCalculatedValue(); + initialize(); + } + + private void initialize() { setNonConsolidatedResourcesPerDay(ResourcesPerDay.amount(0)); initializeResourcesPerDayInput(); - hoursInput.setValue(0); hoursInput.setWidth("80px"); hoursInput.setConstraint(constraintForHoursInput()); + loadHours(); } public abstract ResourcesPerDayModification toResourcesPerDayModification( @@ -272,11 +286,6 @@ public abstract class AllocationRow { return origin; } - protected void setOrigin(ResourceAllocation allocation) { - this.origin = allocation; - loadHours(); - } - public boolean hasDerivedAllocations() { return ! getDerivedAllocations().isEmpty(); } @@ -369,6 +378,7 @@ public abstract class AllocationRow { public void applyDisabledRules(CalculatedValue calculatedValue, boolean recommendedAllocation) { + this.currentCalculatedValue = calculatedValue; hoursInput .setDisabled(calculatedValue != CalculatedValue.RESOURCES_PER_DAY || recommendedAllocation); diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRowsHandler.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRowsHandler.java index 4dc311c75..745f9cb2f 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRowsHandler.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AllocationRowsHandler.java @@ -79,7 +79,7 @@ public class AllocationRowsHandler { alreadyPresent.add(each); } else { SpecificAllocationRow specificAllocationRow = SpecificAllocationRow - .forResource(each); + .forResource(getCalculatedValue(), each); setupInitialHours(specificAllocationRow); currentRows.add(specificAllocationRow); formBinder.newAllocationAdded(); @@ -105,7 +105,8 @@ public class AllocationRowsHandler { return false; } else { GenericAllocationRow genericAllocationRow = GenericAllocationRow - .create(resourceType, criteria, resourcesMatched); + .create(getCalculatedValue(), resourceType, criteria, + resourcesMatched); if (hours != null) { genericAllocationRow.setHoursToInput(hours); } else { diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationRow.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationRow.java index e0cc800cb..f433e1f2d 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationRow.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/GenericAllocationRow.java @@ -31,6 +31,7 @@ import java.util.List; import java.util.Set; import org.apache.commons.lang.Validate; +import org.navalplanner.business.planner.entities.CalculatedValue; import org.navalplanner.business.planner.entities.GenericResourceAllocation; import org.navalplanner.business.planner.entities.ResourceAllocation; import org.navalplanner.business.planner.entities.Task; @@ -49,21 +50,24 @@ import org.navalplanner.business.workingday.ResourcesPerDay; */ public class GenericAllocationRow extends AllocationRow { - private static GenericAllocationRow createDefault(ResourceEnum resourceType) { + private static GenericAllocationRow initializeDefault( + GenericAllocationRow result, ResourceEnum resourceType) { Validate.notNull(resourceType); - GenericAllocationRow result = new GenericAllocationRow(); result.setName(_("Generic")); result.setNonConsolidatedResourcesPerDay(ResourcesPerDay.amount(0)); result.resourceType = resourceType; return result; } - public static GenericAllocationRow create(ResourceEnum resourceType, + public static GenericAllocationRow create(CalculatedValue calculatedValue, + ResourceEnum resourceType, Collection criterions, Collection resources) { + + GenericAllocationRow result = new GenericAllocationRow(calculatedValue); Validate.isTrue(!resources.isEmpty()); Validate.notNull(criterions); - GenericAllocationRow result = createDefault(resourceType); + initializeDefault(result, resourceType); result.criterions = new HashSet(criterions); result.resources = new ArrayList(resources); result.setName(Criterion.getCaptionFor(resourceType, criterions)); @@ -73,9 +77,9 @@ public class GenericAllocationRow extends AllocationRow { public static GenericAllocationRow from( GenericResourceAllocation resourceAllocation, IResourcesSearcher searchModel) { - GenericAllocationRow result = createDefault(resourceAllocation - .getResourceType()); - result.setOrigin(resourceAllocation); + GenericAllocationRow result = initializeDefault( + new GenericAllocationRow(resourceAllocation), + resourceAllocation.getResourceType()); result.setNonConsolidatedResourcesPerDay(resourceAllocation .getNonConsolidatedResourcePerDay()); @@ -98,6 +102,14 @@ public class GenericAllocationRow extends AllocationRow { private Set criterions; private List resources; + private GenericAllocationRow(CalculatedValue calculatedValue) { + super(calculatedValue); + } + + private GenericAllocationRow(GenericResourceAllocation origin) { + super(origin); + } + @Override public boolean isGeneric() { return true; diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationRow.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationRow.java index b86b6c9e7..599ecedc4 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationRow.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/SpecificAllocationRow.java @@ -26,6 +26,7 @@ import java.util.Collection; import java.util.Collections; import java.util.List; +import org.navalplanner.business.planner.entities.CalculatedValue; import org.navalplanner.business.planner.entities.ResourceAllocation; import org.navalplanner.business.planner.entities.SpecificResourceAllocation; import org.navalplanner.business.planner.entities.Task; @@ -86,8 +87,8 @@ public class SpecificAllocationRow extends AllocationRow { } public static SpecificAllocationRow from(SpecificResourceAllocation specific) { - SpecificAllocationRow result = forResource(specific.getResource()); - result.setOrigin(specific); + SpecificAllocationRow result = new SpecificAllocationRow(specific); + setupResource(result, specific.getResource()); result.setNonConsolidatedResourcesPerDay(specific .getNonConsolidatedResourcePerDay()); @@ -95,16 +96,32 @@ public class SpecificAllocationRow extends AllocationRow { return result; } - public static SpecificAllocationRow forResource(Resource resource) { - SpecificAllocationRow result = new SpecificAllocationRow(); - result.setName(resource.getShortDescription()); - result.setResource(resource); - result.setNonConsolidatedResourcesPerDay(ResourcesPerDay.amount(1)); + public static SpecificAllocationRow forResource( + CalculatedValue calculatedValue, Resource resource) { + SpecificAllocationRow result = new SpecificAllocationRow( + calculatedValue); + setupResource(result, resource); return result; } + private static void setupResource(SpecificAllocationRow specificRow, + Resource resource) { + specificRow.setName(resource.getShortDescription()); + specificRow.setResource(resource); + specificRow + .setNonConsolidatedResourcesPerDay(ResourcesPerDay.amount(1)); + } + private Resource resource; + private SpecificAllocationRow(CalculatedValue calculatedValue) { + super(calculatedValue); + } + + private SpecificAllocationRow(SpecificResourceAllocation origin) { + super(origin); + } + @Override public ResourcesPerDayModification toResourcesPerDayModification(Task task, Collection> requestedToRemove) {