From 79f99b8d81d6a2026eecf53695524fb2e36e1ed0 Mon Sep 17 00:00:00 2001 From: Carlos Ruiz Date: Fri, 15 Aug 2014 08:57:05 +0200 Subject: [PATCH] IDEMPIERE-2112 improve shortcuts for master detail data entry windows / WIP, enabled shortcut Shift+Alt+N for new detail button --- .../adempiere/webui/adwindow/BreadCrumb.java | 8 +- .../adempiere/webui/adwindow/DetailPane.java | 87 +++++++++++++++---- .../webui/component/ToolBarButton.java | 8 +- 3 files changed, 78 insertions(+), 25 deletions(-) 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 40e60b9353..d5fb79fa6d 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 @@ -76,7 +76,6 @@ public class BreadCrumb extends Div implements EventListener { private int windowNo; private HashMap buttons = new HashMap(); - private Map altKeyMap = new HashMap(); private DataStatusEvent m_dse; @@ -128,12 +127,7 @@ public class BreadCrumb extends Div implements EventListener { btnLast = createButton("Last", "Last", "Last"); btnLast.setTooltiptext(btnLast.getTooltiptext()+" Alt+End"); toolbar.appendChild(btnLast); - - altKeyMap.put(KeyEvent.UP, btnPrevious); - altKeyMap.put(KeyEvent.DOWN, btnNext); - altKeyMap.put(KeyEvent.PAGE_UP, btnFirst); - altKeyMap.put(KeyEvent.PAGE_DOWN, btnLast); - + toolbar.setStyle("background-image: none; background-color: transparent; border: none;"); setWidgetAttribute(AdempiereWebUI.WIDGET_INSTANCE_NAME, "breadcrumb"); 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 c277569c5c..460671f875 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 @@ -8,6 +8,7 @@ import java.util.List; import java.util.Map; import org.adempiere.webui.LayoutUtils; +import org.adempiere.webui.component.ADTabListModel.ADTabLabel; import org.adempiere.webui.component.Label; import org.adempiere.webui.component.Panel; import org.adempiere.webui.component.Tab; @@ -16,13 +17,13 @@ import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.ToolBar; import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.component.Window; -import org.adempiere.webui.component.ADTabListModel.ADTabLabel; import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.theme.ThemeManager; import org.compiere.util.Env; import org.compiere.util.Msg; import org.compiere.util.Util; import org.zkoss.zhtml.Text; +import org.zkoss.zk.au.out.AuScript; import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Execution; import org.zkoss.zk.ui.Executions; @@ -31,6 +32,7 @@ import org.zkoss.zk.ui.Page; import org.zkoss.zk.ui.event.Event; import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.event.KeyEvent; import org.zkoss.zk.ui.sys.ExecutionCtrl; import org.zkoss.zk.ui.util.Clients; import org.zkoss.zul.Div; @@ -45,6 +47,10 @@ import org.zkoss.zul.Toolbar; * */ public class DetailPane extends Panel implements EventListener, IdSpace { + /** + * + */ + private static final long serialVersionUID = -5714780894880069158L; private static final String BTN_PROCESS_ID = "BtnProcess"; @@ -67,11 +73,10 @@ public class DetailPane extends Panel implements EventListener, IdSpace { private static final String NEW_IMAGE = "images/New16.png"; private static final String PROCESS_IMAGE = "images/Process16.png"; - /** - * generated serial id - */ - private static final long serialVersionUID = -7914602940626352282L; - + private ToolBarButton btnNew; + private long prevKeyEventTime = 0; + private KeyEvent prevKeyEvent; + private Tabbox tabbox; private EventListener eventListener; @@ -251,19 +256,19 @@ public class DetailPane extends Panel implements EventListener, IdSpace { tp.setSclass("adwindow-detailpane-tabpanel"); ToolBar toolbar = new ToolBar(); tp.appendChild(toolbar); - ToolBarButton button = new ToolBarButton(); - - button = new ToolBarButton(); - button.setImage(ThemeManager.getThemeResource(NEW_IMAGE)); - button.setId(BTN_NEW_ID); - toolbar.appendChild(button); - button.addEventListener(Events.ON_CLICK, new EventListener() { + btnNew = new ToolBarButton(); + btnNew.setImage(ThemeManager.getThemeResource(NEW_IMAGE)); + btnNew.setId(BTN_NEW_ID); + toolbar.appendChild(btnNew); + btnNew.addEventListener(Events.ON_CLICK, new EventListener() { @Override public void onEvent(Event event) throws Exception { onNew(); } }); - button.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "New"))); + btnNew.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "New")) + " Shift+Alt+N"); + + ToolBarButton button = new ToolBarButton(); button = new ToolBarButton(); button.setImage(ThemeManager.getThemeResource(EDIT_IMAGE)); @@ -483,7 +488,25 @@ public class DetailPane extends Panel implements EventListener, IdSpace { return; } LayoutUtils.redraw(this); - } + } else if (event.getName().equals(Events.ON_CTRL_KEY)) { + KeyEvent keyEvent = (KeyEvent) event; + if (LayoutUtils.isReallyVisible(this)) { + //filter same key event that is too close + //firefox fire key event twice when grid is visible + long time = System.currentTimeMillis(); + if (prevKeyEvent != null && prevKeyEventTime > 0 && + prevKeyEvent.getKeyCode() == keyEvent.getKeyCode() && + prevKeyEvent.getTarget() == keyEvent.getTarget() && + prevKeyEvent.isAltKey() == keyEvent.isAltKey() && + prevKeyEvent.isCtrlKey() == keyEvent.isCtrlKey() && + prevKeyEvent.isShiftKey() == keyEvent.isShiftKey()) { + if ((time - prevKeyEventTime) <= 300) { + return; + } + } + this.onCtrlKeyEvent(keyEvent); + } + } } protected void createPopupContent(String status) { @@ -518,6 +541,17 @@ public class DetailPane extends Panel implements EventListener, IdSpace { super.onPageDetached(page); if (msgPopup != null) msgPopup.detach(); + try { + SessionManager.getSessionApplication().getKeylistener().removeEventListener(Events.ON_CTRL_KEY, this); + } catch (Exception e){} + } + + @Override + public void onPageAttached(Page newpage, Page oldpage) { + super.onPageAttached(newpage, oldpage); + if (newpage != null) { + SessionManager.getSessionApplication().getKeylistener().addEventListener(Events.ON_CTRL_KEY, this); + } } /* (non-Javadoc) @@ -715,4 +749,27 @@ public class DetailPane extends Panel implements EventListener, IdSpace { Event openEvent = new Event(ON_NEW_EVENT, DetailPane.this); eventListener.onEvent(openEvent); } + + public static final int VK_N = 0x4E; + private void onCtrlKeyEvent(KeyEvent keyEvent) { + ToolBarButton btn = null; + if (keyEvent.isAltKey() && !keyEvent.isCtrlKey() && keyEvent.isShiftKey()) { // Shift+Alt key + if (keyEvent.getKeyCode() == VK_N) { // Shift+Alt+N + btn = btnNew; + } + } + if (btn != null) { + prevKeyEventTime = System.currentTimeMillis(); + prevKeyEvent = keyEvent; + keyEvent.stopPropagation(); + if (!btn.isDisabled() && btn.isVisible()) { + Events.sendEvent(btn, new Event(Events.ON_CLICK, btn)); + //client side script to close combobox popup + String script = "var w=zk.Widget.$('#" + btn.getUuid()+"'); " + + "zWatch.fire('onFloatUp', w);"; + Clients.response(new AuScript(script)); + } + } + } + } diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ToolBarButton.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ToolBarButton.java index 71eb9838d2..bbb84f5770 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ToolBarButton.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/component/ToolBarButton.java @@ -25,9 +25,11 @@ import org.adempiere.webui.LayoutUtils; */ public class ToolBarButton extends org.zkoss.zul.Toolbarbutton { - - private static final long serialVersionUID = 0L; - + /** + * + */ + private static final long serialVersionUID = -1214319982911389339L; + private String name; private boolean pressed; // Elaine 2008/12/09