diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java index 549c728fb0..98784db541 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/AbstractADWindowContent.java @@ -1022,16 +1022,14 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements if (record_ID == -1) // No Key { - //aAttachment.setEnabled(false); return; } EventListener listener = new EventListener() { - @Override public void onEvent(Event event) throws Exception { toolbar.setPressed("Attachment",adTabbox.getSelectedGridTab().hasAttachment()); - focusToActivePanel(); + focusToLastFocusEditor(); } }; // Attachment va = @@ -1084,7 +1082,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements public void onEvent(Event event) throws Exception { hideBusyMask(); toolbar.setPressed("Chat",adTabbox.getSelectedGridTab().hasChat()); - focusToActivePanel(); + focusToLastFocusEditor(); } }); getComponent().getParent().appendChild(chat); @@ -1125,7 +1123,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements public void onEvent(Event event) throws Exception { hideBusyMask(); toolbar.setPressed("PostIt",adTabbox.getSelectedGridTab().hasPostIt()); - focusToActivePanel(); + focusToLastFocusEditor(); } }); getComponent().getParent().appendChild(postit); @@ -1158,9 +1156,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements if (!b) { //restore focus - if (lastFocusEditor != null && lastFocusEditor instanceof HtmlBasedComponent && - lastFocusEditor.getPage() != null && LayoutUtils.isReallyVisible(lastFocusEditor)) - ((HtmlBasedComponent)lastFocusEditor).focus(); + focusToLastFocusEditor(); } }); } @@ -1171,6 +1167,15 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements } + /** + * restore focus to last known focus editor (if any) + */ + public void focusToLastFocusEditor() { + if (lastFocusEditor != null && lastFocusEditor instanceof HtmlBasedComponent && + lastFocusEditor.getPage() != null && LayoutUtils.isReallyVisible(lastFocusEditor)) + ((HtmlBasedComponent)lastFocusEditor).focus(); + } + /** * Invoke when quick form is click */ @@ -2303,12 +2308,14 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements } } toolbar.refreshUserQuery(adTabbox.getSelectedGridTab().getAD_Tab_ID(), getCurrentFindWindow().getAD_UserQuery_ID()); + focusToActivePanel(); } else { toolbar.setPressed("Find",adTabbox.getSelectedGridTab().isQueryActive()); + focusToLastFocusEditor(); } - focusToActivePanel(); + } }); } @@ -3219,7 +3226,8 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements win.addEventListener(DialogEvents.ON_WINDOW_CLOSE, new EventListener() { public void onEvent(Event event) throws Exception { hideBusyMask(); - if (!win.isStartProcess()) { + focusToLastFocusEditor(); + if (!win.isStartProcess()) { return; } boolean startWOasking = true; @@ -3252,7 +3260,9 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements hideBusyMask(); if (!window.isCancel()) { onRefresh(true, false); - } + } else { + focusToLastFocusEditor(); + } } }); window.setZindex(1000); @@ -3584,6 +3594,7 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements { statusBar.setStatusLine(error, true); } + focusToLastFocusEditor(); return; } actionButton((IProcessButton) event.getSource()); @@ -3755,7 +3766,9 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements */ public void onCustomize() { ADTabpanel tabPanel = (ADTabpanel) getADTab().getSelectedTabpanel(); - CustomizeGridViewDialog.onCustomize(tabPanel); + CustomizeGridViewDialog.onCustomize(tabPanel, b -> { + focusToLastFocusEditor(); + }); } /** @@ -3777,6 +3790,8 @@ public abstract class AbstractADWindowContent extends AbstractUIPart implements public void onSelect() { if (getCurrentFindWindow() != null && getCurrentFindWindow().getPage() != null && getCurrentFindWindow().isVisible() && m_queryInitiating) { LayoutUtils.openEmbeddedWindow(getComponent().getParent(), getCurrentFindWindow(), "overlap"); + } else { + focusToLastFocusEditor(); } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/BreadCrumb.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/BreadCrumb.java index e54a91e23f..bf8ec917c8 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/BreadCrumb.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/BreadCrumb.java @@ -49,6 +49,7 @@ import org.zkoss.zk.ui.util.Clients; import org.zkoss.zul.Div; import org.zkoss.zul.Hlayout; import org.zkoss.zul.Menuitem; +import org.zkoss.zul.Window; /** * @author hengsin @@ -307,7 +308,12 @@ public class BreadCrumb extends Div implements EventListener { return; String title = Msg.getMsg(Env.getCtx(), "Who") + m_text; - new WRecordInfo (title, m_dse, m_gridTab); + WRecordInfo winfo = new WRecordInfo (title, m_dse, m_gridTab); + winfo.addCallback(Window.AFTER_PAGE_DETACHED, t -> { + ADWindow adwindow = ADWindow.findADWindow(BreadCrumb.this); + if (adwindow != null) + adwindow.getADWindowContent().focusToLastFocusEditor(); + }); } else if (event.getTarget() == btnFirst) { if (toolbarListener != null) toolbarListener.onFirst(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/DetailPane.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/DetailPane.java index 1ecd5a352d..3a26f64a2f 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/DetailPane.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/adwindow/DetailPane.java @@ -560,7 +560,11 @@ public class DetailPane extends Panel implements EventListener, IdSpace { protected void onCustomize(Event e) { if (getSelectedADTabpanel() instanceof ADTabpanel) { ADTabpanel tabPanel = (ADTabpanel) getSelectedADTabpanel(); - CustomizeGridViewDialog.onCustomize(tabPanel); + CustomizeGridViewDialog.onCustomize(tabPanel, b -> { + ADWindow adwindow = ADWindow.findADWindow(DetailPane.this); + if (adwindow != null) + adwindow.getADWindowContent().focusToLastFocusEditor(); + }); } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WQuickForm.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WQuickForm.java index 30deca00ca..1f0afb6502 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WQuickForm.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/form/WQuickForm.java @@ -103,6 +103,8 @@ public class WQuickForm extends Window implements IQuickForm // To maintain parent-child Quick Form prevQGV = adWinContent.getCurrQGV(); adWinContent.setCurrQGV(quickGridView); + + addCallback(AFTER_PAGE_DETACHED, t -> adWinContent.focusToLastFocusEditor()); } protected void initForm( ) @@ -264,7 +266,7 @@ public class WQuickForm extends Window implements IQuickForm ZKUpdateUtil.setWidth(quickGridView, getWidth()); ZKUpdateUtil.setHeight(quickGridView, getHeight()); - CustomizeGridViewDialog.showCustomize(0, gridTab.getAD_Tab_ID(), columnsWidth, gridFieldIds, null, quickGridView, true); + CustomizeGridViewDialog.showCustomize(0, gridTab.getAD_Tab_ID(), columnsWidth, gridFieldIds, null, quickGridView, true, null); } // onCustomize public void onIgnore( ) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Window.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Window.java index a3caa9fdef..2e88aded4d 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Window.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/Window.java @@ -17,8 +17,6 @@ package org.adempiere.webui.component; -import java.util.Collection; - import org.adempiere.webui.ISupportMask; import org.adempiere.webui.ShowMaskWrapper; import org.adempiere.webui.event.DialogEvents; @@ -27,7 +25,6 @@ import org.zkoss.zk.ui.Executions; import org.zkoss.zk.ui.Page; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.Events; -import org.zkoss.zk.ui.util.Callback; /** * @@ -79,7 +76,6 @@ public class Window extends org.zkoss.zul.Window implements ISupportMask /* (non-Javadoc) * @see org.zkoss.zul.Window#onPageDetached(org.zkoss.zk.ui.Page) */ - @SuppressWarnings({ "rawtypes", "unchecked" }) @Override public void onPageDetached(Page page) { super.onPageDetached(page); @@ -87,13 +83,7 @@ public class Window extends org.zkoss.zul.Window implements ISupportMask Executions.getCurrent().getDesktop().getExecution() != null) { Events.sendEvent(this, new Event(DialogEvents.ON_WINDOW_CLOSE, this, null)); } - //org.zkoss.zul.Window.onPageDetached doesn't call super.onPageDetached, bug ? - Collection callbacks = getCallback(AFTER_PAGE_DETACHED); - for (Callback callback : callbacks) { - callback.call(this); - } } - /** * Get the window mode attribute diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/CSVImportAction.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/CSVImportAction.java index 707c63039d..c76222dcd7 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/CSVImportAction.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/CSVImportAction.java @@ -240,6 +240,7 @@ public class CSVImportAction implements EventListener importFile(); } else if (event.getName().equals(DialogEvents.ON_WINDOW_CLOSE)) { panel.hideBusyMask(); + panel.focusToLastFocusEditor(); } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ExportAction.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ExportAction.java index 70ce7eddb9..525eea9474 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ExportAction.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/ExportAction.java @@ -234,8 +234,9 @@ public class ExportAction implements EventListener else if(event.getTarget().getId().equals(ConfirmPanel.A_OK)) exportFile(); else if (event.getName().equals(DialogEvents.ON_WINDOW_CLOSE)) { - panel.hideBusyMask(); - }else if (event.getTarget().equals(cboType) && event.getName().equals(Events.ON_SELECT)) { + panel.hideBusyMask(); + panel.focusToLastFocusEditor(); + } else if (event.getTarget().equals(cboType) && event.getName().equals(Events.ON_SELECT)) { displayExportTabSelection(); }else if (event.getTarget() instanceof Checkbox) { // A child is not exportable without its parent diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java index f66c553da7..9d45495702 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/panel/action/FileImportAction.java @@ -252,6 +252,7 @@ public class FileImportAction implements EventListener importFile(); } else if (event.getName().equals(DialogEvents.ON_WINDOW_CLOSE)) { panel.hideBusyMask(); + panel.focusToLastFocusEditor(); } } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/CustomizeGridViewDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/CustomizeGridViewDialog.java index 846d82a038..2d75d0c9b0 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/CustomizeGridViewDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/CustomizeGridViewDialog.java @@ -5,6 +5,7 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.adempiere.util.Callback; import org.adempiere.webui.adwindow.ADTabpanel; import org.adempiere.webui.adwindow.GridView; import org.adempiere.webui.adwindow.QuickGridView; @@ -108,9 +109,20 @@ public class CustomizeGridViewDialog extends Window { /** * show grid view customization dialog for tabPanel * @param tabPanel - * @return true if saved is ok + * @return ignore the return value, it is not working correctly + * @deprecated */ public static boolean onCustomize(ADTabpanel tabPanel) { + onCustomize(tabPanel, null); + return true; + } + + /** + * Show grid view customization dialog for tabPanel + * @param tabPanel + * @param callback + */ + public static void onCustomize(ADTabpanel tabPanel, Callback callback) { Columns columns = tabPanel.getGridView().getListbox().getColumns(); List columnList = columns.getChildren(); GridField[] fields = tabPanel.getGridView().getFields(); @@ -130,7 +142,7 @@ public class CustomizeGridViewDialog extends Window { gridFieldIds.add(fields[i].getAD_Field_ID()); } - return showCustomize(0, tabPanel.getGridTab().getAD_Tab_ID(), columnsWidth,gridFieldIds,tabPanel.getGridView(), null, false); + showCustomize(0, tabPanel.getGridTab().getAD_Tab_ID(), columnsWidth,gridFieldIds,tabPanel.getGridView(), null, false, callback); } /** @@ -141,10 +153,30 @@ public class CustomizeGridViewDialog extends Window { * @param gridFieldIds list fieldId current display in gridview * @param gridPanel * @param isQuickForm - * @param quickGridView + * @param quickGridView + * @return ignore the return value, it is not working correctly + * @deprecated */ public static boolean showCustomize(int WindowNo, int AD_Tab_ID, Map columnsWidth, ArrayList gridFieldIds, GridView gridPanel, QuickGridView quickGridView, boolean isQuickForm) + { + showCustomize(WindowNo, AD_Tab_ID, columnsWidth, gridFieldIds, gridPanel, quickGridView, isQuickForm, null); + return true; + } + + /** + * Show User customize (modal) + * @param WindowNo window no + * @param AD_Tab_ID + * @param columnsWidth + * @param gridFieldIds list fieldId current display in gridview + * @param gridPanel + * @param quickGridView + * @param isQuickForm + * @param callback + */ + public static void showCustomize(int WindowNo, int AD_Tab_ID, Map columnsWidth, ArrayList gridFieldIds, GridView gridPanel, + QuickGridView quickGridView, boolean isQuickForm, Callback callback) { CustomizeGridViewDialog customizeWindow = new CustomizeGridViewDialog(WindowNo, AD_Tab_ID, Env.getAD_User_ID(Env.getCtx()), columnsWidth, gridFieldIds, isQuickForm); @@ -156,8 +188,11 @@ public class CustomizeGridViewDialog extends Window { { customizeWindow.setGridPanel(gridPanel); } + customizeWindow.addCallback(Window.AFTER_PAGE_DETACHED, t -> { + if (callback != null) + callback.onCallback(customizeWindow.isSaved()); + }); AEnv.showWindow(customizeWindow); - return customizeWindow.isSaved(); } // showCustomize /**