ItEr14S11CUConfiguracionDeOrganizacionsDeTraballoConUnidadesTraballoItEr13S13: Extracting bind methods to the utilities class.
This commit is contained in:
parent
657afd9c24
commit
9652efb04d
2 changed files with 197 additions and 80 deletions
|
|
@ -1,11 +1,21 @@
|
|||
package org.navalplanner.web.common;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.InputEvent;
|
||||
import org.zkoss.zkplus.databind.DataBinder;
|
||||
import org.zkoss.zul.Datebox;
|
||||
import org.zkoss.zul.Intbox;
|
||||
import org.zkoss.zul.Textbox;
|
||||
|
||||
/**
|
||||
* Utilities class. <br />
|
||||
*
|
||||
* @author Óscar González Fernández <ogonzalez@igalia.com>
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*/
|
||||
public class Util {
|
||||
|
||||
|
|
@ -22,4 +32,176 @@ public class Util {
|
|||
return (DataBinder) component.getVariable("binder", false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic interface to represent a class with a typical get method.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the variable to be returned.
|
||||
*/
|
||||
public static interface Getter<T> {
|
||||
/**
|
||||
* Typical get method that returns a variable.
|
||||
*
|
||||
* @return A variable of type <T>.
|
||||
*/
|
||||
public T get();
|
||||
}
|
||||
|
||||
/**
|
||||
* Generic interface to represent a class with a typical set method.
|
||||
*
|
||||
* @author Manuel Rego Casasnovas <mrego@igalia.com>
|
||||
*
|
||||
* @param <T>
|
||||
* The type of the variable to be set.
|
||||
*/
|
||||
public static interface Setter<T> {
|
||||
/**
|
||||
* Typical set method to store a variable.
|
||||
*
|
||||
* @param value
|
||||
* A variable of type <T> to be set.
|
||||
*/
|
||||
public void set(T value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a {@link Textbox} with a {@link Getter}. The {@link Getter} will be
|
||||
* used to get the value that is going to be showed in the {@link Textbox}.
|
||||
*
|
||||
* @param textBox
|
||||
* The {@link Textbox} to be bound
|
||||
* @param getter
|
||||
* The {@link Getter} interface that will implement a get method.
|
||||
* @return The {@link Textbox} bound
|
||||
*/
|
||||
public static Textbox bind(Textbox textBox, Getter<String> getter) {
|
||||
textBox.setValue(getter.get());
|
||||
textBox.setDisabled(true);
|
||||
return textBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a {@link Textbox} with a {@link Getter}. The {@link Getter} will be
|
||||
* used to get the value that is going to be showed in the {@link Textbox}.
|
||||
* The {@link Setter} will be used to store the value inserted by the user
|
||||
* in the {@link Textbox}.
|
||||
*
|
||||
* @param textBox
|
||||
* The {@link Textbox} to be bound
|
||||
* @param getter
|
||||
* The {@link Getter} interface that will implement a get method.
|
||||
* @param setter
|
||||
* The {@link Setter} interface that will implement a set method.
|
||||
* @return The {@link Textbox} bound
|
||||
*/
|
||||
public static Textbox bind(final Textbox textBox,
|
||||
final Getter<String> getter, final Setter<String> setter) {
|
||||
textBox.setValue(getter.get());
|
||||
textBox.addEventListener("onChange", new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
InputEvent newInput = (InputEvent) event;
|
||||
String value = newInput.getValue();
|
||||
setter.set(value);
|
||||
textBox.setValue(getter.get());
|
||||
}
|
||||
});
|
||||
return textBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a {@link Intbox} with a {@link Getter}. The {@link Getter} will be
|
||||
* used to get the value that is going to be showed in the {@link Intbox}.
|
||||
*
|
||||
* @param intBox
|
||||
* The {@link Intbox} to be bound
|
||||
* @param getter
|
||||
* The {@link Getter} interface that will implement a get method.
|
||||
* @return The {@link Intbox} bound
|
||||
*/
|
||||
public static Intbox bind(Intbox intBox, Getter<Integer> getter) {
|
||||
intBox.setValue(getter.get());
|
||||
intBox.setDisabled(true);
|
||||
return intBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a {@link Intbox} with a {@link Getter}. The {@link Getter} will be
|
||||
* used to get the value that is going to be showed in the {@link Intbox}.
|
||||
* The {@link Setter} will be used to store the value inserted by the user
|
||||
* in the {@link Intbox}.
|
||||
*
|
||||
* @param intBox
|
||||
* The {@link Intbox} to be bound
|
||||
* @param getter
|
||||
* The {@link Getter} interface that will implement a get method.
|
||||
* @param setter
|
||||
* The {@link Setter} interface that will implement a set method.
|
||||
* @return The {@link Intbox} bound
|
||||
*/
|
||||
public static Intbox bind(final Intbox intBox,
|
||||
final Getter<Integer> getter, final Setter<Integer> setter) {
|
||||
intBox.setValue(getter.get());
|
||||
intBox.addEventListener("onChange", new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
InputEvent newInput = (InputEvent) event;
|
||||
String value = newInput.getValue();
|
||||
setter.set(Integer.valueOf(value));
|
||||
intBox.setValue(getter.get());
|
||||
}
|
||||
});
|
||||
return intBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a {@link Datebox} with a {@link Getter}. The {@link Getter} will be
|
||||
* used to get the value that is going to be showed in the {@link Datebox}.
|
||||
*
|
||||
* @param dateBox
|
||||
* The {@link Datebox} to be bound
|
||||
* @param getter
|
||||
* The {@link Getter} interface that will implement a get method.
|
||||
* @return The {@link Datebox} bound
|
||||
*/
|
||||
public static Datebox bind(final Datebox dateBox,
|
||||
final Getter<Date> getter) {
|
||||
dateBox.setValue(getter.get());
|
||||
dateBox.setDisabled(true);
|
||||
return dateBox;
|
||||
}
|
||||
|
||||
/**
|
||||
* Binds a {@link Datebox} with a {@link Getter}. The {@link Getter} will be
|
||||
* used to get the value that is going to be showed in the {@link Datebox}.
|
||||
* The {@link Setter} will be used to store the value inserted by the user
|
||||
* in the {@link Datebox}.
|
||||
*
|
||||
* @param dateBox
|
||||
* The {@link Datebox} to be bound
|
||||
* @param getter
|
||||
* The {@link Getter} interface that will implement a get method.
|
||||
* @param setter
|
||||
* The {@link Setter} interface that will implement a set method.
|
||||
* @return The {@link Datebox} bound
|
||||
*/
|
||||
public static Datebox bind(final Datebox dateBox,
|
||||
final Getter<Date> getter, final Setter<Date> setter) {
|
||||
dateBox.setValue(getter.get());
|
||||
dateBox.addEventListener("onChange", new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
setter.set(dateBox.getValue());
|
||||
dateBox.setValue(getter.get());
|
||||
}
|
||||
});
|
||||
return dateBox;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -14,9 +14,7 @@ import org.navalplanner.business.workorders.entities.TaskWorkLeaf;
|
|||
import org.navalplanner.web.common.Util;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.event.DropEvent;
|
||||
import org.zkoss.zk.ui.event.Event;
|
||||
import org.zkoss.zk.ui.event.EventListener;
|
||||
import org.zkoss.zk.ui.event.InputEvent;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
import org.zkoss.zul.Datebox;
|
||||
import org.zkoss.zul.Intbox;
|
||||
|
|
@ -175,72 +173,6 @@ public class TaskWorksTreeController extends GenericForwardComposer {
|
|||
comp.setVariable("tasksTreeController", this, true);
|
||||
}
|
||||
|
||||
private static interface Getter<T> {
|
||||
public T get();
|
||||
}
|
||||
|
||||
private static interface Setter<T> {
|
||||
public void set(T value);
|
||||
}
|
||||
|
||||
private static Textbox bind(Textbox textBox, Getter<String> getter) {
|
||||
textBox.setValue(getter.get());
|
||||
textBox.setDisabled(true);
|
||||
return textBox;
|
||||
}
|
||||
|
||||
private static Textbox bind(final Textbox textBox,
|
||||
final Getter<String> getter, final Setter<String> setter) {
|
||||
textBox.setValue(getter.get());
|
||||
textBox.addEventListener("onChange", new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
InputEvent newInput = (InputEvent) event;
|
||||
String value = newInput.getValue();
|
||||
setter.set(value);
|
||||
textBox.setValue(getter.get());
|
||||
}
|
||||
});
|
||||
return textBox;
|
||||
}
|
||||
|
||||
private static Intbox bind(Intbox intBox, Getter<Integer> getter) {
|
||||
intBox.setValue(getter.get());
|
||||
intBox.setDisabled(true);
|
||||
return intBox;
|
||||
}
|
||||
|
||||
private static Intbox bind(final Intbox intBox,
|
||||
final Getter<Integer> getter, final Setter<Integer> setter) {
|
||||
intBox.setValue(getter.get());
|
||||
intBox.addEventListener("onChange", new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
InputEvent newInput = (InputEvent) event;
|
||||
String value = newInput.getValue();
|
||||
setter.set(Integer.valueOf(value));
|
||||
intBox.setValue(getter.get());
|
||||
}
|
||||
});
|
||||
return intBox;
|
||||
}
|
||||
|
||||
private static Datebox bind(final Datebox dateBox,
|
||||
final Getter<Date> getter, final Setter<Date> setter) {
|
||||
dateBox.setValue(getter.get());
|
||||
dateBox.addEventListener("onChange", new EventListener() {
|
||||
|
||||
@Override
|
||||
public void onEvent(Event event) throws Exception {
|
||||
setter.set(dateBox.getValue());
|
||||
dateBox.setValue(getter.get());
|
||||
}
|
||||
});
|
||||
return dateBox;
|
||||
}
|
||||
|
||||
public class TaskWorkTreeitemRenderer implements TreeitemRenderer {
|
||||
|
||||
private Map<SimpleTreeNode, Intbox> map = new HashMap<SimpleTreeNode, Intbox>();
|
||||
|
|
@ -259,13 +191,14 @@ public class TaskWorksTreeController extends GenericForwardComposer {
|
|||
// Contruct treecells
|
||||
int[] path = getTasksTreeModel().getPath(t);
|
||||
Treecell cellForName = new Treecell(pathAsString(path));
|
||||
cellForName.appendChild(bind(new Textbox(), new Getter<String>() {
|
||||
cellForName.appendChild(Util.bind(new Textbox(),
|
||||
new Util.Getter<String>() {
|
||||
|
||||
@Override
|
||||
public String get() {
|
||||
return taskWork.getName();
|
||||
}
|
||||
}, new Setter<String>() {
|
||||
}, new Util.Setter<String>() {
|
||||
|
||||
@Override
|
||||
public void set(String value) {
|
||||
|
|
@ -277,14 +210,14 @@ public class TaskWorksTreeController extends GenericForwardComposer {
|
|||
map.put(t, intboxHours);
|
||||
if (taskWork instanceof TaskWorkLeaf) {
|
||||
// If it's a leaf hours cell is editable
|
||||
cellForHours.appendChild(bind(intboxHours,
|
||||
new Getter<Integer>() {
|
||||
cellForHours.appendChild(Util.bind(intboxHours,
|
||||
new Util.Getter<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer get() {
|
||||
return taskWork.getWorkHours();
|
||||
}
|
||||
}, new Setter<Integer>() {
|
||||
}, new Util.Setter<Integer>() {
|
||||
|
||||
@Override
|
||||
public void set(Integer value) {
|
||||
|
|
@ -307,8 +240,8 @@ public class TaskWorksTreeController extends GenericForwardComposer {
|
|||
}));
|
||||
} else {
|
||||
// If it's a container hours cell is not editable
|
||||
cellForHours.appendChild(bind(intboxHours,
|
||||
new Getter<Integer>() {
|
||||
cellForHours.appendChild(Util.bind(intboxHours,
|
||||
new Util.Getter<Integer>() {
|
||||
|
||||
@Override
|
||||
public Integer get() {
|
||||
|
|
@ -317,13 +250,14 @@ public class TaskWorksTreeController extends GenericForwardComposer {
|
|||
}));
|
||||
}
|
||||
Treecell tcDateStart = new Treecell();
|
||||
tcDateStart.appendChild(bind(new Datebox(), new Getter<Date>() {
|
||||
tcDateStart.appendChild(Util.bind(new Datebox(),
|
||||
new Util.Getter<Date>() {
|
||||
|
||||
@Override
|
||||
public Date get() {
|
||||
return taskWork.getInitDate();
|
||||
}
|
||||
}, new Setter<Date>() {
|
||||
}, new Util.Setter<Date>() {
|
||||
|
||||
@Override
|
||||
public void set(Date value) {
|
||||
|
|
@ -331,13 +265,14 @@ public class TaskWorksTreeController extends GenericForwardComposer {
|
|||
}
|
||||
}));
|
||||
Treecell tcDateEnd = new Treecell();
|
||||
tcDateEnd.appendChild(bind(new Datebox(), new Getter<Date>() {
|
||||
tcDateEnd.appendChild(Util.bind(new Datebox(),
|
||||
new Util.Getter<Date>() {
|
||||
|
||||
@Override
|
||||
public Date get() {
|
||||
return taskWork.getEndDate();
|
||||
}
|
||||
}, new Setter<Date>() {
|
||||
}, new Util.Setter<Date>() {
|
||||
|
||||
@Override
|
||||
public void set(Date value) {
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue