diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/Util.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/Util.java
index 6c238e301..c3d2a4e57 100644
--- a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/Util.java
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/Util.java
@@ -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.
@@ -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 bind(final C checkBox,
final Getter getter, final Setter setter) {
checkBox.setChecked(getter.get());
checkBox.addEventListener(Events.ON_CHECK, new EventListener() {
diff --git a/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/CapacityPicker.java b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/CapacityPicker.java
new file mode 100644
index 000000000..a65b31c28
--- /dev/null
+++ b/navalplanner-webapp/src/main/java/org/navalplanner/web/common/components/CapacityPicker.java
@@ -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 .
+ */
+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
+ */
+public class CapacityPicker {
+
+ public static CapacityPicker workWith(Checkbox checkbox,
+ EffortDurationPicker standardEffortPicker,
+ EffortDurationPicker extraHoursPicker,
+ final Getter getter,
+ Setter setter) {
+ return new CapacityPicker(checkbox, standardEffortPicker,
+ extraHoursPicker, getter.get(), setter);
+ }
+
+ private Capacity currentCapacity;
+
+ private final Setter setter;
+
+ private CapacityPicker(Checkbox checkbox,
+ EffortDurationPicker standardEffortPicker,
+ final EffortDurationPicker extraEffortPicker,
+ Capacity initialCapacity,
+ Setter setter) {
+ this.currentCapacity = initialCapacity;
+ this.setter = setter;
+ standardEffortPicker.bind(new Getter() {
+
+ @Override
+ public EffortDuration get() {
+ return currentCapacity.getStandardEffort();
+ }
+ }, new Setter() {
+
+ @Override
+ public void set(EffortDuration value) {
+ updateCapacity(currentCapacity.withNormalDuration(value));
+ }
+ });
+ extraEffortPicker.bind(new Getter() {
+
+ @Override
+ public EffortDuration get() {
+ if (currentCapacity.getAllowedExtraEffort() == null) {
+ return EffortDuration.zero();
+ }
+ return currentCapacity.getAllowedExtraEffort();
+ }
+ }, new Setter() {
+
+ @Override
+ public void set(EffortDuration value) {
+ updateCapacity(currentCapacity.extraEffort(value));
+ }
+ });
+ Util.bind(checkbox, new Getter() {
+
+ @Override
+ public Boolean get() {
+ return currentCapacity.isOverAssignable();
+ }
+ }, new Setter() {
+
+ @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);
+ }
+
+}