From 361c3f49827e4fa02d357fb4de0f0951db8857af Mon Sep 17 00:00:00 2001 From: Heng Sin Low Date: Wed, 13 Jun 2007 05:20:23 +0000 Subject: [PATCH] [ 1684853 ] Add Print Preview button [ 1729327 ] Reporting Functionality ( zk client ) --- client/src/org/compiere/apps/APanel.java | 17 ++- client/src/org/compiere/apps/ProcessCtl.java | 17 +-- .../{Report16.gif => PrintPreview16.gif} | Bin .../{Report24.gif => PrintPreview24.gif} | Bin client/src/org/compiere/images/Report16.png | Bin 0 -> 392 bytes client/src/org/compiere/images/Report24.png | Bin 0 -> 654 bytes client/src/org/compiere/print/ReportCtl.java | 101 +++++++++++++----- .../compiere/print/ReportViewerProvider.java | 28 +++++ .../compiere/print/SwingViewerProvider.java | 38 +++++++ 9 files changed, 166 insertions(+), 35 deletions(-) rename client/src/org/compiere/images/{Report16.gif => PrintPreview16.gif} (100%) rename client/src/org/compiere/images/{Report24.gif => PrintPreview24.gif} (100%) create mode 100644 client/src/org/compiere/images/Report16.png create mode 100644 client/src/org/compiere/images/Report24.png create mode 100644 client/src/org/compiere/print/ReportViewerProvider.java create mode 100644 client/src/org/compiere/print/SwingViewerProvider.java diff --git a/client/src/org/compiere/apps/APanel.java b/client/src/org/compiere/apps/APanel.java index 0a390942f2..a92c88a42b 100644 --- a/client/src/org/compiere/apps/APanel.java +++ b/client/src/org/compiere/apps/APanel.java @@ -159,7 +159,7 @@ public final class APanel extends CPanel } // jbInit private AppsAction aPrevious, aNext, aParent, aDetail, aFirst, aLast, - aNew, aCopy, aDelete, aPrint, + aNew, aCopy, aDelete, aPrint, aPrintPreview, aRefresh, aHistory, aAttachment, aChat, aMulti, aFind, aWorkflow, aZoomAcross, aRequest, aWinSize, aArchive; /** Ignore Button */ @@ -191,6 +191,7 @@ public final class APanel extends CPanel aScrShot = addAction("ScreenShot", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_PRINTSCREEN, Event.SHIFT_MASK), false); aReport = addAction("Report", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_F11, 0), false); aPrint = addAction("Print", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0), false); + aPrintPreview = addAction("PrintPreview", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_P, Event.SHIFT_MASK+Event.ALT_MASK), false); mFile.addSeparator(); aEnd = addAction("End", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.ALT_MASK), false); aLogout = addAction("Logout", mFile, KeyStroke.getKeyStroke(KeyEvent.VK_L, Event.SHIFT_MASK+Event.ALT_MASK), false); @@ -339,6 +340,7 @@ public final class APanel extends CPanel toolBar.addSeparator(); toolBar.add(aReport.getButton()); toolBar.add(aArchive.getButton()); + toolBar.add(aPrintPreview.getButton()); toolBar.add(aPrint.getButton()); toolBar.addSeparator(); if (m_isPersonalLock) @@ -1184,6 +1186,7 @@ public final class APanel extends CPanel } // Document Print aPrint.setEnabled(m_curTab.isPrinted()); + aPrintPreview.setEnabled(m_curTab.isPrinted()); // Query aFind.setPressed(m_curTab.isQueryActive()); @@ -1319,6 +1322,8 @@ public final class APanel extends CPanel cmd_report(); else if (cmd.equals(aPrint.getName())) cmd_print(); + else if (cmd.equals(aPrintPreview.getName())) + cmd_print(true); else if (cmd.equals(aEnd.getName())) cmd_end(false); else if (cmd.equals(aExit.getName())) @@ -1694,6 +1699,7 @@ public final class APanel extends CPanel } m_curTab.dataIgnore(); m_curGC.dynamicDisplay(0); + } // cmd_ignore /** @@ -1823,6 +1829,14 @@ public final class APanel extends CPanel * Print specific Report - or start default Report */ private void cmd_print() + { + cmd_print(false); + } + + /** + * Print specific Report - or start default Report + */ + private void cmd_print(boolean printPreview) { // Get process defined for this tab int AD_Process_ID = m_curTab.getAD_Process_ID(); @@ -1842,6 +1856,7 @@ public final class APanel extends CPanel ProcessInfo pi = new ProcessInfo (getTitle(), AD_Process_ID, table_ID, record_ID); pi.setAD_User_ID (Env.getAD_User_ID(m_ctx)); pi.setAD_Client_ID (Env.getAD_Client_ID(m_ctx)); + pi.setPrintPreview(printPreview); ProcessCtl.process(this, m_curWindowNo, pi, null); // calls lockUI, unlockUI } // cmd_print diff --git a/client/src/org/compiere/apps/ProcessCtl.java b/client/src/org/compiere/apps/ProcessCtl.java index a592e809b7..8a42b95b85 100644 --- a/client/src/org/compiere/apps/ProcessCtl.java +++ b/client/src/org/compiere/apps/ProcessCtl.java @@ -174,11 +174,13 @@ public class ProcessCtl implements Runnable pi.setAD_PInstance_ID (instance.getAD_PInstance_ID()); // Get Parameters - if (!parameter.saveParameters()) - { - pi.setSummary (Msg.getMsg(Env.getCtx(), "ProcessCancelled")); - pi.setError (true); - return null; + if (parameter != null) { + if (!parameter.saveParameters()) + { + pi.setSummary (Msg.getMsg(Env.getCtx(), "ProcessCancelled")); + pi.setError (true); + return null; + } } // execute @@ -258,6 +260,8 @@ public class ProcessCtl implements Runnable int AD_Workflow_ID = 0; boolean IsReport = false; boolean IsDirectPrint = false; + boolean isPrintPreview = m_pi.isPrintPreview(); + // String sql = "SELECT p.Name, p.ProcedureName,p.ClassName, p.AD_Process_ID," // 1..4 + " p.isReport,p.IsDirectPrint,p.AD_ReportView_ID,p.AD_Workflow_ID," // 5..8 @@ -297,7 +301,8 @@ public class ProcessCtl implements Runnable if ("Y".equals(rs.getString(5))) { IsReport = true; - if ("Y".equals(rs.getString(6)) && !Ini.isPropertyBool(Ini.P_PRINTPREVIEW)) + if ("Y".equals(rs.getString(6)) && !Ini.isPropertyBool(Ini.P_PRINTPREVIEW) + && !isPrintPreview ) IsDirectPrint = true; } AD_ReportView_ID = rs.getInt(7); diff --git a/client/src/org/compiere/images/Report16.gif b/client/src/org/compiere/images/PrintPreview16.gif similarity index 100% rename from client/src/org/compiere/images/Report16.gif rename to client/src/org/compiere/images/PrintPreview16.gif diff --git a/client/src/org/compiere/images/Report24.gif b/client/src/org/compiere/images/PrintPreview24.gif similarity index 100% rename from client/src/org/compiere/images/Report24.gif rename to client/src/org/compiere/images/PrintPreview24.gif diff --git a/client/src/org/compiere/images/Report16.png b/client/src/org/compiere/images/Report16.png new file mode 100644 index 0000000000000000000000000000000000000000..d18082e397e7e54f20721af768c4c2983258f1b4 GIT binary patch literal 392 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`Y)RhkE)4%caKYZ?lYt_f1s;*b z3=G`DAk4@xYmNj^kiEpy*OmP$HyOL$D9)yc9|lc|nKf<9@eUiWd>3GuTC!a5vdfWYEazjncPj5ZQX%+1 zt8B*4=d)!cdDz4wr^#OMYfqGz$1LDFF>|#>*O?AGil(WEs?wLLy{Gj2J_@opDm%`dlax3yA*@*N$G&*ukFv>P8+2CBWO(qz zD0k1@kN>hhb1_6`&wrCswzINE(evt-5C1B^STi2@PmdKI;Vst0PQB6!2kdN literal 0 HcmV?d00001 diff --git a/client/src/org/compiere/images/Report24.png b/client/src/org/compiere/images/Report24.png new file mode 100644 index 0000000000000000000000000000000000000000..c9baeda2c491d2c9e10d6145ce24147895fef3e3 GIT binary patch literal 654 zcmV;90&)F`P)B}SvxYBe0k!5D)eAcEL)Nze}_5T7a8Y&L`w0rofh8`n2p zM1+%pdO^!CUXIND6*#w$NA0+OMpdzlEn8tsr~`l>Km8i((pFb8@qks8p63B@@pO-+ z^V7WE`NoI($q2x^-F84^xasJ`%U4^Wh2uv$98JtJmo%Z^KX>2a{oeP-8Uy&!g?TcW z41Fs!_vU!A<+AzyR3KB^t>JZk(RM%DJC%4+G#ZV-Vy#baXbtI(>Cyes0Khpm3rSGb z2`z(EIU+$U3gW*JMk==6U}*OvXYi7rosV&MuR>a$d_OnsKBIyeOrF!lqe zUvxxJTiHa!2C)tl##W&Sa5|m-Cr?uV?0Me(hmRht9R_S?yM80`=8XiK0Z!O&21wev o;s6Hd0BxWJd 0) { ProcessInfo pi = new ProcessInfo ("", re.getPrintFormat().getJasperProcess_ID()); - + pi.setPrintPreview(!IsDirectPrint); // Execute Process ProcessCtl worker = ProcessCtl.process(parent, WindowNo, pi, null); if(worker == null) // Process has been canceled @@ -209,13 +237,11 @@ public class ReportCtl } else { + createOutput(re, !IsDirectPrint); if (IsDirectPrint) { - re.print (); ReportEngine.printConfirm (type, Record_ID); } - else - preview(re); } return true; @@ -243,10 +269,29 @@ public class ReportCtl return startDocumentPrint (ReportEngine.CHECK, C_PaySelectionCheck_ID, null, -1, IsDirectPrint); } // startCheckPrint - private static void preview(ReportEngine re) { - Viewer viewer = new Viewer(re); - JFrame top = Env.getWindow(0); - if (top instanceof AMenu) - ((AMenu)top).getWindowManager().add(viewer); + private static void createOutput(ReportEngine re, boolean printPreview) + { + if (printPreview) + preview(re); + else + re.print(); + } + + private static void preview(ReportEngine re) + { + ReportViewerProvider provider = getReportViewerProvider(); + provider.openViewer(re); + } + + public static void setReportViewerProvider(ReportViewerProvider provider) + { + if (provider == null) + throw new IllegalArgumentException("Cannot set report viewer provider to null"); + viewerProvider = provider; + } + + public static ReportViewerProvider getReportViewerProvider() + { + return viewerProvider; } } // ReportCtl diff --git a/client/src/org/compiere/print/ReportViewerProvider.java b/client/src/org/compiere/print/ReportViewerProvider.java new file mode 100644 index 0000000000..2c08a29926 --- /dev/null +++ b/client/src/org/compiere/print/ReportViewerProvider.java @@ -0,0 +1,28 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 2007 Adempiere, Inc. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * + * Copyright (C) 2007 Low Heng Sin hengsin@avantz.com + * _____________________________________________ + *****************************************************************************/ +package org.compiere.print; + +import org.compiere.print.ReportEngine; + +/** + * + * @author Low Heng Sin + * + */ +public interface ReportViewerProvider { + public void openViewer(ReportEngine re); +} diff --git a/client/src/org/compiere/print/SwingViewerProvider.java b/client/src/org/compiere/print/SwingViewerProvider.java new file mode 100644 index 0000000000..7c4cbaefc9 --- /dev/null +++ b/client/src/org/compiere/print/SwingViewerProvider.java @@ -0,0 +1,38 @@ +/****************************************************************************** + * Product: Adempiere ERP & CRM Smart Business Solution * + * Copyright (C) 2007 Adempiere, Inc. All Rights Reserved. * + * This program is free software; you can redistribute it and/or modify it * + * under the terms version 2 of the GNU General Public License as published * + * by the Free Software Foundation. This program is distributed in the hope * + * that it will be useful, but WITHOUT ANY WARRANTY; without even the implied * + * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * See the GNU General Public License for more details. * + * You should have received a copy of the GNU General Public License along * + * with this program; if not, write to the Free Software Foundation, Inc., * + * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. * + * + * Copyright (C) 2007 Low Heng Sin hengsin@avantz.com + * _____________________________________________ + *****************************************************************************/ +package org.compiere.print; + +import javax.swing.JFrame; + +import org.compiere.apps.AMenu; +import org.compiere.util.Env; + +/** + * + * @author Low Heng Sin + * + */ +public class SwingViewerProvider implements ReportViewerProvider { + + public void openViewer(ReportEngine re) { + Viewer viewer = new Viewer(re); + JFrame top = Env.getWindow(0); + if (top instanceof AMenu) + ((AMenu)top).getWindowManager().add(viewer); + } + +}