ItEr13S14ArquitecturaClientesItEr11S12: DateBoxes on left panel are now loaded by demand.

This commit is contained in:
Óscar González Fernández 2009-06-20 18:32:33 +02:00 committed by Javier Moran Rua
parent 2bb89fe950
commit 17ec1a3eee
2 changed files with 77 additions and 8 deletions

View file

@ -9,6 +9,7 @@ import java.util.Date;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.zkoss.ganttz.util.TaskBean; import org.zkoss.ganttz.util.TaskBean;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.HtmlMacroComponent; import org.zkoss.zk.ui.HtmlMacroComponent;
import org.zkoss.zk.ui.ext.AfterCompose; import org.zkoss.zk.ui.ext.AfterCompose;
import org.zkoss.zul.Datebox; import org.zkoss.zul.Datebox;
@ -16,10 +17,6 @@ import org.zkoss.zul.Textbox;
public class TaskDetail extends HtmlMacroComponent implements AfterCompose { 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 DateFormat dateFormat = new SimpleDateFormat("dd/MM/yyyy");
private static final Log LOG = LogFactory.getLog(TaskDetail.class); 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 nameBox;
private Textbox startDateTextBox;
private Textbox endDateTextBox;
public Textbox getNameBox() { public Textbox getNameBox() {
return nameBox; return nameBox;
} }
@ -75,6 +76,47 @@ public class TaskDetail extends HtmlMacroComponent implements AfterCompose {
return taskBean; 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 @Override
public void afterCompose() { public void afterCompose() {
super.afterCompose(); super.afterCompose();
@ -102,6 +144,29 @@ public class TaskDetail extends HtmlMacroComponent implements AfterCompose {
getNameBox().setValue(taskBean.getName()); getNameBox().setValue(taskBean.getName());
getStartDateBox().setValue(taskBean.getBeginDate()); getStartDateBox().setValue(taskBean.getBeginDate());
getEndDateBox().setValue(taskBean.getEndDate()); 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;
}
} }

View file

@ -4,15 +4,19 @@
]]> ]]>
</zscript> </zscript>
<hbox> <hbox>
<textbox id="nameBox" value="" onChange="top.updateBean();" /> <textbox id="nameBox" value="" onChange="top.updateBean();" />
<datebox id="startDateBox" compact="true" onChange="top.updateBean();"/> <textbox id="startDateTextBox" value="" onChange="top.updateBean();" onFocus="top.hasReceivedFocus(self);" />
<datebox id="endDateBox" compact="true" onChange="top.updateBean();" /> <datebox id="startDateBox" compact="true" onChange="top.updateBean();" visible="${false}" onBlur="top.dateBoxHasLostFocus(self);"/>
</hbox> <textbox id="endDateTextBox" value="" onChange="top.updateBean();" onFocus="top.hasReceivedFocus(self);"/>
<datebox id="endDateBox" compact="true" onChange="top.updateBean();" visible ="${false}" onBlur="top.dateBoxHasLostFocus(self);"/>
</hbox>
<zscript><![CDATA[ <zscript><![CDATA[
top.nameBox = nameBox; top.nameBox = nameBox;
top.startDateBox = startDateBox; top.startDateBox = startDateBox;
top.endDateBox = endDateBox; top.endDateBox = endDateBox;
top.startDateTextBox = startDateTextBox;
top.endDateTextBox = endDateTextBox;
]]> ]]>
</zscript> </zscript>
</zk> </zk>