[ 1684853 ] Add Print Preview button
[ 1729327 ] Reporting Functionality ( zk client )
This commit is contained in:
parent
361c3f4982
commit
9fc4df5597
|
@ -0,0 +1,9 @@
|
||||||
|
package org.compiere.report;
|
||||||
|
|
||||||
|
import net.sf.jasperreports.engine.JRException;
|
||||||
|
import net.sf.jasperreports.engine.JasperPrint;
|
||||||
|
|
||||||
|
public interface JRViewerProvider {
|
||||||
|
|
||||||
|
public void openViewer(JasperPrint jasperPrint, String title) throws JRException;
|
||||||
|
}
|
|
@ -49,6 +49,7 @@ import org.compiere.process.ProcessInfo;
|
||||||
import org.compiere.util.CLogger;
|
import org.compiere.util.CLogger;
|
||||||
import org.compiere.util.DB;
|
import org.compiere.util.DB;
|
||||||
import org.compiere.util.Env;
|
import org.compiere.util.Env;
|
||||||
|
import org.compiere.util.Ini;
|
||||||
import org.compiere.util.Language;
|
import org.compiere.util.Language;
|
||||||
import org.compiere.util.Trx;
|
import org.compiere.util.Trx;
|
||||||
import org.compiere.utils.DBUtils;
|
import org.compiere.utils.DBUtils;
|
||||||
|
@ -62,6 +63,8 @@ public class ReportStarter implements ProcessCall {
|
||||||
//logger
|
//logger
|
||||||
private static CLogger log = CLogger.getCLogger(ReportStarter.class);
|
private static CLogger log = CLogger.getCLogger(ReportStarter.class);
|
||||||
private static File REPORT_HOME = null;
|
private static File REPORT_HOME = null;
|
||||||
|
|
||||||
|
private static JRViewerProvider viewerProvider = new SwingJRViewerProvider();
|
||||||
|
|
||||||
static {
|
static {
|
||||||
System.setProperty( "javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
|
System.setProperty( "javax.xml.parsers.SAXParserFactory", "org.apache.xerces.jaxp.SAXParserFactoryImpl");
|
||||||
|
@ -337,7 +340,7 @@ public class ReportStarter implements ProcessCall {
|
||||||
if (trx != null) {
|
if (trx != null) {
|
||||||
trxName = trx.getTrxName();
|
trxName = trx.getTrxName();
|
||||||
}
|
}
|
||||||
ReportData reportData = getReportData( AD_PInstance_ID, trxName);
|
ReportData reportData = getReportData( pi, trxName);
|
||||||
if (reportData==null) {
|
if (reportData==null) {
|
||||||
reportResult( AD_PInstance_ID, "Can not find report data", trxName);
|
reportResult( AD_PInstance_ID, "Can not find report data", trxName);
|
||||||
return false;
|
return false;
|
||||||
|
@ -454,9 +457,8 @@ public class ReportStarter implements ProcessCall {
|
||||||
// JasperExportManager.exportReportToPdfFile(jasperPrint, "BasicReport.pdf");
|
// JasperExportManager.exportReportToPdfFile(jasperPrint, "BasicReport.pdf");
|
||||||
} else {
|
} else {
|
||||||
log.info( "ReportStarter.startProcess run report -"+jasperPrint.getName());
|
log.info( "ReportStarter.startProcess run report -"+jasperPrint.getName());
|
||||||
JasperViewer jasperViewer = new JasperViewer( jasperPrint, pi.getTitle()+" - " + reportPath);
|
JRViewerProvider viewerLauncher = getReportViewerProvider();
|
||||||
jasperViewer.setExtendedState(jasperViewer.getExtendedState() | javax.swing.JFrame.MAXIMIZED_BOTH);
|
viewerLauncher.openViewer(jasperPrint, pi.getTitle()+" - " + reportPath);
|
||||||
jasperViewer.setVisible(true);
|
|
||||||
}
|
}
|
||||||
} catch (JRException e) {
|
} catch (JRException e) {
|
||||||
log.severe("ReportStarter.startProcess: Can not run report - "+ e.getMessage());
|
log.severe("ReportStarter.startProcess: Can not run report - "+ e.getMessage());
|
||||||
|
@ -709,10 +711,10 @@ public class ReportStarter implements ProcessCall {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author rlemeill
|
* @author rlemeill
|
||||||
* @param AD_PInstance_ID
|
* @param ProcessInfo
|
||||||
* @return ReportData
|
* @return ReportData
|
||||||
*/
|
*/
|
||||||
public ReportData getReportData( int AD_PInstance_ID, String trxName) {
|
public ReportData getReportData( ProcessInfo pi, String trxName) {
|
||||||
log.info("");
|
log.info("");
|
||||||
String sql = "SELECT pr.JasperReport, pr.IsDirectPrint "
|
String sql = "SELECT pr.JasperReport, pr.IsDirectPrint "
|
||||||
+ "FROM AD_Process pr, AD_PInstance pi "
|
+ "FROM AD_Process pr, AD_PInstance pi "
|
||||||
|
@ -722,18 +724,22 @@ public class ReportStarter implements ProcessCall {
|
||||||
ResultSet rs = null;
|
ResultSet rs = null;
|
||||||
try {
|
try {
|
||||||
pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, trxName);
|
pstmt = DB.prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, trxName);
|
||||||
pstmt.setInt(1, AD_PInstance_ID);
|
pstmt.setInt(1, pi.getAD_PInstance_ID());
|
||||||
rs = pstmt.executeQuery();
|
rs = pstmt.executeQuery();
|
||||||
String path = null;
|
String path = null;
|
||||||
String tmp = null;
|
String tmp = null;
|
||||||
//boolean directPrint;
|
boolean directPrint = false;
|
||||||
|
boolean isPrintPreview = pi.isPrintPreview();
|
||||||
if (rs.next()) {
|
if (rs.next()) {
|
||||||
path = rs.getString(1);
|
path = rs.getString(1);
|
||||||
tmp = rs.getString(2);
|
tmp = rs.getString(2);
|
||||||
} else {
|
} else {
|
||||||
log.info("data not found; sql = "+sql);
|
log.info("data not found; sql = "+sql);
|
||||||
}
|
}
|
||||||
return new ReportData( path, ((tmp.equalsIgnoreCase("y"))?true:false));
|
if ("Y".equals(rs.getString(6)) && !Ini.isPropertyBool(Ini.P_PRINTPREVIEW)
|
||||||
|
&& !isPrintPreview )
|
||||||
|
directPrint = true;
|
||||||
|
return new ReportData( path, directPrint);
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
log.severe("sql = "+sql+"; e.getMessage() = "+ e.getMessage());
|
log.severe("sql = "+sql+"; e.getMessage() = "+ e.getMessage());
|
||||||
return null;
|
return null;
|
||||||
|
@ -742,6 +748,16 @@ public class ReportStarter implements ProcessCall {
|
||||||
DBUtils.close( pstmt);
|
DBUtils.close( pstmt);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setReportViewerProvider(JRViewerProvider provider) {
|
||||||
|
if (provider == null)
|
||||||
|
throw new IllegalArgumentException("Cannot set report viewer provider to null");
|
||||||
|
viewerProvider = provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JRViewerProvider getReportViewerProvider() {
|
||||||
|
return viewerProvider;
|
||||||
|
}
|
||||||
|
|
||||||
class ReportData {
|
class ReportData {
|
||||||
private String reportFilePath;
|
private String reportFilePath;
|
||||||
|
|
|
@ -0,0 +1,14 @@
|
||||||
|
package org.compiere.report;
|
||||||
|
|
||||||
|
import net.sf.jasperreports.engine.JRException;
|
||||||
|
import net.sf.jasperreports.engine.JasperPrint;
|
||||||
|
|
||||||
|
public class SwingJRViewerProvider implements JRViewerProvider {
|
||||||
|
|
||||||
|
public void openViewer(JasperPrint jasperPrint, String title) throws JRException {
|
||||||
|
JasperViewer jasperViewer = new JasperViewer( jasperPrint, title);
|
||||||
|
jasperViewer.setExtendedState(jasperViewer.getExtendedState() | javax.swing.JFrame.MAXIMIZED_BOTH);
|
||||||
|
jasperViewer.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue