2009-04-14 17:51:03 +02:00
|
|
|
package org.zkoss.ganttz;
|
|
|
|
|
|
|
|
|
|
import java.beans.PropertyChangeEvent;
|
|
|
|
|
import java.beans.PropertyChangeListener;
|
|
|
|
|
import java.text.DateFormat;
|
|
|
|
|
import java.text.SimpleDateFormat;
|
|
|
|
|
import java.util.Date;
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.logging.Log;
|
|
|
|
|
import org.apache.commons.logging.LogFactory;
|
2009-04-27 15:57:33 +02:00
|
|
|
import org.zkoss.ganttz.util.TaskBean;
|
2009-04-14 17:51:03 +02:00
|
|
|
import org.zkoss.zk.ui.HtmlMacroComponent;
|
|
|
|
|
import org.zkoss.zk.ui.ext.AfterCompose;
|
|
|
|
|
import org.zkoss.zul.Datebox;
|
|
|
|
|
import org.zkoss.zul.Textbox;
|
|
|
|
|
|
|
|
|
|
public class TaskDetail extends HtmlMacroComponent implements AfterCompose {
|
|
|
|
|
|
|
|
|
|
static String format(Date date) {
|
|
|
|
|
return dateFormat.format(date);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
|
|
|
|
|
|
|
|
|
|
private static final Log LOG = LogFactory.getLog(TaskDetail.class);
|
|
|
|
|
|
2009-06-15 21:48:54 +02:00
|
|
|
private final TaskBean taskBean;
|
2009-04-14 17:51:03 +02:00
|
|
|
|
|
|
|
|
public TaskBean getTaskBean() {
|
|
|
|
|
return taskBean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Textbox nameBox;
|
|
|
|
|
|
|
|
|
|
public Textbox getNameBox() {
|
|
|
|
|
return nameBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setNameBox(Textbox nameBox) {
|
|
|
|
|
this.nameBox = nameBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Datebox getStartDateBox() {
|
|
|
|
|
return startDateBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setStartDateBox(Datebox startDateBox) {
|
|
|
|
|
this.startDateBox = startDateBox;
|
|
|
|
|
this.startDateBox.setCompact(true);
|
|
|
|
|
this.startDateBox.setFormat("dd/MM/yyyy");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Datebox getEndDateBox() {
|
|
|
|
|
return endDateBox;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void setEndDateBox(Datebox endDateBox) {
|
|
|
|
|
this.endDateBox = endDateBox;
|
|
|
|
|
this.endDateBox.setFormat("dd/MM/yyyy");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private Datebox startDateBox;
|
|
|
|
|
|
|
|
|
|
private Datebox endDateBox;
|
|
|
|
|
|
2009-06-15 21:48:54 +02:00
|
|
|
public static TaskDetail create(TaskBean bean) {
|
|
|
|
|
return new TaskDetail(bean);
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
2009-06-15 21:48:54 +02:00
|
|
|
private TaskDetail(TaskBean task) {
|
|
|
|
|
this.taskBean = task;
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public TaskBean getData() {
|
|
|
|
|
return taskBean;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void afterCompose() {
|
|
|
|
|
super.afterCompose();
|
|
|
|
|
updateComponents();
|
|
|
|
|
taskBean.addPropertyChangeListener(new PropertyChangeListener() {
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void propertyChange(PropertyChangeEvent evt) {
|
|
|
|
|
updateComponents();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void updateBean() {
|
|
|
|
|
if (getEndDateBox().getValue().before(getStartDateBox().getValue())) {
|
|
|
|
|
updateComponents();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
taskBean.setName(getNameBox().getValue());
|
|
|
|
|
taskBean.setBeginDate(getStartDateBox().getValue());
|
|
|
|
|
taskBean.setEndDate(getEndDateBox().getValue());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void updateComponents() {
|
|
|
|
|
getNameBox().setValue(taskBean.getName());
|
|
|
|
|
getStartDateBox().setValue(taskBean.getBeginDate());
|
|
|
|
|
getEndDateBox().setValue(taskBean.getEndDate());
|
|
|
|
|
}
|
2009-06-15 21:48:54 +02:00
|
|
|
|
2009-04-14 17:51:03 +02:00
|
|
|
}
|