IDEMPIERE-3721 : Adding Archive toolbar button on Jasper viewer
This commit is contained in:
parent
817cd5fd65
commit
dd2766d88c
|
@ -18,13 +18,14 @@ import net.sf.jasperreports.engine.JasperPrint;
|
|||
import net.sf.jasperreports.engine.JasperReport;
|
||||
|
||||
import org.compiere.db.CConnection;
|
||||
|
||||
import org.compiere.model.PrintInfo;
|
||||
|
||||
public class JasperViewer extends javax.swing.JFrame {
|
||||
|
||||
private static final long serialVersionUID = 1192807883081180999L;
|
||||
|
||||
private String m_title;
|
||||
private PrintInfo m_printInfo;
|
||||
|
||||
/** Creates new form JasperViewer */
|
||||
/**
|
||||
|
@ -32,11 +33,12 @@ public class JasperViewer extends javax.swing.JFrame {
|
|||
* @param frameTitle Title to be displayed
|
||||
* @throws JRException
|
||||
*/
|
||||
protected JasperViewer(JasperPrint jasperPrint,String frameTitle) throws JRException {
|
||||
protected JasperViewer(JasperPrint jasperPrint,String frameTitle, PrintInfo printInfo) throws JRException {
|
||||
this.m_title = frameTitle;
|
||||
initComponents();
|
||||
JasperReportViewer viewer = new JasperReportViewer(this, jasperPrint);
|
||||
this.pnlMain.add(viewer, BorderLayout.CENTER);
|
||||
m_printInfo = printInfo;
|
||||
}
|
||||
|
||||
|
||||
|
@ -85,12 +87,12 @@ public class JasperViewer extends javax.swing.JFrame {
|
|||
/**
|
||||
*
|
||||
*/
|
||||
public static void viewReport(JasperPrint jasperPrint) throws JRException {
|
||||
JasperViewer jasperViewer = new JasperViewer(jasperPrint,"JasperReport");
|
||||
public static void viewReport(JasperPrint jasperPrint, PrintInfo printInfo) throws JRException {
|
||||
JasperViewer jasperViewer = new JasperViewer(jasperPrint,"JasperReport", printInfo);
|
||||
jasperViewer.setVisible(true);
|
||||
}
|
||||
public static void viewReport(JasperPrint jasperPrint,String frameTitle) throws JRException {
|
||||
JasperViewer jasperViewer = new JasperViewer(jasperPrint,frameTitle);
|
||||
public static void viewReport(JasperPrint jasperPrint,String frameTitle, PrintInfo printInfo) throws JRException {
|
||||
JasperViewer jasperViewer = new JasperViewer(jasperPrint,frameTitle, printInfo);
|
||||
jasperViewer.setVisible(true);
|
||||
}
|
||||
|
||||
|
@ -105,7 +107,7 @@ public class JasperViewer extends javax.swing.JFrame {
|
|||
try {
|
||||
JasperReport myjasperReport = (JasperReport) JasperCompileManager.compileReport(args[0] );
|
||||
JasperPrint myjasperPrint = JasperFillManager.fillReport( myjasperReport, new HashMap<String,Object>(), getConnection());
|
||||
JasperViewer.viewReport(myjasperPrint);
|
||||
JasperViewer.viewReport(myjasperPrint, null);
|
||||
}
|
||||
catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
|
|
|
@ -1,14 +1,15 @@
|
|||
package org.compiere.report;
|
||||
|
||||
import org.adempiere.report.jasper.JRViewerProvider;
|
||||
import org.compiere.model.PrintInfo;
|
||||
|
||||
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);
|
||||
public void openViewer(JasperPrint jasperPrint, String title, PrintInfo printInfo) throws JRException {
|
||||
JasperViewer jasperViewer = new JasperViewer( jasperPrint, title, printInfo);
|
||||
jasperViewer.setExtendedState(jasperViewer.getExtendedState() | javax.swing.JFrame.MAXIMIZED_BOTH);
|
||||
jasperViewer.setVisible(true);
|
||||
}
|
||||
|
|
|
@ -1,9 +1,11 @@
|
|||
package org.adempiere.report.jasper;
|
||||
|
||||
import org.compiere.model.PrintInfo;
|
||||
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
|
||||
public interface JRViewerProvider {
|
||||
|
||||
public void openViewer(JasperPrint jasperPrint, String title) throws JRException;
|
||||
public void openViewer(JasperPrint jasperPrint, String title, PrintInfo printInfo) throws JRException;
|
||||
}
|
||||
|
|
|
@ -2,10 +2,12 @@ package org.adempiere.report.jasper;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import org.compiere.model.PrintInfo;
|
||||
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
|
||||
public interface JRViewerProviderList {
|
||||
|
||||
public void openViewer(List<JasperPrint> jasperPrintList, String title) throws JRException;
|
||||
public void openViewer(List<JasperPrint> jasperPrintList, String title, PrintInfo printInfo) throws JRException;
|
||||
}
|
||||
|
|
|
@ -722,13 +722,15 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
|||
}
|
||||
}
|
||||
} else {
|
||||
if (reportPathList.length == 1) {
|
||||
if (printInfo == null)
|
||||
printInfo = new PrintInfo(pi);
|
||||
if (reportPathList.length == 1) {
|
||||
if (log.isLoggable(Level.INFO)) log.info( "ReportStarter.startProcess run report -"+jasperPrint.getName());
|
||||
JRViewerProvider viewerLauncher = Service.locator().locate(JRViewerProvider.class).getService();
|
||||
if (!Util.isEmpty(processInfo.getReportType())) {
|
||||
jasperPrint.setProperty("IDEMPIERE_REPORT_TYPE", processInfo.getReportType());
|
||||
}
|
||||
viewerLauncher.openViewer(jasperPrint, pi.getTitle());
|
||||
viewerLauncher.openViewer(jasperPrint, pi.getTitle(), printInfo);
|
||||
} else {
|
||||
jasperPrintList.add(jasperPrint);
|
||||
if (idx+1 == reportPathList.length) {
|
||||
|
@ -736,7 +738,7 @@ public class ReportStarter implements ProcessCall, ClientProcess
|
|||
if (viewerLauncher == null) {
|
||||
throw new AdempiereException("Can not find a viewer provider for multiple jaspers");
|
||||
}
|
||||
viewerLauncher.openViewer(jasperPrintList, pi.getTitle());
|
||||
viewerLauncher.openViewer(jasperPrintList, pi.getTitle(), printInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package org.adempiere.webui.window;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
|
@ -21,9 +23,11 @@ import org.adempiere.webui.panel.ITabOnCloseHandler;
|
|||
import org.adempiere.webui.session.SessionManager;
|
||||
import org.adempiere.webui.theme.ThemeManager;
|
||||
import org.adempiere.webui.util.ZKUpdateUtil;
|
||||
import org.compiere.model.MArchive;
|
||||
import org.compiere.model.MRole;
|
||||
import org.compiere.model.MSysConfig;
|
||||
import org.compiere.model.MUser;
|
||||
import org.compiere.model.PrintInfo;
|
||||
import org.compiere.tools.FileUtil;
|
||||
import org.compiere.util.CLogger;
|
||||
import org.compiere.util.Env;
|
||||
|
@ -91,10 +95,12 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
|||
private KeyEvent prevKeyEvent;
|
||||
|
||||
private String m_title; // local title - embedded windows clear the title
|
||||
protected ToolBarButton bArchive = new ToolBarButton();
|
||||
private PrintInfo m_printInfo;
|
||||
|
||||
private int mediaVersion = 0;
|
||||
|
||||
public ZkJRViewer(JasperPrint jasperPrint, String title) {
|
||||
public ZkJRViewer(JasperPrint jasperPrint, String title, PrintInfo printInfo) {
|
||||
super();
|
||||
this.setTitle(title);
|
||||
m_title = title;
|
||||
|
@ -102,10 +108,11 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
|||
this.isList = false;
|
||||
m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
|
||||
setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, m_WindowNo);
|
||||
m_printInfo = printInfo;
|
||||
init();
|
||||
}
|
||||
|
||||
public ZkJRViewer(java.util.List<JasperPrint> jasperPrintList, String title) {
|
||||
public ZkJRViewer(java.util.List<JasperPrint> jasperPrintList, String title, PrintInfo printInfo) {
|
||||
super();
|
||||
this.setTitle(title);
|
||||
m_title = title;
|
||||
|
@ -113,6 +120,7 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
|||
this.isList = true;
|
||||
m_WindowNo = SessionManager.getAppDesktop().registerWindow(this);
|
||||
setAttribute(IDesktop.WINDOWNO_ATTRIBUTE, m_WindowNo);
|
||||
m_printInfo = printInfo;
|
||||
init();
|
||||
}
|
||||
|
||||
|
@ -202,6 +210,16 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
|||
bSendMail.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "SendMail")));
|
||||
toolbar.appendChild(bSendMail);
|
||||
bSendMail.addEventListener(Events.ON_CLICK, this);
|
||||
|
||||
toolbar.appendChild(new Separator("vertical"));
|
||||
bArchive.setName("Archive");
|
||||
if (ThemeManager.isUseFontIconForImage())
|
||||
bArchive.setIconSclass("z-icon-Archive");
|
||||
else
|
||||
bArchive.setImage(ThemeManager.getThemeResource("images/Archive24.png"));
|
||||
bArchive.setTooltiptext(Util.cleanAmp(Msg.getMsg(Env.getCtx(), "Archive")));
|
||||
toolbar.appendChild(bArchive);
|
||||
bArchive.addEventListener(Events.ON_CLICK, this);
|
||||
|
||||
North north = new North();
|
||||
layout.appendChild(north);
|
||||
|
@ -251,6 +269,8 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
|||
cmd_render();
|
||||
else if (e.getTarget() == bSendMail) // Added by Martin Augustine - Ntier software services 09/10/2013
|
||||
cmd_sendMail();
|
||||
else if (e.getTarget() == bArchive)
|
||||
cmd_archive();
|
||||
} // actionPerformed
|
||||
|
||||
private void cmd_render() {
|
||||
|
@ -524,5 +544,62 @@ public class ZkJRViewer extends Window implements EventListener<Event>, ITabOnCl
|
|||
return media;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create archive for jasper report
|
||||
*/
|
||||
protected void cmd_archive()
|
||||
{
|
||||
boolean success = false;
|
||||
try
|
||||
{
|
||||
byte[] data = getFileByteData(getPDF());
|
||||
if (data != null && m_printInfo != null)
|
||||
{
|
||||
MArchive archive = new MArchive(Env.getCtx(), m_printInfo, null);
|
||||
archive.setBinaryData(data);
|
||||
success = archive.save();
|
||||
}
|
||||
|
||||
if (success)
|
||||
FDialog.info(m_WindowNo, this, "Archived");
|
||||
else
|
||||
FDialog.error(m_WindowNo, this, "ArchiveError");
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
log.log(Level.SEVERE, "Exception while reading file " + e);
|
||||
}
|
||||
catch (JRException e)
|
||||
{
|
||||
log.log(Level.SEVERE, "Error loading object from InputStream" + e);
|
||||
}
|
||||
} // cmd_archive
|
||||
|
||||
/**
|
||||
* convert File data into Byte Data
|
||||
* @param tempFile
|
||||
* @return file in ByteData
|
||||
*/
|
||||
private byte[] getFileByteData(File tempFile)
|
||||
{
|
||||
byte fileContent[] = new byte[(int) tempFile.length()];
|
||||
|
||||
try
|
||||
{
|
||||
FileInputStream fis = new FileInputStream(tempFile);
|
||||
fis.read(fileContent);
|
||||
fis.close();
|
||||
}
|
||||
catch (FileNotFoundException e)
|
||||
{
|
||||
log.log(Level.SEVERE, "File not found " + e);
|
||||
}
|
||||
catch (IOException ioe)
|
||||
{
|
||||
log.log(Level.SEVERE, "Exception while reading file " + ioe);
|
||||
}
|
||||
return fileContent;
|
||||
} // getFileByteData
|
||||
|
||||
}
|
||||
|
|
|
@ -8,19 +8,20 @@ import org.adempiere.webui.apps.AEnv;
|
|||
import org.adempiere.webui.component.Window;
|
||||
import org.adempiere.webui.part.WindowContainer;
|
||||
import org.adempiere.webui.session.SessionManager;
|
||||
import org.compiere.model.PrintInfo;
|
||||
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JasperPrint;
|
||||
|
||||
public class ZkJRViewerProvider implements JRViewerProvider, JRViewerProviderList {
|
||||
|
||||
public void openViewer(final JasperPrint jasperPrint, final String title)
|
||||
public void openViewer(final JasperPrint jasperPrint, final String title, final PrintInfo printInfo)
|
||||
throws JRException {
|
||||
Runnable runnable = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Window viewer = new ZkJRViewer(jasperPrint, title);
|
||||
Window viewer = new ZkJRViewer(jasperPrint, title, printInfo);
|
||||
|
||||
viewer.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED);
|
||||
viewer.setAttribute(Window.INSERT_POSITION_KEY, Window.INSERT_NEXT);
|
||||
|
@ -31,13 +32,13 @@ public class ZkJRViewerProvider implements JRViewerProvider, JRViewerProviderLis
|
|||
AEnv.executeAsyncDesktopTask(runnable);
|
||||
}
|
||||
|
||||
public void openViewer(final List<JasperPrint> jasperPrintList, final String title)
|
||||
public void openViewer(final List<JasperPrint> jasperPrintList, final String title , final PrintInfo printInfo)
|
||||
throws JRException {
|
||||
Runnable runnable = new Runnable() {
|
||||
|
||||
@Override
|
||||
public void run() {
|
||||
Window viewer = new ZkJRViewer(jasperPrintList, title);
|
||||
Window viewer = new ZkJRViewer(jasperPrintList, title, printInfo);
|
||||
|
||||
viewer.setAttribute(Window.MODE_KEY, Window.MODE_EMBEDDED);
|
||||
viewer.setAttribute(Window.INSERT_POSITION_KEY, Window.INSERT_NEXT);
|
||||
|
|
Loading…
Reference in New Issue