diff --git a/navalplanner-gantt-zk/src/main/java/org/zkoss/ganttz/TaskDetail.java b/navalplanner-gantt-zk/src/main/java/org/zkoss/ganttz/TaskDetail.java index eb0e0cfb6..948a6d46a 100644 --- a/navalplanner-gantt-zk/src/main/java/org/zkoss/ganttz/TaskDetail.java +++ b/navalplanner-gantt-zk/src/main/java/org/zkoss/ganttz/TaskDetail.java @@ -9,6 +9,7 @@ import java.util.Date; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.zkoss.ganttz.util.TaskBean; +import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.HtmlMacroComponent; import org.zkoss.zk.ui.ext.AfterCompose; import org.zkoss.zul.Datebox; @@ -16,10 +17,6 @@ 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); @@ -32,6 +29,10 @@ public class TaskDetail extends HtmlMacroComponent implements AfterCompose { private Textbox nameBox; + private Textbox startDateTextBox; + + private Textbox endDateTextBox; + public Textbox getNameBox() { return nameBox; } @@ -75,6 +76,47 @@ public class TaskDetail extends HtmlMacroComponent implements AfterCompose { return taskBean; } + /** + * When a text box associated to a datebox receives focus, the corresponding + * datebox is shown + * @param component + * the component that has received focus + */ + public void hasReceivedFocus(Component component) { + if (component == startDateTextBox) { + showDateBox(startDateBox, startDateTextBox); + } + if (component == endDateTextBox) { + showDateBox(endDateBox, endDateTextBox); + } + } + + private void showDateBox(Datebox dateBox, Textbox associatedTextBox) { + associatedTextBox.setVisible(false); + dateBox.setVisible(true); + dateBox.setFocus(true); + } + + /** + * When the dateBox loses focus the corresponding textbox is shown instead. + * @param dateBox + * the component that has lost focus + */ + public void dateBoxHasLostFocus(Datebox dateBox) { + if (dateBox == startDateBox) { + hideDateBox(startDateBox, startDateTextBox); + } + if (dateBox == endDateBox) { + hideDateBox(endDateBox, endDateTextBox); + } + } + + private void hideDateBox(Datebox dateBoxToDissapear, + Textbox associatedTextBox) { + dateBoxToDissapear.setVisible(false); + associatedTextBox.setVisible(true); + } + @Override public void afterCompose() { super.afterCompose(); @@ -102,6 +144,29 @@ public class TaskDetail extends HtmlMacroComponent implements AfterCompose { getNameBox().setValue(taskBean.getName()); getStartDateBox().setValue(taskBean.getBeginDate()); getEndDateBox().setValue(taskBean.getEndDate()); + getStartDateTextBox().setValue(asString(taskBean.getBeginDate())); + getEndDateTextBox().setValue(asString(taskBean.getEndDate())); } + private String asString(Date date) { + return dateFormat.format(date); + } + + public Textbox getStartDateTextBox() { + return startDateTextBox; + } + + public void setStartDateTextBox(Textbox startDateTextBox) { + this.startDateTextBox = startDateTextBox; + } + + public Textbox getEndDateTextBox() { + return endDateTextBox; + } + + public void setEndDateTextBox(Textbox endDateTextBox) { + this.endDateTextBox = endDateTextBox; + } + + } diff --git a/navalplanner-gantt-zk/src/main/resources/web/ganttz/zul/taskdetail.zul b/navalplanner-gantt-zk/src/main/resources/web/ganttz/zul/taskdetail.zul index ba9ef4cf8..1aec9e5a0 100644 --- a/navalplanner-gantt-zk/src/main/resources/web/ganttz/zul/taskdetail.zul +++ b/navalplanner-gantt-zk/src/main/resources/web/ganttz/zul/taskdetail.zul @@ -4,15 +4,19 @@ ]]> - - - - + + + + + + \ No newline at end of file