Search in sources :

Example 11 with AMedia

use of org.zkoss.util.media.AMedia in project adempiere by adempiere.

the class ZkReportViewer method renderReport.

private void renderReport() throws Exception {
    AMedia media = null;
    Listitem selected = previewType.getSelectedItem();
    if (selected == null || "PDF".equals(selected.getValue())) {
        String path = System.getProperty("java.io.tmpdir");
        String prefix = makePrefix(m_reportEngine.getName());
        if (log.isLoggable(Level.FINE)) {
            log.log(Level.FINE, "Path=" + path + " Prefix=" + prefix);
        }
        File file = File.createTempFile(prefix, ".pdf", new File(path));
        m_reportEngine.createPDF(file);
        media = new AMedia(getTitle(), "pdf", "application/pdf", file, true);
    } else if ("HTML".equals(previewType.getSelectedItem().getValue())) {
        String path = System.getProperty("java.io.tmpdir");
        String prefix = makePrefix(m_reportEngine.getName());
        if (log.isLoggable(Level.FINE)) {
            log.log(Level.FINE, "Path=" + path + " Prefix=" + prefix);
        }
        File file = File.createTempFile(prefix, ".html", new File(path));
        m_reportEngine.createHTML(file, false, AEnv.getLanguage(Env.getCtx()), new HTMLExtension(Executions.getCurrent().getContextPath(), "rp", this.getUuid()));
        media = new AMedia(getTitle(), "html", "text/html", file, false);
    } else if ("XLS".equals(previewType.getSelectedItem().getValue())) {
        String path = System.getProperty("java.io.tmpdir");
        String prefix = makePrefix(m_reportEngine.getName());
        if (log.isLoggable(Level.FINE)) {
            log.log(Level.FINE, "Path=" + path + " Prefix=" + prefix);
        }
        File file = File.createTempFile(prefix, ".xls", new File(path));
        m_reportEngine.createXLS(file, AEnv.getLanguage(Env.getCtx()));
        media = new AMedia(getTitle(), "xls", "application/vnd.ms-excel", file, true);
    }
    iframe.setContent(media);
}
Also used : AMedia(org.zkoss.util.media.AMedia) Listitem(org.zkoss.zul.Listitem) File(java.io.File) HTMLExtension(org.adempiere.webui.report.HTMLExtension)

Example 12 with AMedia

use of org.zkoss.util.media.AMedia in project adempiere by adempiere.

the class WCollect method printTicketWeb.

/**
	 * 	Print Ticket for Web
	 *  @return void
	 */
public void printTicketWeb() {
    try {
        if (posPanel.isToPrint() && posPanel.hasOrder()) {
            ReportCtl.startDocumentPrint(0, posPanel.getC_Order_ID(), false);
            ReportEngine m_reportEngine = ReportEngine.get(p_ctx, ReportEngine.ORDER, posPanel.getC_Order_ID());
            StringWriter sw = new StringWriter();
            m_reportEngine.createCSV(sw, '\t', m_reportEngine.getPrintFormat().getLanguage());
            byte[] data = sw.getBuffer().toString().getBytes();
            AMedia media = new AMedia(m_reportEngine.getPrintFormat().getName() + ".txt", null, "application/octet-stream", data);
            posPanel.printFile(media.getByteData(), posPanel.getC_Order_ID());
        }
    } catch (Exception e) {
        log.severe("PrintTicket - Error Printing Ticket");
    }
}
Also used : ReportEngine(org.compiere.print.ReportEngine) StringWriter(java.io.StringWriter) AMedia(org.zkoss.util.media.AMedia) POSaveFailedException(org.adempiere.pipo.exception.POSaveFailedException)

Example 13 with AMedia

use of org.zkoss.util.media.AMedia in project adempiere by adempiere.

the class WMediaDialog method displayData.

// dispose
/**
	 *  Display gif or jpg in gifPanel
	 * 	@param index index
	 */
private void displayData() {
    //	Reset UI		
    preview.setVisible(false);
    bDelete.setEnabled(false);
    bSave.setEnabled(false);
    if (m_data != null) {
        bSave.setEnabled(true);
        bDelete.setEnabled(true);
        try {
            AMedia media = createMedia();
            preview.setContent(media);
            preview.setVisible(true);
        } catch (Exception e) {
            log.log(Level.SEVERE, "Failed to preview content", e);
        }
    }
}
Also used : AMedia(org.zkoss.util.media.AMedia) SQLException(java.sql.SQLException)

Example 14 with AMedia

use of org.zkoss.util.media.AMedia in project adempiere by adempiere.

the class WMediaDialog method save.

//	getFileName
/**
	 *	download
	 */
private void save() {
    if (m_data == null)
        return;
    try {
        AMedia media = createMedia();
        Filedownload.save(media);
    } catch (Exception e) {
        log.log(Level.SEVERE, "Failed to export content.", e);
    }
}
Also used : AMedia(org.zkoss.util.media.AMedia) SQLException(java.sql.SQLException)

Aggregations

AMedia (org.zkoss.util.media.AMedia)14 File (java.io.File)4 SQLException (java.sql.SQLException)4 IOException (java.io.IOException)2 StringWriter (java.io.StringWriter)2 AdempiereException (org.adempiere.exceptions.AdempiereException)2 MAttachmentEntry (org.compiere.model.MAttachmentEntry)2 Listitem (org.zkoss.zul.Listitem)2 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 FileOutputStream (java.io.FileOutputStream)1 Blob (java.sql.Blob)1 Clob (java.sql.Clob)1 JRRtfExporter (net.sf.jasperreports.engine.export.JRRtfExporter)1 JRXlsExporter (net.sf.jasperreports.engine.export.JRXlsExporter)1 POSaveFailedException (org.adempiere.pipo.exception.POSaveFailedException)1 ListItem (org.adempiere.webui.component.ListItem)1 HTMLExtension (org.adempiere.webui.report.HTMLExtension)1 ReportEngine (org.compiere.print.ReportEngine)1 Iframe (org.zkoss.zul.Iframe)1