Move taskWorkableDays handling code to FormBinder
This is a refactoring. It does not change the observable behaviour. FEA: ItEr61OTS04PlanificacionHaciaAtras
This commit is contained in:
parent
2aa82bf9cf
commit
9f92c8a39e
3 changed files with 54 additions and 53 deletions
|
|
@ -32,11 +32,13 @@ import java.util.List;
|
|||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.joda.time.format.DateTimeFormat;
|
||||
import org.joda.time.format.DateTimeFormatter;
|
||||
import org.joda.time.format.ISODateTimeFormat;
|
||||
import org.navalplanner.business.common.ProportionalDistributor;
|
||||
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.resources.entities.Criterion;
|
||||
import org.navalplanner.business.resources.entities.Resource;
|
||||
import org.navalplanner.business.resources.entities.ResourceEnum;
|
||||
|
|
@ -47,6 +49,7 @@ import org.navalplanner.web.common.Level;
|
|||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.common.components.NewAllocationSelectorCombo;
|
||||
import org.navalplanner.web.planner.allocation.IResourceAllocationModel.IResourceAllocationContext;
|
||||
import org.navalplanner.web.planner.taskedition.TaskPropertiesController;
|
||||
import org.zkoss.util.Locales;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.WrongValueException;
|
||||
|
|
@ -287,12 +290,52 @@ public class FormBinder {
|
|||
this.taskStartDate = startDate;
|
||||
}
|
||||
|
||||
public void setWorkableDays(Intbox duration) {
|
||||
public void setWorkableDays(Intbox duration,
|
||||
final TaskPropertiesController taskPropertiesController,
|
||||
final Label labelTaskStart, final Label labelTaskEnd) {
|
||||
|
||||
Task task = allocationRowsHandler.getTask();
|
||||
showValueOfDateOn(labelTaskStart, task.getStartAsLocalDate());
|
||||
showValueOfDateOn(labelTaskEnd, task.getEndAsLocalDate());
|
||||
|
||||
this.taskWorkableDays = duration;
|
||||
taskWorkableDays.setValue(task.getWorkableDays());
|
||||
taskWorkableDays.addEventListener(Events.ON_CHANGE,
|
||||
new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
Date newEndDate = calculateEndDate(taskWorkableDays
|
||||
.getValue());
|
||||
taskPropertiesController.updateTaskEndDate(newEndDate);
|
||||
showValueOfDateOn(labelTaskEnd,
|
||||
LocalDate.fromDateFields(newEndDate));
|
||||
}
|
||||
});
|
||||
taskDurationDisabilityRule();
|
||||
onChangeEnableApply(taskWorkableDays);
|
||||
}
|
||||
|
||||
private void showValueOfDateOn(final Label label, LocalDate date) {
|
||||
DateTimeFormatter formatter = DateTimeFormat.forStyle("S-").withLocale(
|
||||
Locales.getCurrent());
|
||||
label.setValue(formatter.print(date));
|
||||
}
|
||||
|
||||
private Date calculateEndDate(int duration) {
|
||||
LocalDate result = new LocalDate(getPlannedTaskStart());
|
||||
result = result.plusDays(duration);
|
||||
return toDate(result);
|
||||
}
|
||||
|
||||
private Date toDate(LocalDate date) {
|
||||
return date.toDateTimeAtStartOfDay().toDate();
|
||||
}
|
||||
|
||||
public Date getPlannedTaskStart() {
|
||||
return resourceAllocationModel.getTaskStart();
|
||||
}
|
||||
|
||||
public void setAllResourcesPerDay(Decimalbox allResourcesPerDay) {
|
||||
this.allResourcesPerDay = allResourcesPerDay;
|
||||
this.allResourcesPerDay.setConstraint(new SimpleConstraint(
|
||||
|
|
|
|||
|
|
@ -31,7 +31,6 @@ import java.util.List;
|
|||
import org.apache.commons.lang.Validate;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.joda.time.LocalDate;
|
||||
import org.navalplanner.business.orders.entities.AggregatedHoursGroup;
|
||||
import org.navalplanner.business.planner.entities.CalculatedValue;
|
||||
import org.navalplanner.business.planner.entities.DerivedAllocation;
|
||||
|
|
@ -46,6 +45,7 @@ import org.navalplanner.web.common.components.NewAllocationSelector;
|
|||
import org.navalplanner.web.common.components.NewAllocationSelectorCombo;
|
||||
import org.navalplanner.web.planner.order.PlanningState;
|
||||
import org.navalplanner.web.planner.taskedition.EditTaskController;
|
||||
import org.navalplanner.web.planner.taskedition.TaskPropertiesController;
|
||||
import org.springframework.beans.factory.config.BeanDefinition;
|
||||
import org.springframework.context.annotation.Scope;
|
||||
import org.zkoss.ganttz.extensions.IContextWithPlannerTask;
|
||||
|
|
@ -58,7 +58,6 @@ import org.zkoss.zk.ui.Component;
|
|||
import org.zkoss.zk.ui.WrongValueException;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.Events;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Button;
|
||||
import org.zkoss.zul.Checkbox;
|
||||
|
|
@ -115,9 +114,6 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
|
||||
private Intbox taskWorkableDays;
|
||||
|
||||
// Orientative task end according to number of workable days
|
||||
private Date plannedTaskEnd;
|
||||
|
||||
private Decimalbox allResourcesPerDay;
|
||||
|
||||
private Label allOriginalHours;
|
||||
|
|
@ -225,7 +221,6 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
}
|
||||
allocationRows = resourceAllocationModel.initAllocationsFor(task,
|
||||
context, planningState);
|
||||
initTaskWorkableDays(task);
|
||||
|
||||
formBinder = allocationRows.createFormBinder(planningState
|
||||
.getCurrentScenario(), resourceAllocationModel);
|
||||
|
|
@ -239,7 +234,11 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
.setAllConsolidatedResourcesPerDay(allConsolidatedResourcesPerDay);
|
||||
formBinder.setAllResourcesPerDay(allResourcesPerDay);
|
||||
|
||||
formBinder.setWorkableDays(taskWorkableDays);
|
||||
TaskPropertiesController taskPropertiesController = editTaskController
|
||||
.getTaskPropertiesController();
|
||||
formBinder.setWorkableDays(taskWorkableDays,
|
||||
taskPropertiesController, lbTaskStart, lbTaskEnd);
|
||||
|
||||
formBinder.setApplyButton(applyButton);
|
||||
formBinder.setAllocationsGrid(allocationsGrid);
|
||||
formBinder.setMessagesForUser(messagesForUser);
|
||||
|
|
@ -265,51 +264,10 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
}
|
||||
}
|
||||
|
||||
private Label lbTaskStart;
|
||||
|
||||
private Label lbTaskEnd;
|
||||
|
||||
private void initTaskWorkableDays(org.navalplanner.business.planner.entities.Task task) {
|
||||
taskWorkableDays.setValue(task.getWorkableDays());
|
||||
plannedTaskEnd = resourceAllocationModel.getTaskEnd();
|
||||
taskWorkableDays.addEventListener(Events.ON_CHANGE,
|
||||
new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
setPlannedTaskEnd(calculateEndDate(taskWorkableDays
|
||||
.getValue()));
|
||||
updateTaskEndDateInTaskPropertiesPanel(getPlannedTaskEnd());
|
||||
Util.reloadBindings(lbTaskEnd);
|
||||
}
|
||||
|
||||
private void updateTaskEndDateInTaskPropertiesPanel(Date endDate) {
|
||||
editTaskController.getTaskPropertiesController().updateTaskEndDate(endDate);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private Date calculateEndDate(int duration) {
|
||||
LocalDate result = new LocalDate(getPlannedTaskStart());
|
||||
result = result.plusDays(duration);
|
||||
return toDate(result);
|
||||
}
|
||||
|
||||
private Date toDate(LocalDate date) {
|
||||
return date.toDateTimeAtStartOfDay().toDate();
|
||||
}
|
||||
|
||||
public Date getPlannedTaskStart() {
|
||||
return resourceAllocationModel.getTaskStart();
|
||||
}
|
||||
|
||||
public Date getPlannedTaskEnd() {
|
||||
return plannedTaskEnd;
|
||||
}
|
||||
|
||||
private void setPlannedTaskEnd(Date taskEnd) {
|
||||
this.plannedTaskEnd = taskEnd;
|
||||
}
|
||||
|
||||
public enum HoursRendererColumn {
|
||||
|
||||
CRITERIONS {
|
||||
|
|
|
|||
|
|
@ -74,11 +74,11 @@
|
|||
<hbox>
|
||||
<!-- Planned Task Start -->
|
||||
<label style="font-weight: bold" value="${i18n:_('Planned start :')}" />
|
||||
<label value="@{allocationController.plannedTaskStart,converter='org.navalplanner.web.common.typeconverters.DateConverter'}" />
|
||||
<label id="lbTaskStart" />
|
||||
|
||||
<!-- Planned Task End -->
|
||||
<label style="font-weight: bold" value="${i18n:_('Planned end :')}" />
|
||||
<label id="lbTaskEnd" value="@{allocationController.plannedTaskEnd,converter='org.navalplanner.web.common.typeconverters.DateConverter'}" />
|
||||
<label id="lbTaskEnd" />
|
||||
|
||||
</hbox>
|
||||
<!-- Planned Workable Days -->
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue