diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java index 29917b534a..910ed66f15 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/apps/ProcessDialog.java @@ -67,9 +67,11 @@ import org.zkoss.zhtml.Tr; import org.zkoss.zk.au.out.AuEcho; import org.zkoss.zk.au.out.AuScript; import org.zkoss.zk.ui.Component; +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.util.Clients; import org.zkoss.zul.A; import org.zkoss.zul.Borderlayout; @@ -99,13 +101,13 @@ import com.lowagie.text.pdf.PdfWriter; */ public class ProcessDialog extends AbstractProcessDialog implements EventListener, IHelpContext { + /** + * + */ + private static final long serialVersionUID = -6728929130788829223L; + public static final String ON_INITIAL_FOCUS_EVENT = "onInitialFocus"; - /** - * generate serial version ID - */ - private static final long serialVersionUID = 3329046204196602797L; - private static final String MESSAGE_DIV_STYLE = "max-height: 150pt; overflow: auto; margin: 10px;"; /** Logger */ @@ -127,6 +129,11 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene private Grid southRowPanel = GridFactory.newGridLayout(); + /** Window No */ + private int m_WindowNo = -1; + private long prevKeyEventTime = 0; + private KeyEvent prevKeyEvent; + /** * Dialog to start a process/report * @param ctx @@ -142,9 +149,9 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene public ProcessDialog (int AD_Process_ID, boolean isSOTrx) { log.info("Process=" + AD_Process_ID ); - int WindowNo = SessionManager.getAppDesktop().registerWindow(this); - this.setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, WindowNo); - Env.setContext(Env.getCtx(), WindowNo, "IsSOTrx", isSOTrx ? "Y" : "N"); + m_WindowNo = SessionManager.getAppDesktop().registerWindow(this); + this.setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, m_WindowNo); + Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", isSOTrx ? "Y" : "N"); try { MProcess process = MProcess.get(Env.getCtx(), AD_Process_ID); @@ -153,7 +160,7 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene showLastRun = true; initComponents(); - init(Env.getCtx(), WindowNo, AD_Process_ID, null, "70%", false, false); + init(Env.getCtx(), m_WindowNo, AD_Process_ID, null, "70%", false, false); querySaved(); addEventListener(WindowContainer.ON_WINDOW_CONTAINER_SELECTION_CHANGED_EVENT, this); addEventListener(ON_INITIAL_FOCUS_EVENT, this); @@ -178,6 +185,22 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene fSavedName.setValue(""); } + @Override + public void onPageAttached(Page newpage, Page oldpage) { + super.onPageAttached(newpage, oldpage); + try { + SessionManager.getSessionApplication().getKeylistener().addEventListener(Events.ON_CTRL_KEY, this); + } catch (Exception e) {} + } + + @Override + public void onPageDetached(Page page) { + super.onPageDetached(page); + try { + SessionManager.getSessionApplication().getKeylistener().removeEventListener(Events.ON_CTRL_KEY, this); + } catch (Exception e) {} + } + private void initComponents() { this.setStyle("position: absolute; width: 100%; height: 100%"); Borderlayout layout = new Borderlayout(); @@ -371,11 +394,40 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene bOK.focus(); } } + } 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); + } } else { super.onEvent(event); } } + private void onCtrlKeyEvent(KeyEvent keyEvent) { + if (keyEvent.isAltKey() && keyEvent.getKeyCode() == 0x58) { // Alt-X + if (m_WindowNo > 0) { + prevKeyEventTime = System.currentTimeMillis(); + prevKeyEvent = keyEvent; + keyEvent.stopPropagation(); + SessionManager.getAppDesktop().closeWindow(m_WindowNo); + } + } + } + public Comboitem getComboItem( String value) { Comboitem item = null; for (int i = 0; i < fSavedName.getItems().size(); i++) { diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java index c4eeafe702..9e6e4d967c 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkJRViewer.java @@ -23,11 +23,13 @@ import net.sf.jasperreports.engine.export.JRXlsExporterParameter; import net.sf.jasperreports.engine.util.LocalJasperReportsContext; import org.adempiere.exceptions.AdempiereException; +import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.component.Listbox; import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.component.Window; +import org.adempiere.webui.desktop.IDesktop; import org.adempiere.webui.panel.ITabOnCloseHandler; import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.theme.ThemeManager; @@ -42,9 +44,11 @@ import org.compiere.util.Util; import org.zkoss.util.media.AMedia; import org.zkoss.zk.ui.Component; 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.EventListener; import org.zkoss.zk.ui.event.Events; +import org.zkoss.zk.ui.event.KeyEvent; import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Center; import org.zkoss.zul.Iframe; @@ -58,7 +62,7 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl /** * */ - private static final long serialVersionUID = -1250003381099609830L; + private static final long serialVersionUID = -7047317766671393738L; private JasperPrint jasperPrint; private Listbox previewType = new Listbox(); @@ -72,6 +76,8 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl /** Window No */ private int m_WindowNo = -1; + private long prevKeyEventTime = 0; + private KeyEvent prevKeyEvent; private String m_title; // local title - embedded windows clear the title @@ -81,9 +87,26 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl m_title = title; this.jasperPrint = jasperPrint; m_WindowNo = SessionManager.getAppDesktop().registerWindow(this); + setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, m_WindowNo); init(); } - + + @Override + public void onPageAttached(Page newpage, Page oldpage) { + super.onPageAttached(newpage, oldpage); + try { + SessionManager.getSessionApplication().getKeylistener().addEventListener(Events.ON_CTRL_KEY, this); + } catch (Exception e) {} + } + + @Override + public void onPageDetached(Page page) { + super.onPageDetached(page); + try { + SessionManager.getSessionApplication().getKeylistener().removeEventListener(Events.ON_CTRL_KEY, this); + } catch (Exception e) {} + } + private void init() { final boolean isCanExport=MRole.getDefault().isCanExport(); defaultType = MSysConfig.getValue(MSysConfig.ZK_REPORT_JASPER_OUTPUT_TYPE, "PDF", @@ -229,11 +252,40 @@ public class ZkJRViewer extends Window implements EventListener, ITabOnCl } // cmd_sendMail public void onEvent(Event event) throws Exception { - if(event.getName().equals(Events.ON_CLICK) || event.getName().equals(Events.ON_SELECT)) + if (event.getName().equals(Events.ON_CLICK) || event.getName().equals(Events.ON_SELECT)) { actionPerformed(event); - + } 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); + } + } } - + + private void onCtrlKeyEvent(KeyEvent keyEvent) { + if (keyEvent.isAltKey() && keyEvent.getKeyCode() == 0x58) { // Alt-X + if (m_WindowNo > 0) { + prevKeyEventTime = System.currentTimeMillis(); + prevKeyEvent = keyEvent; + keyEvent.stopPropagation(); + SessionManager.getAppDesktop().closeWindow(m_WindowNo); + } + } + } + private void renderReport() throws Exception { String reportType; ClassLoader cl = Thread.currentThread().getContextClassLoader(); diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java index 5f82d79f2a..75d293dc37 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewer.java @@ -48,6 +48,7 @@ import org.adempiere.webui.component.Mask; import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.component.Window; +import org.adempiere.webui.desktop.IDesktop; import org.adempiere.webui.event.DialogEvents; import org.adempiere.webui.event.DrillEvent; import org.adempiere.webui.event.ZoomEvent; @@ -91,6 +92,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.ext.render.DynamicMedia; import org.zkoss.zk.ui.util.Clients; import org.zkoss.zul.A; @@ -134,10 +136,12 @@ public class ZkReportViewer extends Window implements EventListener, ITab /** * */ - private static final long serialVersionUID = 3463776496724974142L; + private static final long serialVersionUID = 946000686957291327L; /** Window No */ private int m_WindowNo = -1; + private long prevKeyEventTime = 0; + private KeyEvent prevKeyEvent; /** Print Context */ private Properties m_ctx; /** Setting Values */ @@ -203,6 +207,7 @@ public class ZkReportViewer extends Window implements EventListener, ITab init = false; m_WindowNo = SessionManager.getAppDesktop().registerWindow(this); + setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, m_WindowNo); Env.setContext(re.getCtx(), m_WindowNo, "_WinInfo_IsReportViewer", "Y"); m_reportEngine = re; m_AD_Table_ID = re.getPrintFormat().getAD_Table_ID(); @@ -218,8 +223,6 @@ public class ZkReportViewer extends Window implements EventListener, ITab addEventListener(ON_RENDER_REPORT_EVENT, this); } - - @Override public void onPageAttached(Page newpage, Page oldpage) { @@ -230,6 +233,7 @@ public class ZkReportViewer extends Window implements EventListener, ITab m_ctx = m_reportEngine.getCtx(); init(); dynInit(); + SessionManager.getSessionApplication().getKeylistener().addEventListener(Events.ON_CTRL_KEY, this); } catch(Exception e) { @@ -240,6 +244,14 @@ public class ZkReportViewer extends Window implements EventListener, ITab } } + @Override + public void onPageDetached(Page page) { + super.onPageDetached(page); + try { + SessionManager.getSessionApplication().getKeylistener().removeEventListener(Events.ON_CTRL_KEY, this); + } catch (Exception e) {} + } + private void init() { Borderlayout layout = new Borderlayout(); layout.setStyle("position: absolute; height: 97%; width: 98%; border:none; padding:none; margin:none;"); @@ -735,6 +747,35 @@ public class ZkReportViewer extends Window implements EventListener, ITab else if (event.getName().equals(ON_RENDER_REPORT_EVENT)) { onRenderReportEvent(); + } 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); + } + } + } + + private void onCtrlKeyEvent(KeyEvent keyEvent) { + if (keyEvent.isAltKey() && keyEvent.getKeyCode() == 0x58) { // Alt-X + if (m_WindowNo > 0) { + prevKeyEventTime = System.currentTimeMillis(); + prevKeyEvent = keyEvent; + keyEvent.stopPropagation(); + SessionManager.getAppDesktop().closeWindow(m_WindowNo); + } } }