diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationCommand.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationCommand.java new file mode 100644 index 000000000..1cca39a6a --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/AdvancedAllocationCommand.java @@ -0,0 +1,76 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2011 Igalia, S.L. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.navalplanner.web.planner.allocation; + +import static org.navalplanner.web.I18nHelper._; + +import org.navalplanner.business.planner.entities.Task; +import org.navalplanner.business.planner.entities.TaskElement; +import org.navalplanner.web.planner.order.PlanningStateCreator.PlanningState; +import org.navalplanner.web.planner.taskedition.EditTaskController; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.context.annotation.Scope; +import org.springframework.stereotype.Component; +import org.zkoss.ganttz.extensions.IContextWithPlannerTask; + +/** + * A command that opens a window to make the advance allocation of a task. + * + * @author Manuel Rego Casasnovas + */ +@Component +@Scope(BeanDefinition.SCOPE_PROTOTYPE) +public class AdvancedAllocationCommand implements IAdvancedAllocationCommand { + + private EditTaskController editTaskController; + private PlanningState planningState; + + @Override + public String getName() { + return _("Advanced allocation"); + } + + @Override + public String getIcon() { + return "/common/img/ico_menu_advanced-assignment.png"; + } + + @Override + public void doAction(IContextWithPlannerTask context, + TaskElement taskElement) { + if (isApplicableTo(taskElement)) { + editTaskController.showAdvancedAllocation((Task) taskElement, + context, planningState); + } + } + + @Override + public boolean isApplicableTo(TaskElement task) { + return (task instanceof Task) && !task.isSubcontracted(); + } + + @Override + public void initialize(EditTaskController editTaskController, + PlanningState state) { + this.editTaskController = editTaskController; + this.planningState = state; + } + +} diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IAdvancedAllocationCommand.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IAdvancedAllocationCommand.java new file mode 100644 index 000000000..b036573c9 --- /dev/null +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/allocation/IAdvancedAllocationCommand.java @@ -0,0 +1,37 @@ +/* + * This file is part of NavalPlan + * + * Copyright (C) 2011 Igalia, S.L. + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + */ + +package org.navalplanner.web.planner.allocation; + +import org.navalplanner.business.planner.entities.TaskElement; +import org.navalplanner.web.planner.order.PlanningStateCreator.PlanningState; +import org.navalplanner.web.planner.taskedition.EditTaskController; +import org.zkoss.ganttz.extensions.ICommandOnTask; + +/** + * Contract for {@link AdvancedAllocationCommand}. + * + * @author Manuel Rego Casasnovas + */ +public interface IAdvancedAllocationCommand extends ICommandOnTask { + + void initialize(EditTaskController editTaskController, + PlanningState state); + +} diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/order/OrderPlanningModel.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/order/OrderPlanningModel.java index e2c4a925d..15986627b 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/order/OrderPlanningModel.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/order/OrderPlanningModel.java @@ -78,6 +78,7 @@ import org.navalplanner.web.calendars.BaseCalendarModel; import org.navalplanner.web.common.ViewSwitcher; import org.navalplanner.web.planner.advances.AdvanceAssignmentPlanningController; import org.navalplanner.web.planner.advances.IAdvanceAssignmentPlanningCommand; +import org.navalplanner.web.planner.allocation.IAdvancedAllocationCommand; import org.navalplanner.web.planner.allocation.IResourceAllocationCommand; import org.navalplanner.web.planner.calendar.CalendarAllocationController; import org.navalplanner.web.planner.calendar.ICalendarAllocationCommand; @@ -224,6 +225,9 @@ public class OrderPlanningModel implements IOrderPlanningModel { @Autowired private IResourceAllocationCommand resourceAllocationCommand; + @Autowired + private IAdvancedAllocationCommand advancedAllocationCommand; + @Autowired private IAddMilestoneCommand addMilestoneCommand; @@ -335,6 +339,8 @@ public class OrderPlanningModel implements IOrderPlanningModel { configuration .addCommandOnTask(buildTaskPropertiesCommand(editTaskController)); configuration.addCommandOnTask(resourceAllocationCommand); + configuration + .addCommandOnTask(buildAdvancedAllocationCommand(editTaskController)); configuration .addCommandOnTask(buildSubcontractCommand(editTaskController)); configuration @@ -982,6 +988,12 @@ public class OrderPlanningModel implements IOrderPlanningModel { return resourceAllocationCommand; } + private IAdvancedAllocationCommand buildAdvancedAllocationCommand( + EditTaskController editTaskController) { + advancedAllocationCommand.initialize(editTaskController, planningState); + return advancedAllocationCommand; + } + private ICommand buildReassigningCommand() { reassignCommand.setState(planningState); return reassignCommand; diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/taskedition/EditTaskController.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/taskedition/EditTaskController.java index 281baf581..cc0a2cb5f 100644 --- a/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/taskedition/EditTaskController.java +++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/planner/taskedition/EditTaskController.java @@ -42,7 +42,6 @@ import org.navalplanner.web.planner.allocation.AdvancedAllocationController.IAdv import org.navalplanner.web.planner.allocation.AdvancedAllocationController.Restriction; import org.navalplanner.web.planner.allocation.AdvancedAllocationController.Restriction.IRestrictionSource; import org.navalplanner.web.planner.allocation.AllocationResult; -import org.navalplanner.web.planner.allocation.FormBinder; import org.navalplanner.web.planner.allocation.ResourceAllocationController; import org.navalplanner.web.planner.limiting.allocation.LimitingResourceAllocationController; import org.navalplanner.web.planner.order.PlanningStateCreator.PlanningState; @@ -360,21 +359,24 @@ public class EditTaskController extends GenericForwardComposer { return (isTask(task) && !task.isSubcontracted()); } - public void goToAdvancedAllocation() { - FormBinder formBinder = resourceAllocationController.getFormBinder(); + public void showAdvancedAllocation(Task task, + IContextWithPlannerTask context, + PlanningState planningState) { + this.taskElement = task; + this.context = context; + this.planningState = planningState; + + AllocationResult allocationResult = AllocationResult.createCurrent( + planningState.getCurrentScenario(), task); - AllocationResult allocationResult = formBinder.getLastAllocation(); - if (allocationResult.getAggregate().isEmpty()) { - formBinder.doApply(); - allocationResult = formBinder.getLastAllocation(); - } if (allocationResult.getAggregate().isEmpty()) { getMessagesForUser().showMessage(Level.WARNING, _("Some allocations needed")); return; } - getSwitcher().goToAdvancedAllocation( - allocationResult, createResultReceiver(allocationResult)); + + getSwitcher().goToAdvancedAllocation(allocationResult, + createResultReceiver(allocationResult)); window.setVisible(false); } @@ -432,12 +434,14 @@ public class EditTaskController extends GenericForwardComposer { @Override public void cancel() { - showEditFormResourceAllocation(context, taskElement, planningState); + // Do nothing } @Override public void accepted(AggregateOfResourceAllocations aggregate) { - resourceAllocationController.accept(allocation); + allocation.applyTo(planningState.getCurrentScenario(), + (Task) taskElement); + askForReloads(); } @Override