Move advanced allocation command controller out of EditTaskController
FEA: ItEr75S23FixAllocationModel
This commit is contained in:
parent
d09dbb7fcb
commit
4b66eb66b6
8 changed files with 193 additions and 116 deletions
|
|
@ -24,7 +24,7 @@ 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.navalplanner.web.planner.taskedition.AdvancedAllocationTaskController;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.springframework.stereotype.Component;
|
||||
|
|
@ -39,7 +39,7 @@ import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
|
|||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class AdvancedAllocationCommand implements IAdvancedAllocationCommand {
|
||||
|
||||
private EditTaskController editTaskController;
|
||||
private AdvancedAllocationTaskController advancedAllocationTaskController;
|
||||
private PlanningState planningState;
|
||||
|
||||
@Override
|
||||
|
|
@ -56,7 +56,8 @@ public class AdvancedAllocationCommand implements IAdvancedAllocationCommand {
|
|||
public void doAction(IContextWithPlannerTask<TaskElement> context,
|
||||
TaskElement taskElement) {
|
||||
if (isApplicableTo(taskElement)) {
|
||||
editTaskController.showAdvancedAllocation((Task) taskElement,
|
||||
advancedAllocationTaskController.showAdvancedAllocation(
|
||||
(Task) taskElement,
|
||||
context, planningState);
|
||||
}
|
||||
}
|
||||
|
|
@ -67,9 +68,10 @@ public class AdvancedAllocationCommand implements IAdvancedAllocationCommand {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void initialize(EditTaskController editTaskController,
|
||||
public void initialize(
|
||||
AdvancedAllocationTaskController advancedAllocationTaskController,
|
||||
PlanningState state) {
|
||||
this.editTaskController = editTaskController;
|
||||
this.advancedAllocationTaskController = advancedAllocationTaskController;
|
||||
this.planningState = state;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ 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.navalplanner.web.planner.taskedition.AdvancedAllocationTaskController;
|
||||
import org.zkoss.ganttz.extensions.ICommandOnTask;
|
||||
|
||||
/**
|
||||
|
|
@ -31,7 +31,8 @@ import org.zkoss.ganttz.extensions.ICommandOnTask;
|
|||
*/
|
||||
public interface IAdvancedAllocationCommand extends ICommandOnTask<TaskElement> {
|
||||
|
||||
void initialize(EditTaskController editTaskController,
|
||||
void initialize(
|
||||
AdvancedAllocationTaskController advancedAllocationTaskController,
|
||||
PlanningState state);
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -30,6 +30,7 @@ import org.navalplanner.web.planner.advances.AdvanceAssignmentPlanningController
|
|||
import org.navalplanner.web.planner.calendar.CalendarAllocationController;
|
||||
import org.navalplanner.web.planner.consolidations.AdvanceConsolidationController;
|
||||
import org.navalplanner.web.planner.order.PlanningStateCreator.PlanningState;
|
||||
import org.navalplanner.web.planner.taskedition.AdvancedAllocationTaskController;
|
||||
import org.navalplanner.web.planner.taskedition.EditTaskController;
|
||||
import org.zkoss.ganttz.Planner;
|
||||
import org.zkoss.ganttz.extensions.ICommand;
|
||||
|
|
@ -42,6 +43,7 @@ public interface IOrderPlanningModel {
|
|||
void setConfigurationToPlanner(Planner planner, Order order,
|
||||
ViewSwitcher viewSwitcher,
|
||||
EditTaskController editTaskController,
|
||||
AdvancedAllocationTaskController advancedAllocationTaskController,
|
||||
AdvanceAssignmentPlanningController advanceAssignmentPlanningController,
|
||||
AdvanceConsolidationController advanceConsolidationController,
|
||||
CalendarAllocationController calendarAllocationController,
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@ import org.navalplanner.web.orders.OrderElementPredicate;
|
|||
import org.navalplanner.web.planner.advances.AdvanceAssignmentPlanningController;
|
||||
import org.navalplanner.web.planner.calendar.CalendarAllocationController;
|
||||
import org.navalplanner.web.planner.consolidations.AdvanceConsolidationController;
|
||||
import org.navalplanner.web.planner.taskedition.AdvancedAllocationTaskController;
|
||||
import org.navalplanner.web.planner.taskedition.EditTaskController;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
|
|
@ -95,6 +96,9 @@ public class OrderPlanningController implements Composer {
|
|||
@Autowired
|
||||
private EditTaskController editTaskController;
|
||||
|
||||
@Autowired
|
||||
private AdvancedAllocationTaskController advancedAllocationTaskController;
|
||||
|
||||
@Autowired
|
||||
private AdvanceConsolidationController advanceConsolidationController;
|
||||
|
||||
|
|
@ -201,7 +205,8 @@ public class OrderPlanningController implements Composer {
|
|||
if (order != null) {
|
||||
long time = System.currentTimeMillis();
|
||||
model.setConfigurationToPlanner(planner, order, viewSwitcher,
|
||||
editTaskController, advanceAssignmentPlanningController,
|
||||
editTaskController, advancedAllocationTaskController,
|
||||
advanceAssignmentPlanningController,
|
||||
advanceConsolidationController,
|
||||
calendarAllocationController, additional);
|
||||
PROFILING_LOG.info("setConfigurationToPlanner took: "
|
||||
|
|
@ -215,6 +220,10 @@ public class OrderPlanningController implements Composer {
|
|||
return editTaskController;
|
||||
}
|
||||
|
||||
public AdvancedAllocationTaskController getAdvancedAllocationTaskController() {
|
||||
return advancedAllocationTaskController;
|
||||
}
|
||||
|
||||
public OrderCRUDController getOrderCRUDController() {
|
||||
return orderCRUDController;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -95,6 +95,7 @@ import org.navalplanner.web.planner.order.ISaveCommand.IAfterSaveListener;
|
|||
import org.navalplanner.web.planner.order.PlanningStateCreator.IActionsOnRetrieval;
|
||||
import org.navalplanner.web.planner.order.PlanningStateCreator.PlanningState;
|
||||
import org.navalplanner.web.planner.reassign.IReassignCommand;
|
||||
import org.navalplanner.web.planner.taskedition.AdvancedAllocationTaskController;
|
||||
import org.navalplanner.web.planner.taskedition.EditTaskController;
|
||||
import org.navalplanner.web.planner.taskedition.ITaskPropertiesCommand;
|
||||
import org.navalplanner.web.print.CutyPrint;
|
||||
|
|
@ -292,6 +293,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
public void setConfigurationToPlanner(final Planner planner, Order order,
|
||||
ViewSwitcher switcher,
|
||||
EditTaskController editTaskController,
|
||||
AdvancedAllocationTaskController advancedAllocationTaskController,
|
||||
AdvanceAssignmentPlanningController advanceAssignmentPlanningController,
|
||||
AdvanceConsolidationController advanceConsolidationController,
|
||||
CalendarAllocationController calendarAllocationController,
|
||||
|
|
@ -340,7 +342,7 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
.addCommandOnTask(buildTaskPropertiesCommand(editTaskController));
|
||||
configuration.addCommandOnTask(resourceAllocationCommand);
|
||||
configuration
|
||||
.addCommandOnTask(buildAdvancedAllocationCommand(editTaskController));
|
||||
.addCommandOnTask(buildAdvancedAllocationCommand(advancedAllocationTaskController));
|
||||
configuration
|
||||
.addCommandOnTask(buildSubcontractCommand(editTaskController));
|
||||
configuration
|
||||
|
|
@ -989,8 +991,9 @@ public class OrderPlanningModel implements IOrderPlanningModel {
|
|||
}
|
||||
|
||||
private IAdvancedAllocationCommand buildAdvancedAllocationCommand(
|
||||
EditTaskController editTaskController) {
|
||||
advancedAllocationCommand.initialize(editTaskController, planningState);
|
||||
AdvancedAllocationTaskController advancedAllocationTaskController) {
|
||||
advancedAllocationCommand.initialize(advancedAllocationTaskController,
|
||||
planningState);
|
||||
return advancedAllocationCommand;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -0,0 +1,164 @@
|
|||
/*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package org.navalplanner.web.planner.taskedition;
|
||||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations;
|
||||
import org.navalplanner.business.planner.entities.CalculatedValue;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.IntraDayDate;
|
||||
import org.navalplanner.web.common.ViewSwitcher;
|
||||
import org.navalplanner.web.planner.allocation.AdvancedAllocationController.IAdvanceAllocationResultReceiver;
|
||||
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.order.PlanningStateCreator.PlanningState;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Messagebox;
|
||||
|
||||
/**
|
||||
* Controller for advanced allocation of a {@link Task}.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <rego@igalia.com>
|
||||
*/
|
||||
@org.springframework.stereotype.Component("advancedAllocationTaskController")
|
||||
@Scope(BeanDefinition.SCOPE_PROTOTYPE)
|
||||
public class AdvancedAllocationTaskController extends GenericForwardComposer {
|
||||
|
||||
private Task taskElement;
|
||||
|
||||
private IContextWithPlannerTask<TaskElement> context;
|
||||
|
||||
private PlanningState planningState;
|
||||
|
||||
private ViewSwitcher switcher;
|
||||
|
||||
public void showAdvancedAllocation(Task task,
|
||||
IContextWithPlannerTask<TaskElement> context,
|
||||
PlanningState planningState) {
|
||||
this.taskElement = task;
|
||||
this.context = context;
|
||||
this.planningState = planningState;
|
||||
|
||||
AllocationResult allocationResult = AllocationResult.createCurrent(
|
||||
planningState.getCurrentScenario(), task);
|
||||
|
||||
if (allocationResult.getAggregate().isEmpty()) {
|
||||
try {
|
||||
Messagebox.show(_("Some allocations needed"), _("Warning"),
|
||||
Messagebox.OK, Messagebox.EXCLAMATION);
|
||||
} catch (InterruptedException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
getSwitcher().goToAdvancedAllocation(allocationResult,
|
||||
createResultReceiver(allocationResult));
|
||||
}
|
||||
|
||||
|
||||
public ViewSwitcher getSwitcher() {
|
||||
return switcher;
|
||||
}
|
||||
|
||||
public void setSwitcher(ViewSwitcher switcher) {
|
||||
this.switcher = switcher;
|
||||
}
|
||||
|
||||
private IAdvanceAllocationResultReceiver createResultReceiver(
|
||||
final AllocationResult allocation) {
|
||||
return new AdvanceAllocationResultReceiver(allocation);
|
||||
}
|
||||
|
||||
private final class AdvanceAllocationResultReceiver implements
|
||||
IAdvanceAllocationResultReceiver {
|
||||
|
||||
private final AllocationResult allocation;
|
||||
private final IRestrictionSource restrictionSource;
|
||||
|
||||
private AdvanceAllocationResultReceiver(AllocationResult allocation) {
|
||||
Validate.isTrue(!allocation.getAggregate().isEmpty());
|
||||
this.allocation = allocation;
|
||||
final EffortDuration totalEffort = allocation.getAggregate()
|
||||
.getTotalEffort();
|
||||
final IntraDayDate start = allocation.getIntraDayStart();
|
||||
final IntraDayDate end = allocation.getIntraDayEnd();
|
||||
final CalculatedValue calculatedValue = allocation
|
||||
.getCalculatedValue();
|
||||
restrictionSource = new IRestrictionSource() {
|
||||
|
||||
@Override
|
||||
public EffortDuration getTotalEffort() {
|
||||
return totalEffort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getStart() {
|
||||
return start.getDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getEnd() {
|
||||
return end.asExclusiveEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatedValue getCalculatedValue() {
|
||||
return calculatedValue;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accepted(AggregateOfResourceAllocations aggregate) {
|
||||
allocation.applyTo(planningState.getCurrentScenario(),
|
||||
(Task) taskElement);
|
||||
askForReloads();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Restriction createRestriction() {
|
||||
return Restriction.build(restrictionSource);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void askForReloads() {
|
||||
if (context != null) {
|
||||
context.getTask().reloadResourcesText();
|
||||
context.reloadCharts();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -23,25 +23,14 @@ package org.navalplanner.web.planner.taskedition;
|
|||
|
||||
import static org.navalplanner.web.I18nHelper._;
|
||||
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.common.exceptions.ValidationException;
|
||||
import org.navalplanner.business.planner.entities.AggregateOfResourceAllocations;
|
||||
import org.navalplanner.business.planner.entities.CalculatedValue;
|
||||
import org.navalplanner.business.planner.entities.ITaskPositionConstrained;
|
||||
import org.navalplanner.business.planner.entities.Task;
|
||||
import org.navalplanner.business.planner.entities.TaskElement;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.business.workingday.IntraDayDate;
|
||||
import org.navalplanner.web.common.IMessagesForUser;
|
||||
import org.navalplanner.web.common.Level;
|
||||
import org.navalplanner.web.common.MessagesForUser;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.common.ViewSwitcher;
|
||||
import org.navalplanner.web.planner.allocation.AdvancedAllocationController.IAdvanceAllocationResultReceiver;
|
||||
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.ResourceAllocationController;
|
||||
import org.navalplanner.web.planner.limiting.allocation.LimitingResourceAllocationController;
|
||||
import org.navalplanner.web.planner.order.PlanningStateCreator.PlanningState;
|
||||
|
|
@ -105,8 +94,6 @@ public class EditTaskController extends GenericForwardComposer {
|
|||
|
||||
private PlanningState planningState;
|
||||
|
||||
private ViewSwitcher switcher;
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
|
|
@ -359,97 +346,6 @@ public class EditTaskController extends GenericForwardComposer {
|
|||
return (isTask(task) && !task.isSubcontracted());
|
||||
}
|
||||
|
||||
public void showAdvancedAllocation(Task task,
|
||||
IContextWithPlannerTask<TaskElement> context,
|
||||
PlanningState planningState) {
|
||||
this.taskElement = task;
|
||||
this.context = context;
|
||||
this.planningState = planningState;
|
||||
|
||||
AllocationResult allocationResult = AllocationResult.createCurrent(
|
||||
planningState.getCurrentScenario(), task);
|
||||
|
||||
if (allocationResult.getAggregate().isEmpty()) {
|
||||
getMessagesForUser().showMessage(Level.WARNING,
|
||||
_("Some allocations needed"));
|
||||
return;
|
||||
}
|
||||
|
||||
getSwitcher().goToAdvancedAllocation(allocationResult,
|
||||
createResultReceiver(allocationResult));
|
||||
window.setVisible(false);
|
||||
}
|
||||
|
||||
public ViewSwitcher getSwitcher() {
|
||||
return switcher;
|
||||
}
|
||||
|
||||
public void setSwitcher(ViewSwitcher switcher) {
|
||||
this.switcher = switcher;
|
||||
}
|
||||
|
||||
private IAdvanceAllocationResultReceiver createResultReceiver(
|
||||
final AllocationResult allocation) {
|
||||
return new AdvanceAllocationResultReceiver(allocation);
|
||||
}
|
||||
|
||||
private final class AdvanceAllocationResultReceiver implements
|
||||
IAdvanceAllocationResultReceiver {
|
||||
|
||||
private final AllocationResult allocation;
|
||||
private final IRestrictionSource restrictionSource;
|
||||
|
||||
private AdvanceAllocationResultReceiver(AllocationResult allocation) {
|
||||
Validate.isTrue(!allocation.getAggregate().isEmpty());
|
||||
this.allocation = allocation;
|
||||
final EffortDuration totalEffort = allocation.getAggregate()
|
||||
.getTotalEffort();
|
||||
final IntraDayDate start = allocation.getIntraDayStart();
|
||||
final IntraDayDate end = allocation.getIntraDayEnd();
|
||||
final CalculatedValue calculatedValue = allocation
|
||||
.getCalculatedValue();
|
||||
restrictionSource = new IRestrictionSource() {
|
||||
|
||||
@Override
|
||||
public EffortDuration getTotalEffort() {
|
||||
return totalEffort;
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getStart() {
|
||||
return start.getDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public LocalDate getEnd() {
|
||||
return end.asExclusiveEnd();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CalculatedValue getCalculatedValue() {
|
||||
return calculatedValue;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@Override
|
||||
public void cancel() {
|
||||
// Do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void accepted(AggregateOfResourceAllocations aggregate) {
|
||||
allocation.applyTo(planningState.getCurrentScenario(),
|
||||
(Task) taskElement);
|
||||
askForReloads();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Restriction createRestriction() {
|
||||
return Restriction.build(restrictionSource);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isTask() {
|
||||
return isTask(taskElement);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
switcher = planningController.viewSwitcher;
|
||||
|
||||
editController = planningController.editTaskController;
|
||||
editController.switcher = switcher;
|
||||
planningController.advancedAllocationTaskController.switcher = switcher;
|
||||
calendarController = planningController.calendarAllocationController;
|
||||
advanceController = planningController.advanceConsolidationController;
|
||||
advanceAssignmentController = planningController.advanceAssignmentPlanningController;
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue