From 97ede121b830455bcc6e3dbddd0e4ef09fbdc2d4 Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Tue, 2 Apr 2013 00:38:34 +0800 Subject: [PATCH] IDEMPIERE-818 Zk: Focus always move back to first form field even when it is not needed. --- .../adempiere/webui/adwindow/ADTabpanel.java | 35 +++++++++++++++---- .../webui/adwindow/GridTabRowRenderer.java | 3 ++ 2 files changed, 31 insertions(+), 7 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 d428ba6002..3cc496291a 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 @@ -40,6 +40,7 @@ import org.adempiere.webui.component.NumberBox; import org.adempiere.webui.component.Row; import org.adempiere.webui.component.Rows; import org.adempiere.webui.component.SimpleTreeModel; +import org.adempiere.webui.component.Urlbox; import org.adempiere.webui.editor.IZoomableEditor; import org.adempiere.webui.editor.WButtonEditor; import org.adempiere.webui.editor.WEditor; @@ -75,6 +76,7 @@ import org.compiere.util.Evaluatee; import org.compiere.util.Msg; import org.compiere.util.Util; import org.zkoss.zk.au.out.AuFocus; +import org.zkoss.zk.au.out.AuScript; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.HtmlBasedComponent; @@ -963,11 +965,19 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer Events.postEvent(event); } - /** + /** * set focus to first active editor */ @Override - public void focusToFirstEditor() { + public void focusToFirstEditor() { + focusToFirstEditor(false); + } + + /** + * + * @param checkCurrent + */ + public void focusToFirstEditor(boolean checkCurrent) { WEditor toFocus = null; for (WEditor editor : editors) { if (editor.isVisible() && editor.isReadWrite() && editor.getComponent().getParent() != null @@ -977,7 +987,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer } } if (toFocus != null) { - focusToEditor(toFocus); + focusToEditor(toFocus, checkCurrent); } } @@ -1316,7 +1326,7 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer @Override public void focus() { if (formContainer.isVisible()) - this.focusToFirstEditor(); + this.focusToFirstEditor(true); else listPanel.focus(); } @@ -1504,21 +1514,32 @@ DataStatusListener, IADTabpanel, IdSpace, IFieldEditorContainer } if (found) { if (editor.isVisible() && editor.isReadWrite()) { - focusToEditor(editor); + focusToEditor(editor, false); break; } } } } - protected void focusToEditor(WEditor toFocus) { + protected void focusToEditor(WEditor toFocus, boolean checkCurrent) { Component c = toFocus.getComponent(); if (c instanceof EditorBox) { c = ((EditorBox)c).getTextbox(); } else if (c instanceof NumberBox) { c = ((NumberBox)c).getDecimalbox(); + } else if (c instanceof Urlbox) { + c = ((Urlbox)c).getTextbox(); + } + if (!checkCurrent) { + ((HtmlBasedComponent)c).focus(); + } else { + StringBuilder script = new StringBuilder("var b=true;try{if (zk.currentFocus) {"); + script.append("var p=zk.Widget.$('#").append(formContainer.getCenter().getUuid()).append("');"); + script.append("if (zUtl.isAncestor(p, zk.currentFocus)) {"); + script.append("b=false;}}}catch(error){}"); + script.append("if(b){var w=zk.Widget.$('#").append(c.getUuid()).append("');w.focus(0);}"); + Clients.response(new AuScript(script.toString())); } - ((HtmlBasedComponent)c).focus(); } } 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 f9ae3f3f46..572fd804a5 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 @@ -23,6 +23,7 @@ import org.adempiere.util.GridRowCtx; import org.adempiere.webui.component.Checkbox; import org.adempiere.webui.component.EditorBox; import org.adempiere.webui.component.NumberBox; +import org.adempiere.webui.component.Urlbox; import org.adempiere.webui.editor.WButtonEditor; import org.adempiere.webui.editor.WEditor; import org.adempiere.webui.editor.WEditorPopupMenu; @@ -608,6 +609,8 @@ public class GridTabRowRenderer implements RowRenderer, RowRendererExt c = ((EditorBox)c).getTextbox(); } else if (c instanceof NumberBox) { c = ((NumberBox)c).getDecimalbox(); + } else if (c instanceof Urlbox) { + c = ((Urlbox) c).getTextbox(); } ((HtmlBasedComponent)c).focus(); }