Create picker for Capacity
FEA: ItEr68OTS05IntroducionLimiteSobreasignacionCalendarios
This commit is contained in:
parent
24323893ba
commit
a50d08ae33
2 changed files with 116 additions and 2 deletions
|
|
@ -36,7 +36,6 @@ import org.zkoss.zkplus.databind.AnnotateDataBinder;
|
|||
import org.zkoss.zkplus.databind.DataBinder;
|
||||
import org.zkoss.zul.Bandbox;
|
||||
import org.zkoss.zul.Button;
|
||||
import org.zkoss.zul.Checkbox;
|
||||
import org.zkoss.zul.Combobox;
|
||||
import org.zkoss.zul.Comboitem;
|
||||
import org.zkoss.zul.Datebox;
|
||||
|
|
@ -45,6 +44,7 @@ import org.zkoss.zul.Intbox;
|
|||
import org.zkoss.zul.Radio;
|
||||
import org.zkoss.zul.Textbox;
|
||||
import org.zkoss.zul.Timebox;
|
||||
import org.zkoss.zul.api.Checkbox;
|
||||
|
||||
/**
|
||||
* Utilities class. <br />
|
||||
|
|
@ -414,7 +414,7 @@ public class Util {
|
|||
* The {@link Setter} interface that will implement a set method.
|
||||
* @return The {@link Checkbox} bound
|
||||
*/
|
||||
public static Checkbox bind(final Checkbox checkBox,
|
||||
public static <C extends Checkbox> C bind(final C checkBox,
|
||||
final Getter<Boolean> getter, final Setter<Boolean> setter) {
|
||||
checkBox.setChecked(getter.get());
|
||||
checkBox.addEventListener(Events.ON_CHECK, new EventListener() {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,114 @@
|
|||
/*
|
||||
* 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.common.components;
|
||||
|
||||
import org.apache.commons.lang.BooleanUtils;
|
||||
import org.navalplanner.business.calendars.entities.Capacity;
|
||||
import org.navalplanner.business.workingday.EffortDuration;
|
||||
import org.navalplanner.web.common.Util;
|
||||
import org.navalplanner.web.common.Util.Getter;
|
||||
import org.navalplanner.web.common.Util.Setter;
|
||||
import org.zkoss.zul.api.Checkbox;
|
||||
|
||||
/**
|
||||
* It configures some ZK components to work together and edit a Capacity object
|
||||
*
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
*/
|
||||
public class CapacityPicker {
|
||||
|
||||
public static CapacityPicker workWith(Checkbox checkbox,
|
||||
EffortDurationPicker standardEffortPicker,
|
||||
EffortDurationPicker extraHoursPicker,
|
||||
final Getter<Capacity> getter,
|
||||
Setter<Capacity> setter) {
|
||||
return new CapacityPicker(checkbox, standardEffortPicker,
|
||||
extraHoursPicker, getter.get(), setter);
|
||||
}
|
||||
|
||||
private Capacity currentCapacity;
|
||||
|
||||
private final Setter<Capacity> setter;
|
||||
|
||||
private CapacityPicker(Checkbox checkbox,
|
||||
EffortDurationPicker standardEffortPicker,
|
||||
final EffortDurationPicker extraEffortPicker,
|
||||
Capacity initialCapacity,
|
||||
Setter<Capacity> setter) {
|
||||
this.currentCapacity = initialCapacity;
|
||||
this.setter = setter;
|
||||
standardEffortPicker.bind(new Getter<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration get() {
|
||||
return currentCapacity.getStandardEffort();
|
||||
}
|
||||
}, new Setter<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public void set(EffortDuration value) {
|
||||
updateCapacity(currentCapacity.withNormalDuration(value));
|
||||
}
|
||||
});
|
||||
extraEffortPicker.bind(new Getter<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public EffortDuration get() {
|
||||
if (currentCapacity.getAllowedExtraEffort() == null) {
|
||||
return EffortDuration.zero();
|
||||
}
|
||||
return currentCapacity.getAllowedExtraEffort();
|
||||
}
|
||||
}, new Setter<EffortDuration>() {
|
||||
|
||||
@Override
|
||||
public void set(EffortDuration value) {
|
||||
updateCapacity(currentCapacity.extraEffort(value));
|
||||
}
|
||||
});
|
||||
Util.bind(checkbox, new Getter<Boolean>() {
|
||||
|
||||
@Override
|
||||
public Boolean get() {
|
||||
return currentCapacity.isOverAssignable();
|
||||
}
|
||||
}, new Setter<Boolean>() {
|
||||
|
||||
@Override
|
||||
public void set(Boolean value) {
|
||||
updateCapacity(currentCapacity.overAssignable(BooleanUtils
|
||||
.isTrue(value)));
|
||||
updateExtraEffortDisability(extraEffortPicker);
|
||||
}
|
||||
});
|
||||
updateExtraEffortDisability(extraEffortPicker);
|
||||
|
||||
}
|
||||
|
||||
private void updateExtraEffortDisability(
|
||||
EffortDurationPicker extraHoursPicker) {
|
||||
extraHoursPicker.setDisabled(currentCapacity.isOverAssignable());
|
||||
}
|
||||
|
||||
private void updateCapacity(Capacity newCapacity) {
|
||||
this.currentCapacity = newCapacity;
|
||||
this.setter.set(currentCapacity);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue