From d235c840a95e0480efc0a3e4f0861c6ba4c05a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenzo=20Tilve=20=C3=81lvaro?= Date: Wed, 9 Nov 2011 22:54:51 +0100 Subject: [PATCH] [Bug #1244] Fixed DynamicDatebox component behaviour in zk5 The component created for 'transforming' a textbox into a datebox with onOk event, was now building all dateboxes, which could decrease performance on big orders. The component has been modified to create the dateboxes just on demand. FEA: ItEr75S04BugFixing --- .../libreplan/web/orders/DynamicDatebox.java | 58 ++++++++++--------- .../common/components/dynamicDatebox.zul | 1 - .../main/webapp/common/css/libreplan_zk.css | 2 +- 3 files changed, 31 insertions(+), 30 deletions(-) diff --git a/libreplan-webapp/src/main/java/org/libreplan/web/orders/DynamicDatebox.java b/libreplan-webapp/src/main/java/org/libreplan/web/orders/DynamicDatebox.java index a11bd7e15..f6d6d2dc4 100644 --- a/libreplan-webapp/src/main/java/org/libreplan/web/orders/DynamicDatebox.java +++ b/libreplan-webapp/src/main/java/org/libreplan/web/orders/DynamicDatebox.java @@ -36,6 +36,14 @@ import org.zkoss.zul.Datebox; import org.zkoss.zul.Hbox; import org.zkoss.zul.Textbox; +/** + * Textbox component which is transformed into a Datebox picker on demand
+ * + * @author Susana Montes Pedreira + * @author Lorenzo Tilve Álvaro + * @author Manuel Rego Casasnovas + * @author Jacobo Aragunde Pérez + */ public class DynamicDatebox extends GenericForwardComposer { private final OrderElement orderElement; @@ -65,14 +73,19 @@ public class DynamicDatebox extends GenericForwardComposer { return orderElement; } - public Datebox getDateBox() { + public Datebox createDateBox() { + dateBox = new Datebox(); + dateBox.setFormat("short"); + dateBox.setValue(getter.get()); + registerOnEnterOpenDateBox(dateBox); + registerBlurListener(dateBox); + registerOnChange(dateBox); + dateTextBox.getParent().appendChild(dateBox); return dateBox; } - public void setDateBox(Datebox dateBox) { - this.dateBox = dateBox; - this.dateBox.setCompact(true); - this.dateBox.setFormat("dd/MM/yyyy"); + public Datebox getDateBox() { + return dateBox; } /** @@ -83,15 +96,17 @@ public class DynamicDatebox extends GenericForwardComposer { */ public void userWantsDateBox(Component component) { if (component == dateTextBox) { - showDateBox(dateBox, dateTextBox); + showDateBox(dateTextBox); } } - private void showDateBox(Datebox currentDateBox, Textbox associatedTextBox) { + private void showDateBox(Textbox associatedTextBox) { associatedTextBox.setVisible(false); - currentDateBox.setVisible(true); - currentDateBox.setFocus(true); - currentDateBox.setOpen(true); + getDateBox(); + createDateBox(); + dateBox.setVisible(true); + dateBox.setFocus(true); + dateBox.setOpen(true); } /** @@ -101,13 +116,12 @@ public class DynamicDatebox extends GenericForwardComposer { */ public void dateBoxHasLostFocus(Datebox currentDateBox) { if (currentDateBox == dateBox) { - hideDateBox(dateBox, dateTextBox); + hideDateBox(dateTextBox); } } - private void hideDateBox(Datebox dateBoxToDissapear, - Textbox associatedTextBox) { - dateBoxToDissapear.setVisible(false); + private void hideDateBox(Textbox associatedTextBox) { + dateBox.detach(); associatedTextBox.setVisible(true); } @@ -122,22 +136,14 @@ public class DynamicDatebox extends GenericForwardComposer { private void registerListeners() { registerOnEnterListener(dateTextBox); - registerOnEnterOpenDateBox(dateBox); - registerBlurListener(dateBox); - registerOnChange(dateBox); } private void findComponents(Hbox hbox) { List children = hbox.getChildren(); - assert children.size() == 2; + assert children.size() == 1; dateTextBox = findTextBoxOfCell(children); - dateBox = findDateBoxOfCell(children); - } - - private static Datebox findDateBoxOfCell(List children) { - return ComponentsFinder.findComponentsOfType(Datebox.class, children) - .get(0); + // dateBox = findDateBoxOfCell(children); } private static Textbox findTextBoxOfCell(List children) { @@ -210,7 +216,6 @@ public class DynamicDatebox extends GenericForwardComposer { } private void updateComponents() { - getDateBox().setValue(getter.get()); getDateTextBox().setValue(asString(getter.get())); } @@ -239,9 +244,6 @@ public class DynamicDatebox extends GenericForwardComposer { } private void applyDisabledToElements(boolean disabled) { - if(dateBox != null) { - dateBox.setDisabled(disabled); - } if(dateTextBox != null) { dateTextBox.setDisabled(disabled); } diff --git a/libreplan-webapp/src/main/webapp/common/components/dynamicDatebox.zul b/libreplan-webapp/src/main/webapp/common/components/dynamicDatebox.zul index cf7a9e96c..136bb4613 100644 --- a/libreplan-webapp/src/main/webapp/common/components/dynamicDatebox.zul +++ b/libreplan-webapp/src/main/webapp/common/components/dynamicDatebox.zul @@ -21,5 +21,4 @@ - diff --git a/libreplan-webapp/src/main/webapp/common/css/libreplan_zk.css b/libreplan-webapp/src/main/webapp/common/css/libreplan_zk.css index e82d33338..1217692a3 100644 --- a/libreplan-webapp/src/main/webapp/common/css/libreplan_zk.css +++ b/libreplan-webapp/src/main/webapp/common/css/libreplan_zk.css @@ -572,7 +572,7 @@ div.z-grid { .listdetails .z-textbox, .listdetails .z-decimalbox, .listdetails .z-intbox, .listdetails .z-longbox, -.listdetails .z-doublebox { +.listdetails .z-doublebox, .listdetails .z-datebox-inp { height: 15px; } .listdetails input {