IDEMPIERE-2112 improve shortcuts / implement Alt-X shortcut to close process/report dialog and report viewer window

This commit is contained in:
Carlos Ruiz 2015-05-25 20:23:26 -05:00
parent 44b07db53f
commit 4b0793a6e2
3 changed files with 162 additions and 17 deletions

View File

@ -67,9 +67,11 @@ import org.zkoss.zhtml.Tr;
import org.zkoss.zk.au.out.AuEcho; import org.zkoss.zk.au.out.AuEcho;
import org.zkoss.zk.au.out.AuScript; import org.zkoss.zk.au.out.AuScript;
import org.zkoss.zk.ui.Component; 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.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.KeyEvent;
import org.zkoss.zk.ui.util.Clients; import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.A; import org.zkoss.zul.A;
import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Borderlayout;
@ -99,13 +101,13 @@ import com.lowagie.text.pdf.PdfWriter;
*/ */
public class ProcessDialog extends AbstractProcessDialog implements EventListener<Event>, IHelpContext public class ProcessDialog extends AbstractProcessDialog implements EventListener<Event>, IHelpContext
{ {
/**
*
*/
private static final long serialVersionUID = -6728929130788829223L;
public static final String ON_INITIAL_FOCUS_EVENT = "onInitialFocus"; 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;"; private static final String MESSAGE_DIV_STYLE = "max-height: 150pt; overflow: auto; margin: 10px;";
/** Logger */ /** Logger */
@ -127,6 +129,11 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
private Grid southRowPanel = GridFactory.newGridLayout(); 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 * Dialog to start a process/report
* @param ctx * @param ctx
@ -142,9 +149,9 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
public ProcessDialog (int AD_Process_ID, boolean isSOTrx) public ProcessDialog (int AD_Process_ID, boolean isSOTrx)
{ {
log.info("Process=" + AD_Process_ID ); log.info("Process=" + AD_Process_ID );
int WindowNo = SessionManager.getAppDesktop().registerWindow(this); m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
this.setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, WindowNo); this.setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, m_WindowNo);
Env.setContext(Env.getCtx(), WindowNo, "IsSOTrx", isSOTrx ? "Y" : "N"); Env.setContext(Env.getCtx(), m_WindowNo, "IsSOTrx", isSOTrx ? "Y" : "N");
try try
{ {
MProcess process = MProcess.get(Env.getCtx(), AD_Process_ID); MProcess process = MProcess.get(Env.getCtx(), AD_Process_ID);
@ -153,7 +160,7 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
showLastRun = true; showLastRun = true;
initComponents(); 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(); querySaved();
addEventListener(WindowContainer.ON_WINDOW_CONTAINER_SELECTION_CHANGED_EVENT, this); addEventListener(WindowContainer.ON_WINDOW_CONTAINER_SELECTION_CHANGED_EVENT, this);
addEventListener(ON_INITIAL_FOCUS_EVENT, this); addEventListener(ON_INITIAL_FOCUS_EVENT, this);
@ -178,6 +185,22 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
fSavedName.setValue(""); 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() { private void initComponents() {
this.setStyle("position: absolute; width: 100%; height: 100%"); this.setStyle("position: absolute; width: 100%; height: 100%");
Borderlayout layout = new Borderlayout(); Borderlayout layout = new Borderlayout();
@ -371,11 +394,40 @@ public class ProcessDialog extends AbstractProcessDialog implements EventListene
bOK.focus(); 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 { } else {
super.onEvent(event); 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) { public Comboitem getComboItem( String value) {
Comboitem item = null; Comboitem item = null;
for (int i = 0; i < fSavedName.getItems().size(); i++) { for (int i = 0; i < fSavedName.getItems().size(); i++) {

View File

@ -23,11 +23,13 @@ import net.sf.jasperreports.engine.export.JRXlsExporterParameter;
import net.sf.jasperreports.engine.util.LocalJasperReportsContext; import net.sf.jasperreports.engine.util.LocalJasperReportsContext;
import org.adempiere.exceptions.AdempiereException; import org.adempiere.exceptions.AdempiereException;
import org.adempiere.webui.LayoutUtils;
import org.adempiere.webui.apps.AEnv; import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.Listbox; import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.component.Window; import org.adempiere.webui.component.Window;
import org.adempiere.webui.desktop.IDesktop;
import org.adempiere.webui.panel.ITabOnCloseHandler; import org.adempiere.webui.panel.ITabOnCloseHandler;
import org.adempiere.webui.session.SessionManager; import org.adempiere.webui.session.SessionManager;
import org.adempiere.webui.theme.ThemeManager; import org.adempiere.webui.theme.ThemeManager;
@ -42,9 +44,11 @@ import org.compiere.util.Util;
import org.zkoss.util.media.AMedia; import org.zkoss.util.media.AMedia;
import org.zkoss.zk.ui.Component; import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions; 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.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.KeyEvent;
import org.zkoss.zul.Borderlayout; import org.zkoss.zul.Borderlayout;
import org.zkoss.zul.Center; import org.zkoss.zul.Center;
import org.zkoss.zul.Iframe; import org.zkoss.zul.Iframe;
@ -58,7 +62,7 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
/** /**
* *
*/ */
private static final long serialVersionUID = -1250003381099609830L; private static final long serialVersionUID = -7047317766671393738L;
private JasperPrint jasperPrint; private JasperPrint jasperPrint;
private Listbox previewType = new Listbox(); private Listbox previewType = new Listbox();
@ -72,6 +76,8 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
/** Window No */ /** Window No */
private int m_WindowNo = -1; private int m_WindowNo = -1;
private long prevKeyEventTime = 0;
private KeyEvent prevKeyEvent;
private String m_title; // local title - embedded windows clear the title private String m_title; // local title - embedded windows clear the title
@ -81,9 +87,26 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
m_title = title; m_title = title;
this.jasperPrint = jasperPrint; this.jasperPrint = jasperPrint;
m_WindowNo = SessionManager.getAppDesktop().registerWindow(this); m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, m_WindowNo);
init(); 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() { private void init() {
final boolean isCanExport=MRole.getDefault().isCanExport(); final boolean isCanExport=MRole.getDefault().isCanExport();
defaultType = MSysConfig.getValue(MSysConfig.ZK_REPORT_JASPER_OUTPUT_TYPE, "PDF", defaultType = MSysConfig.getValue(MSysConfig.ZK_REPORT_JASPER_OUTPUT_TYPE, "PDF",
@ -229,11 +252,40 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
} // cmd_sendMail } // cmd_sendMail
public void onEvent(Event event) throws Exception { 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); 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 { private void renderReport() throws Exception {
String reportType; String reportType;
ClassLoader cl = Thread.currentThread().getContextClassLoader(); ClassLoader cl = Thread.currentThread().getContextClassLoader();

View File

@ -48,6 +48,7 @@ import org.adempiere.webui.component.Mask;
import org.adempiere.webui.component.Tabpanel; import org.adempiere.webui.component.Tabpanel;
import org.adempiere.webui.component.ToolBarButton; import org.adempiere.webui.component.ToolBarButton;
import org.adempiere.webui.component.Window; import org.adempiere.webui.component.Window;
import org.adempiere.webui.desktop.IDesktop;
import org.adempiere.webui.event.DialogEvents; import org.adempiere.webui.event.DialogEvents;
import org.adempiere.webui.event.DrillEvent; import org.adempiere.webui.event.DrillEvent;
import org.adempiere.webui.event.ZoomEvent; 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.Event;
import org.zkoss.zk.ui.event.EventListener; import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events; 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.ext.render.DynamicMedia;
import org.zkoss.zk.ui.util.Clients; import org.zkoss.zk.ui.util.Clients;
import org.zkoss.zul.A; import org.zkoss.zul.A;
@ -134,10 +136,12 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
/** /**
* *
*/ */
private static final long serialVersionUID = 3463776496724974142L; private static final long serialVersionUID = 946000686957291327L;
/** Window No */ /** Window No */
private int m_WindowNo = -1; private int m_WindowNo = -1;
private long prevKeyEventTime = 0;
private KeyEvent prevKeyEvent;
/** Print Context */ /** Print Context */
private Properties m_ctx; private Properties m_ctx;
/** Setting Values */ /** Setting Values */
@ -203,6 +207,7 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
init = false; init = false;
m_WindowNo = SessionManager.getAppDesktop().registerWindow(this); m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, m_WindowNo);
Env.setContext(re.getCtx(), m_WindowNo, "_WinInfo_IsReportViewer", "Y"); Env.setContext(re.getCtx(), m_WindowNo, "_WinInfo_IsReportViewer", "Y");
m_reportEngine = re; m_reportEngine = re;
m_AD_Table_ID = re.getPrintFormat().getAD_Table_ID(); m_AD_Table_ID = re.getPrintFormat().getAD_Table_ID();
@ -218,8 +223,6 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
addEventListener(ON_RENDER_REPORT_EVENT, this); addEventListener(ON_RENDER_REPORT_EVENT, this);
} }
@Override @Override
public void onPageAttached(Page newpage, Page oldpage) { public void onPageAttached(Page newpage, Page oldpage) {
@ -230,6 +233,7 @@ public class ZkReportViewer extends Window implements EventListener<Event>, ITab
m_ctx = m_reportEngine.getCtx(); m_ctx = m_reportEngine.getCtx();
init(); init();
dynInit(); dynInit();
SessionManager.getSessionApplication().getKeylistener().addEventListener(Events.ON_CTRL_KEY, this);
} }
catch(Exception e) catch(Exception e)
{ {
@ -240,6 +244,14 @@ public class ZkReportViewer extends Window implements EventListener<Event>, 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() { private void init() {
Borderlayout layout = new Borderlayout(); Borderlayout layout = new Borderlayout();
layout.setStyle("position: absolute; height: 97%; width: 98%; border:none; padding:none; margin:none;"); 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<Event>, ITab
else if (event.getName().equals(ON_RENDER_REPORT_EVENT)) else if (event.getName().equals(ON_RENDER_REPORT_EVENT))
{ {
onRenderReportEvent(); 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);
}
} }
} }