From 19d7e7b8553dbf77c58341896477f34cf2c2a575 Mon Sep 17 00:00:00 2001 From: hieplq Date: Sun, 15 Mar 2015 01:25:36 +0700 Subject: [PATCH] IDEMPIERE-2499:long task (ZkReportViewerProvider.openViewer) in process make GUI lock fix:NPE, and improve long process --- .../src/org/compiere/print/ReportEngine.java | 4 +- .../webui/window/ZkReportViewer.java | 11 ++++-- .../webui/window/ZkReportViewerProvider.java | 38 +++++++++---------- 3 files changed, 26 insertions(+), 27 deletions(-) diff --git a/org.adempiere.base/src/org/compiere/print/ReportEngine.java b/org.adempiere.base/src/org/compiere/print/ReportEngine.java index 34d0c8a082..6a232aaa45 100644 --- a/org.adempiere.base/src/org/compiere/print/ReportEngine.java +++ b/org.adempiere.base/src/org/compiere/print/ReportEngine.java @@ -338,9 +338,9 @@ public class ReportEngine implements PrintServiceAttributeListener */ public Properties getCtx() { - return getLayout().getCtx(); + return m_ctx; } // getCtx - + /** * Get Row Count * @return row count 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 2d0a8ee37a..5a91698147 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 @@ -229,9 +229,6 @@ public class ZkReportViewer extends Window implements EventListener, ITab m_ctx = m_reportEngine.getCtx(); init(); dynInit(); - - if (!ArchiveEngine.isValid(m_reportEngine.getLayout())) - log.warning("Cannot archive Document"); } catch(Exception e) { @@ -467,7 +464,7 @@ public class ZkReportViewer extends Window implements EventListener, ITab future = Adempiere.getThreadPoolExecutor().submit(new DesktopRunnable(new XLSRendererRunnable(this),getDesktop())); } } - + private void onPreviewReport() { try { if (future != null) { @@ -1306,6 +1303,8 @@ public class ZkReportViewer extends Window implements EventListener, ITab @Override protected void doRun() { try { + if (!ArchiveEngine.isValid(viewer.m_reportEngine.getLayout())) + log.warning("Cannot archive Document"); String path = System.getProperty("java.io.tmpdir"); String prefix = viewer.makePrefix(viewer.m_reportEngine.getName()); if (log.isLoggable(Level.FINE)) @@ -1351,6 +1350,8 @@ public class ZkReportViewer extends Window implements EventListener, ITab @Override protected void doRun() { try { + if (!ArchiveEngine.isValid(viewer.m_reportEngine.getLayout())) + log.warning("Cannot archive Document"); String path = System.getProperty("java.io.tmpdir"); String prefix = viewer.makePrefix(viewer.m_reportEngine.getName()); if (log.isLoggable(Level.FINE)) @@ -1395,6 +1396,8 @@ public class ZkReportViewer extends Window implements EventListener, ITab @Override protected void doRun() { try { + if (!ArchiveEngine.isValid(viewer.m_reportEngine.getLayout())) + log.warning("Cannot archive Document"); String path = System.getProperty("java.io.tmpdir"); String prefix = viewer.makePrefix(viewer.m_reportEngine.getName()); if (log.isLoggable(Level.FINE)) diff --git a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewerProvider.java b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewerProvider.java index dbf363144d..3d6e85ffbc 100644 --- a/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewerProvider.java +++ b/org.adempiere.ui.zk/WEB-INF/src/org/adempiere/webui/window/ZkReportViewerProvider.java @@ -17,7 +17,9 @@ package org.adempiere.webui.window; import org.adempiere.util.ContextRunnable; +import org.adempiere.webui.LayoutUtils; import org.adempiere.webui.apps.AEnv; +import org.adempiere.webui.apps.DesktopRunnable; import org.adempiere.webui.component.Window; import org.adempiere.webui.part.WindowContainer; import org.adempiere.webui.session.SessionManager; @@ -34,32 +36,26 @@ import org.zkoss.zk.ui.Executions; public class ZkReportViewerProvider implements ReportViewerProvider { public void openViewer(final ReportEngine report) { - final Runnable runnable = new Runnable() { - @Override - public void run() { - Window viewer = new ZkReportViewer(report, report.getName()); - - viewer.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED); - viewer.setAttribute(Window.INSERT_POSITION_KEY, Window.INSERT_NEXT); - viewer.setAttribute(WindowContainer.DEFER_SET_SELECTED_TAB, Boolean.TRUE); - SessionManager.getAppDesktop().showWindow(viewer); - } - }; - // IDEMPIERE-2499 // detect ui thread by value of Executions.getCurrent(), not office method but work if (Executions.getCurrent() != null){ - Adempiere.getThreadPoolExecutor().submit(new ContextRunnable(){ - protected void doRun(){ - // load layout, with big report it's heavy job, do in non ui thread to don't lock gui - report.getLayout(); - AEnv.executeAsyncDesktopTask(runnable); + openReportViewWindow (report); + }else { + AEnv.executeAsyncDesktopTask(new Runnable() { + @Override + public void run() { + openReportViewWindow (report); } }); - }else{ - // load layout in non ui thread before run into ui thread - report.getLayout(); - AEnv.executeAsyncDesktopTask(runnable); } } + + protected void openReportViewWindow (ReportEngine report) { + Window viewer = new ZkReportViewer(report, report.getName()); + + viewer.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED); + viewer.setAttribute(Window.INSERT_POSITION_KEY, Window.INSERT_NEXT); + viewer.setAttribute(WindowContainer.DEFER_SET_SELECTED_TAB, Boolean.TRUE); + SessionManager.getAppDesktop().showWindow(viewer); + } } \ No newline at end of file