ItEr27S06CUAsignacionGrupoRecursosAPlanificacionItEr26S07: Binding the CalculationType
This commit is contained in:
parent
1b44fdcce6
commit
e6b0b32e87
3 changed files with 57 additions and 6 deletions
|
|
@ -10,6 +10,7 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang.Validate;
|
||||
import org.navalplanner.business.planner.entities.CalculatedValue;
|
||||
import org.navalplanner.business.planner.entities.ResourceAllocation;
|
||||
import org.navalplanner.business.planner.entities.ResourcesPerDay;
|
||||
|
|
@ -39,6 +40,8 @@ import org.zkoss.zul.Listbox;
|
|||
import org.zkoss.zul.Listcell;
|
||||
import org.zkoss.zul.Listitem;
|
||||
import org.zkoss.zul.ListitemRenderer;
|
||||
import org.zkoss.zul.Radio;
|
||||
import org.zkoss.zul.Radiogroup;
|
||||
import org.zkoss.zul.SimpleConstraint;
|
||||
import org.zkoss.zul.api.Window;
|
||||
|
||||
|
|
@ -69,6 +72,7 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
|
||||
private Intbox assignedHoursComponent;
|
||||
|
||||
private Radiogroup calculationTypeSelector;
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
|
|
@ -90,6 +94,9 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
planningState);
|
||||
formBinder = allocationsBeingEdited.createFormBinder();
|
||||
formBinder.setAssignedHoursComponent(assignedHoursComponent);
|
||||
CalculationTypeRadio calculationTypeRadio = CalculationTypeRadio
|
||||
.from(formBinder.getCalculatedValue());
|
||||
calculationTypeRadio.doTheSelectionOn(calculationTypeSelector);
|
||||
Util.reloadBindings(window);
|
||||
try {
|
||||
window.doModal();
|
||||
|
|
@ -164,6 +171,29 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
return _("Calculate Resources per Day");
|
||||
}
|
||||
};
|
||||
|
||||
public static CalculationTypeRadio from(CalculatedValue calculatedValue) {
|
||||
Validate.notNull(calculatedValue);
|
||||
for (CalculationTypeRadio calculationTypeRadio : CalculationTypeRadio.values()) {
|
||||
if (calculationTypeRadio.getCalculatedValue() == calculatedValue) {
|
||||
return calculationTypeRadio;
|
||||
}
|
||||
}
|
||||
throw new RuntimeException("not found "
|
||||
+ CalculationTypeRadio.class.getSimpleName() + " for "
|
||||
+ calculatedValue);
|
||||
}
|
||||
|
||||
public void doTheSelectionOn(Radiogroup radiogroup) {
|
||||
for (int i = 0; i < radiogroup.getItemCount(); i++) {
|
||||
Radio radio = radiogroup.getItemAtIndex(i);
|
||||
if (name().equals(radio.getValue())) {
|
||||
radiogroup.setSelectedIndex(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private final CalculatedValue calculatedValue;
|
||||
|
||||
private CalculationTypeRadio(CalculatedValue calculatedValue) {
|
||||
|
|
@ -185,7 +215,7 @@ public class ResourceAllocationController extends GenericForwardComposer {
|
|||
public void setCalculationTypeSelected(String enumName) {
|
||||
CalculationTypeRadio calculationTypeRadio = CalculationTypeRadio
|
||||
.valueOf(enumName);
|
||||
CalculatedValue c = calculationTypeRadio.getCalculatedValue();
|
||||
formBinder.setCalculatedValue(calculationTypeRadio.getCalculatedValue());
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import org.zkoss.zul.Intbox;
|
|||
public class ResourceAllocationFormBinder {
|
||||
|
||||
private Intbox assignedHoursComponent;
|
||||
|
||||
private final ResourceAllocationsBeingEdited resourceAllocationsBeingEdited;
|
||||
private AggregateOfResourceAllocations aggregate;
|
||||
|
||||
|
|
@ -24,4 +25,16 @@ public class ResourceAllocationFormBinder {
|
|||
this.assignedHoursComponent.setValue(aggregate.getTotalHours());
|
||||
}
|
||||
|
||||
public void setCalculatedValue(CalculatedValue calculatedValue) {
|
||||
if (calculatedValue == resourceAllocationsBeingEdited
|
||||
.getCalculatedValue()) {
|
||||
return;
|
||||
}
|
||||
resourceAllocationsBeingEdited.setCalculatedValue(calculatedValue);
|
||||
}
|
||||
|
||||
public CalculatedValue getCalculatedValue() {
|
||||
return resourceAllocationsBeingEdited.getCalculatedValue();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,6 +38,8 @@ public class ResourceAllocationsBeingEdited {
|
|||
|
||||
private ResourceAllocationFormBinder formBinder = null;
|
||||
|
||||
private CalculatedValue calculatedValue;
|
||||
|
||||
private ResourceAllocationsBeingEdited(Task task,
|
||||
List<AllocationDTO> initialAllocations, IResourceDAO resourceDAO,
|
||||
boolean modifyTask) {
|
||||
|
|
@ -46,6 +48,12 @@ public class ResourceAllocationsBeingEdited {
|
|||
this.modifyTask = modifyTask;
|
||||
this.currentAllocations = new ArrayList<AllocationDTO>(
|
||||
initialAllocations);
|
||||
this.calculatedValue = getCurrentCalculatedValue(task);
|
||||
}
|
||||
|
||||
private CalculatedValue getCurrentCalculatedValue(Task task) {
|
||||
return task.isFixedDuration() ? CalculatedValue.NUMBER_OF_HOURS
|
||||
: CalculatedValue.END_DATE;
|
||||
}
|
||||
|
||||
public void addSpecificResorceAllocationFor(Worker worker) {
|
||||
|
|
@ -157,17 +165,17 @@ public class ResourceAllocationsBeingEdited {
|
|||
return formBinder;
|
||||
}
|
||||
|
||||
private CalculatedValue getCurrentCalculatedValue(Task task) {
|
||||
// TODO retrieve the calculated value from task
|
||||
return CalculatedValue.NUMBER_OF_HOURS;
|
||||
public CalculatedValue getCalculatedValue() {
|
||||
return this.calculatedValue;
|
||||
}
|
||||
|
||||
public CalculatedValue getCalculatedValue() {
|
||||
return getCurrentCalculatedValue(task);
|
||||
public void setCalculatedValue(CalculatedValue calculatedValue) {
|
||||
this.calculatedValue = calculatedValue;
|
||||
}
|
||||
|
||||
public AggregateOfResourceAllocations getInitialAggregate() {
|
||||
return new AggregateOfResourceAllocations(task.getResourceAllocations());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue