From 8af496019d2f218eb8b18eeeec3a3acbcec6a954 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Thu, 21 Mar 2013 13:39:45 +0800 Subject: [PATCH] IDEMPIERE-786 ZK: Remove onFocus and onBlur server side event for field editor. --- .../adempiere/webui/adwindow/ADTabpanel.java | 39 ++++----------- .../webui/adwindow/GridTabRowRenderer.java | 9 +++- .../adempiere/webui/adwindow/GridView.java | 8 +-- .../apps/form/WCreateFromShipmentUI.java | 1 - .../org/adempiere/webui/editor/WEditor.java | 24 +-------- .../adempiere/webui/panel/HelpController.java | 49 ++++++++++++++++++- 6 files changed, 69 insertions(+), 61 deletions(-) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java index c97c17f6bf..ff25945b69 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/ADTabpanel.java @@ -48,7 +48,7 @@ import org.adempiere.webui.editor.WImageEditor; import org.adempiere.webui.editor.WPaymentEditor; import org.adempiere.webui.editor.WebEditorFactory; import org.adempiere.webui.event.ContextMenuListener; -import org.adempiere.webui.session.SessionManager; +import org.adempiere.webui.panel.HelpController; import org.adempiere.webui.util.GridTabDataBinder; import org.adempiere.webui.util.TreeUtils; import org.adempiere.webui.window.FDialog; @@ -527,8 +527,11 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer if (editor != null) // Not heading { - editor.getComponent().addEventListener(Events.ON_FOCUS, this); - editor.getComponent().addEventListener(Events.ON_BLUR, this); + editor.getComponent().setWidgetOverride("fieldHeader", HelpController.escapeJavascriptContent(field.getHeader())); + editor.getComponent().setWidgetOverride("fieldDescription", HelpController.escapeJavascriptContent(field.getDescription())); + editor.getComponent().setWidgetOverride("fieldHelp", HelpController.escapeJavascriptContent(field.getHelp())); + editor.getComponent().setWidgetListener("onFocus", "zWatch.fire('onFieldTooltip', this, null, this.fieldHeader, this.fieldDescription, this.fieldHelp);"); + editor.getComponent().setWidgetListener("onBlur", "zWatch.fire('onFieldTooltip', this);"); editor.setGridTab(this.getGridTab()); field.addPropertyChangeListener(editor); @@ -968,7 +971,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer public void focusToFirstEditor() { WEditor toFocus = null; for (WEditor editor : editors) { - if (editor.isHasFocus() && editor.isVisible() && editor.getComponent().getParent() != null) { + if (editor.isVisible() && editor.getComponent().getParent() != null) { toFocus = editor; break; } @@ -1047,26 +1050,6 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer Env.getCtx().setProperty("P"+windowId+"|"+adTabId+"|DetailPane.IsOpen", value ? "Y" : "N"); } } - else if (event.getName().equals(Events.ON_FOCUS)) { - for (WEditor editor : editors) - { - if (editor.isComponentOfEditor(event.getTarget())) - { - SessionManager.getAppDesktop().updateHelpTooltip(editor.getGridField()); - return; - } - } - } - else if (event.getName().equals(Events.ON_BLUR)) { - for (WEditor editor : editors) - { - if (editor.isComponentOfEditor(event.getTarget())) - { - SessionManager.getAppDesktop().updateHelpTooltip(null); - return; - } - } - } } private void onSouthEvent(SouthEvent event) { @@ -1351,14 +1334,10 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer */ public void setFocusToField(String columnName) { if (formContainer.isVisible()) { - boolean found = false; for (WEditor editor : editors) { - if (found) - editor.setHasFocus(false); - else if (columnName.equals(editor.getColumnName())) { - editor.setHasFocus(true); + if (columnName.equals(editor.getColumnName())) { Clients.response(new AuFocus(editor.getComponent())); - found = true; + break; } } } else { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/GridTabRowRenderer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/GridTabRowRenderer.java index 675e22df16..e592eaed97 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/GridTabRowRenderer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/GridTabRowRenderer.java @@ -30,6 +30,7 @@ import org.adempiere.webui.editor.WebEditorFactory; import org.adempiere.webui.event.ActionEvent; import org.adempiere.webui.event.ActionListener; import org.adempiere.webui.event.ContextMenuListener; +import org.adempiere.webui.panel.HelpController; import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.util.GridTabDataBinder; import org.compiere.model.GridField; @@ -376,6 +377,12 @@ public class GridTabRowRenderer implements RowRenderer, RowRendererExt WEditor readOnlyEditor = WebEditorFactory.getEditor(gridPanelFields[i], true); readOnlyEditor.setReadWrite(false); readOnlyEditors.put(gridPanelFields[i], readOnlyEditor); + + editor.getComponent().setWidgetOverride("fieldHeader", HelpController.escapeJavascriptContent(gridPanelFields[i].getHeader())); + editor.getComponent().setWidgetOverride("fieldDescription", HelpController.escapeJavascriptContent(gridPanelFields[i].getDescription())); + editor.getComponent().setWidgetOverride("fieldHelp", HelpController.escapeJavascriptContent(gridPanelFields[i].getHelp())); + editor.getComponent().setWidgetListener("onFocus", "zWatch.fire('onFieldTooltip', this, null, this.fieldHeader, this.fieldDescription, this.fieldHelp);"); + editor.getComponent().setWidgetListener("onBlur", "zWatch.fire('onFieldTooltip', this);"); } if (!gridPanelFields[i].isDisplayedGrid() || gridPanelFields[i].isToolbarButton()) { @@ -578,7 +585,7 @@ public class GridTabRowRenderer implements RowRenderer, RowRendererExt WEditor toFocus = null; WEditor firstEditor = null; for (WEditor editor : getEditors()) { - if (editor.isHasFocus() && editor.isVisible() && editor.getComponent().getParent() != null) { + if (editor.isVisible() && editor.getComponent().getParent() != null) { toFocus = editor; break; } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/GridView.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/GridView.java index 112600919a..790c392ab0 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/GridView.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/GridView.java @@ -796,12 +796,8 @@ public class GridView extends Vbox implements EventListener, IdSpace, IFi * @param columnName */ public void setFocusToField(String columnName) { - boolean found = false; for (WEditor editor : renderer.getEditors()) { - if (found) - editor.setHasFocus(false); - else if (columnName.equals(editor.getColumnName())) { - editor.setHasFocus(true); + if (columnName.equals(editor.getColumnName())) { Component c = editor.getComponent(); if (c instanceof EditorBox) { c = ((EditorBox)c).getTextbox(); @@ -809,7 +805,7 @@ public class GridView extends Vbox implements EventListener, IdSpace, IFi c = ((NumberBox)c).getDecimalbox(); } Clients.response(new AuFocus(c)); - found = true; + break; } } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java index cbe4fb8ca1..e0f282843e 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WCreateFromShipmentUI.java @@ -331,7 +331,6 @@ public class WCreateFromShipmentUI extends CreateFromShipment implements EventLi } } upcField.setValue(""); - upcField.setHasFocus(true); } /** diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java index 486d0f1076..a396a48a07 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/editor/WEditor.java @@ -88,8 +88,6 @@ public abstract class WEditor implements EventListener, PropertyChangeLis private String columnName; - protected boolean hasFocus; - protected WEditorPopupMenu popupMenu; private boolean tableEditor; @@ -230,18 +228,8 @@ public abstract class WEditor implements EventListener, PropertyChangeLis { component.addEventListener(event, this); } - component.addEventListener(Events.ON_FOCUS, new EventListener() { - public void onEvent(Event event) throws Exception { - hasFocus = true; - } - - }); - component.addEventListener(Events.ON_BLUR, new EventListener() { - public void onEvent(Event event) throws Exception { - hasFocus = false; - } - - }); + + component.setAttribute("idempiere.editor", this); } /** @@ -545,14 +533,6 @@ public abstract class WEditor implements EventListener, PropertyChangeLis } } - public boolean isHasFocus() { - return hasFocus; - } - - public void setHasFocus(boolean b) { - hasFocus = b; - } - public void updateLabelStyle() { if (getLabel() != null) { String style = (isZoomable() ? STYLE_ZOOMABLE_LABEL : "") + (isMandatoryStyle() ? STYLE_EMPTY_MANDATORY_LABEL : STYLE_NORMAL_LABEL); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java index 54e637a969..99ac18daaf 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/HelpController.java @@ -40,7 +40,9 @@ import org.compiere.util.Env; import org.compiere.util.Msg; import org.compiere.wf.MWFNode; import org.compiere.wf.MWorkflow; +import org.zkoss.zk.au.out.AuScript; import org.zkoss.zk.ui.Component; +import org.zkoss.zk.ui.util.Clients; import org.zkoss.zul.Anchorchildren; import org.zkoss.zul.Anchorlayout; import org.zkoss.zul.Html; @@ -95,6 +97,15 @@ public class HelpController Panelchildren content = new Panelchildren(); pnlToolTip.appendChild(content); content.appendChild(htmlToolTip = new Html()); + htmlToolTip.setWidgetOverride("defaultMessage", "'"+Msg.getMsg(Env.getCtx(), "PlaceCursorIntoField")+"'"); + htmlToolTip.setWidgetOverride("onFieldTooltip", "function(origin,opts,header,description,help)" + + "{var s='
';" + + "if (typeof header == 'undefined') {s=s+''+this.defaultMessage+'';} " + + "else {s=s+''+header+'';" + + "if (typeof description=='string' && description.length > 0) {s=s+'

'+description+'';}" + + "if (typeof help=='string' && help.length > 0) {s=s+'

'+help;}}" + + "s=s+'
';this.setContent(s);}"); + Clients.response(new AuScript(htmlToolTip, "var w=zk.Widget.$('#"+htmlToolTip.getUuid()+"');zWatch.listen({onFieldTooltip: w});")); pnlContextHelp = new Panel(); pnlContextHelp.setSclass("dashboard-widget"); @@ -106,7 +117,7 @@ public class HelpController dashboardColumnLayout.appendChild(pnlContextHelp); content = new Panelchildren(); pnlContextHelp.appendChild(content); - content.appendChild(htmlContextHelp = new Html()); + content.appendChild(htmlContextHelp = new Html()); renderToolTip(null); renderCtxHelp(X_AD_CtxHelp.CTXTYPE_Home, 0); @@ -424,4 +435,40 @@ public class HelpController return ""; } + + /** + * @param content content + * @return masked content or empty string if the content is null + */ + public static String escapeJavascriptContent(String content) + { + // If the content is null, then return '' + if (content == null) + return "''"; + // + StringBuilder out = new StringBuilder("'"); + char[] chars = content.toCharArray(); + for (int i = 0; i < chars.length; i++) + { + char c = chars[i]; + switch (c) + { + case '\r': + out.append (""); + break; + case '\'': + out.append ("\\'"); + break; + case '\n': + out.append ("
"); + break; + // + default: + out.append(c); + break; + } + } + out.append("'"); + return out.toString(); + } // maskHTML }