- added option for user to select output type ( pdf, html or excel )
- added optional sysconfig parameter to change the default report output type ( ZK_REPORT_DEFAULT_OUTPUT_TYPE - PDF, HTML or XLS ). PDF is the default for backward compatibility reason.

https://sourceforge.net/tracker/?func=detail&aid=2827675&group_id=176962&atid=955896
- added zoom, drill down and drill across support for report viewer when output type is html
This commit is contained in:
Heng Sin Low 2009-07-27 10:01:36 +00:00
parent e88473e21f
commit f03cafdac1
14 changed files with 663 additions and 117 deletions

View File

@ -93,7 +93,7 @@
<classpathentry exported="true" kind="lib" path="zkwebui/WEB-INF/lib/jxl.jar"/>
<classpathentry exported="true" kind="lib" path="zkwebui/WEB-INF/lib/mvel.jar"/>
<classpathentry exported="true" kind="lib" path="zkwebui/WEB-INF/lib/ognl.jar"/>
<classpathentry exported="true" kind="lib" path="zkwebui/WEB-INF/lib/timelinez.jar"/>
<classpathentry exported="true" kind="lib" path="zkwebui/WEB-INF/lib/timelinez.jar" sourcepath="zkwebui/WEB-INF/lib/timelinez-sources.jar"/>
<classpathentry exported="true" kind="lib" path="zkwebui/WEB-INF/lib/zcommons-el.jar"/>
<classpathentry exported="true" kind="lib" path="zkwebui/WEB-INF/lib/zhtml.jar" sourcepath="zkwebui/WEB-INF/lib/zhtml-sources.jar"/>
<classpathentry exported="true" kind="lib" path="zkwebui/WEB-INF/lib/zhtml-sources.jar"/>

View File

@ -29,11 +29,11 @@ import java.util.Properties;
*/
public class MPInstancePara extends X_AD_PInstance_Para
{
/**
*
*/
private static final long serialVersionUID = -8688626861772200167L;
private static final long serialVersionUID = -8407658637240252680L;
/**
* Persistency Constructor
@ -215,5 +215,21 @@ public class MPInstancePara extends X_AD_PInstance_Para
setParameterName(parameterName);
setP_String(boolParameter ? "Y" : "N");
} // setParameter
/**
* @return Display type
*/
public int getDisplayType()
{
MProcess process = (MProcess) getAD_PInstance().getAD_Process();
MProcessPara[] params = process.getParameters();
for(MProcessPara param : params)
{
if (param.getColumnName().equals(getParameterName()))
{
return param.getAD_Reference_ID();
}
}
return -1;
}
} // MPInstance_Para

View File

@ -0,0 +1,35 @@
/******************************************************************************
* Copyright (C) 2009 Low Heng Sin *
* Copyright (C) 2009 Idalica Corporation *
* 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. *
*****************************************************************************/
package org.compiere.print;
import org.apache.ecs.ConcreteElement;
import org.apache.ecs.xhtml.a;
/**
*
* @author hengsin
*
*/
public interface IHTMLExtension {
public String getClassPrefix();
public String getStyleURL();
public String getScriptURL();
public void extendRowElement(ConcreteElement row, PrintData printData);
public void extendIDColumn(int row, ConcreteElement columnElement, a href, PrintDataElement dataElement);
}

View File

@ -49,6 +49,9 @@ import javax.xml.transform.stream.StreamResult;
import org.adempiere.pdf.Document;
import org.adempiere.print.export.PrintDataExcelExporter;
import org.apache.ecs.XhtmlDocument;
import org.apache.ecs.xhtml.a;
import org.apache.ecs.xhtml.link;
import org.apache.ecs.xhtml.script;
import org.apache.ecs.xhtml.table;
import org.apache.ecs.xhtml.td;
import org.apache.ecs.xhtml.th;
@ -67,6 +70,7 @@ import org.compiere.print.layout.LayoutEngine;
import org.compiere.process.ProcessInfo;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.DisplayType;
import org.compiere.util.Env;
import org.compiere.util.Ini;
import org.compiere.util.Language;
@ -454,7 +458,6 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
return m_printerName;
} // getPrinterName
/**************************************************************************
* Create HTML File
* @param file file
@ -463,6 +466,19 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
* @return true if success
*/
public boolean createHTML (File file, boolean onlyTable, Language language)
{
return createHTML(file, onlyTable, language, null);
}
/**************************************************************************
* Create HTML File
* @param file file
* @param onlyTable if false create complete HTML document
* @param language optional language - if null the default language is used to format nubers/dates
* @param extension optional extension for html output
* @return true if success
*/
public boolean createHTML (File file, boolean onlyTable, Language language, IHTMLExtension extension)
{
try
{
@ -470,7 +486,7 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
if (lang == null)
lang = Language.getLoginLanguage();
Writer fw = new OutputStreamWriter(new FileOutputStream(file, false), Ini.getCharset()); // teo_sarca: save using adempiere charset [ 1658127 ]
return createHTML (new BufferedWriter(fw), onlyTable, lang);
return createHTML (new BufferedWriter(fw), onlyTable, lang, extension);
}
catch (FileNotFoundException fnfe)
{
@ -491,10 +507,29 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
* @return true if success
*/
public boolean createHTML (Writer writer, boolean onlyTable, Language language)
{
return createHTML(writer, onlyTable, language, null);
}
/**
* Write HTML to writer
* @param writer writer
* @param onlyTable if false create complete HTML document
* @param language optional language - if null numbers/dates are not formatted
* @param extension optional extension for html output
* @return true if success
*/
public boolean createHTML (Writer writer, boolean onlyTable, Language language, IHTMLExtension extension)
{
try
{
String cssPrefix = extension != null ? extension.getClassPrefix() : null;
if (cssPrefix != null && cssPrefix.trim().length() == 0)
cssPrefix = null;
table table = new table();
if (cssPrefix != null)
table.setClass(cssPrefix + "-table");
//
// for all rows (-1 = header row)
for (int row = -1; row < m_printData.getRowCount(); row++)
@ -502,7 +537,13 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
tr tr = new tr();
table.addElement(tr);
if (row != -1)
m_printData.setRowIndex(row);
{
m_printData.setRowIndex(row);
if (extension != null)
{
extension.extendRowElement(tr, m_printData);
}
}
// for all columns
for (int col = 0; col < m_printFormat.getItemCount(); col++)
{
@ -525,8 +566,34 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
td.addElement("&nbsp;");
else if (obj instanceof PrintDataElement)
{
String value = ((PrintDataElement)obj).getValueDisplay(language); // formatted
td.addElement(Util.maskHTML(value));
PrintDataElement pde = (PrintDataElement) obj;
String value = pde.getValueDisplay(language); // formatted
if (pde.getColumnName().endsWith("_ID") && extension != null)
{
//link for column
a href = new a("javascript:void(0)");
href.setID(pde.getColumnName() + "_" + row + "_a");
td.addElement(href);
href.addElement(Util.maskHTML(value));
if (cssPrefix != null)
href.setClass(cssPrefix + "-href");
extension.extendIDColumn(row, td, href, pde);
}
else
{
td.addElement(Util.maskHTML(value));
}
if (cssPrefix != null)
{
if (DisplayType.isNumeric(pde.getDisplayType()))
td.setClass(cssPrefix + "-number");
else if (DisplayType.isDate(pde.getDisplayType()))
td.setClass(cssPrefix + "-date");
else
td.setClass(cssPrefix + "-text");
}
}
else if (obj instanceof PrintData)
{
@ -547,6 +614,18 @@ queued-job-count = 0 (class javax.print.attribute.standard.QueuedJobCount)
{
XhtmlDocument doc = new XhtmlDocument();
doc.appendBody(table);
if (extension.getStyleURL() != null)
{
link l = new link(extension.getStyleURL(), "stylesheet", "text/css");
doc.appendHead(l);
}
if (extension.getScriptURL() != null)
{
script jslink = new script();
jslink.setLanguage("javascript");
jslink.setSrc(extension.getScriptURL());
doc.appendHead(jslink);
}
doc.output(w);
}
w.flush();

View File

@ -24,4 +24,5 @@ Copyright (C) 2007 Ashley G Ramdass (ADempiere WebUI).
<javascript src="/js/calc.js" charset="UTF-8"/>
<javascript src="/js/layout.js" charset="UTF-8"/>
<javascript src="/js/report.js" charset="UTF-8"/>
</language>

View File

@ -24,6 +24,8 @@ import java.util.Properties;
import javax.servlet.http.HttpSession;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.component.DrillCommand;
import org.adempiere.webui.component.ZoomCommand;
import org.adempiere.webui.desktop.DefaultDesktop;
import org.adempiere.webui.desktop.IDesktop;
import org.adempiere.webui.session.SessionManager;
@ -34,6 +36,7 @@ import org.compiere.model.MSysConfig;
import org.compiere.util.CLogger;
import org.compiere.util.Env;
import org.compiere.util.Language;
import org.zkoss.zk.au.Command;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.Page;
@ -58,9 +61,9 @@ import org.zkoss.zul.Window;
* @author hengsin
*/
public class AdempiereWebUI extends Window implements EventListener, IWebClient
{
/**
*
{
/**
*
*/
private static final long serialVersionUID = 5759422592670132576L;
@ -316,4 +319,11 @@ public class AdempiereWebUI extends Window implements EventListener, IWebClient
public UserPreference getUserPreference() {
return userPreference;
}
//global command
static {
new ZoomCommand("onZoom", Command.IGNORE_OLD_EQUIV);
new DrillCommand("onDrillAcross", Command.IGNORE_OLD_EQUIV);
new DrillCommand("onDrillDown", Command.IGNORE_OLD_EQUIV);
}
}

View File

@ -0,0 +1,58 @@
/******************************************************************************
* Copyright (C) 2009 Low Heng Sin *
* Copyright (C) 2009 Idalica Corporation *
* 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. *
*****************************************************************************/
package org.adempiere.webui.component;
import org.adempiere.webui.event.DrillEvent;
import org.compiere.model.MQuery;
import org.zkoss.lang.Objects;
import org.zkoss.zk.au.AuRequest;
import org.zkoss.zk.au.Command;
import org.zkoss.zk.mesg.MZk;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.UiException;
import org.zkoss.zk.ui.event.Events;
/**
*
* @author hengsin
*
*/
public class DrillCommand extends Command {
public DrillCommand(String id, int flags) {
super(id, flags);
}
@Override
protected void process(AuRequest request) {
final String[] data = request.getData();
final Component comp = request.getComponent();
if (comp == null)
throw new UiException(MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this);
if (data == null || data.length < 2)
throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA, new Object[] {
Objects.toString(data), this });
String columnName = data[0];
String tableName = MQuery.getZoomTableName(columnName);
String code = data[1];
//
MQuery query = new MQuery(tableName);
query.addRestriction(columnName, MQuery.EQUAL, code);
Events.postEvent(new DrillEvent(getId(), comp, query));
}
}

View File

@ -0,0 +1,72 @@
/******************************************************************************
* Copyright (C) 2009 Low Heng Sin *
* Copyright (C) 2009 Idalica Corporation *
* 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. *
*****************************************************************************/
package org.adempiere.webui.component;
import org.adempiere.webui.event.ZoomEvent;
import org.compiere.model.MQuery;
import org.zkoss.lang.Objects;
import org.zkoss.zk.au.AuRequest;
import org.zkoss.zk.au.Command;
import org.zkoss.zk.mesg.MZk;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.UiException;
import org.zkoss.zk.ui.event.Events;
/**
*
* @author hengsin
*
*/
public class ZoomCommand extends Command {
public ZoomCommand(String id, int flags) {
super(id, flags);
}
@Override
protected void process(AuRequest request) {
final String[] data = request.getData();
final Component comp = request.getComponent();
if (comp == null)
throw new UiException(MZk.ILLEGAL_REQUEST_COMPONENT_REQUIRED, this);
if (data == null || data.length < 2)
throw new UiException(MZk.ILLEGAL_REQUEST_WRONG_DATA, new Object[] {
Objects.toString(data), this });
String columnName = data[0];
String tableName = MQuery.getZoomTableName(columnName);
Object code = null;
if (columnName.endsWith("_ID"))
{
try {
code = Integer.parseInt(data[1]);
} catch (Exception e) {
code = data[1];
}
}
else
{
code = data[1];
}
//
MQuery query = new MQuery(tableName);
query.addRestriction(columnName, MQuery.EQUAL, code);
query.setRecordCount(1);
Events.postEvent(new ZoomEvent(comp, query));
}
}

View File

@ -0,0 +1,33 @@
/******************************************************************************
* Copyright (C) 2009 Low Heng Sin *
* Copyright (C) 2009 Idalica Corporation *
* 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. *
*****************************************************************************/
package org.adempiere.webui.event;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
/**
*
* @author hengsin
*
*/
public class DrillEvent extends Event {
public final static String ON_DRILL_DOWN = "onDrillDown";
public final static String ON_DRILL_ACROSS = "onDrillAcross";
public DrillEvent(String name, Component target, Object data) {
super(name, target, data);
}
}

View File

@ -0,0 +1,32 @@
/******************************************************************************
* Copyright (C) 2009 Low Heng Sin *
* Copyright (C) 2009 Idalica Corporation *
* 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. *
*****************************************************************************/
package org.adempiere.webui.event;
import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.event.Event;
/**
*
* @author hengsin
*
*/
public class ZoomEvent extends Event {
private static final String EVENT_NAME = "onZoom";
public ZoomEvent(Component target, Object data) {
super(EVENT_NAME, target, data);
}
}

View File

@ -0,0 +1,115 @@
/******************************************************************************
* Copyright (C) 2009 Low Heng Sin *
* Copyright (C) 2009 Idalica Corporation *
* 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. *
*****************************************************************************/
package org.adempiere.webui.report;
import org.adempiere.webui.apps.AEnv;
import org.apache.ecs.ConcreteElement;
import org.apache.ecs.xhtml.a;
import org.apache.ecs.xhtml.div;
import org.apache.ecs.xhtml.img;
import org.compiere.print.IHTMLExtension;
import org.compiere.print.PrintData;
import org.compiere.print.PrintDataElement;
import org.compiere.util.Env;
import org.compiere.util.Msg;
/**
*
* @author hengsin
*
*/
public class HTMLExtension implements IHTMLExtension {
private String contextPath;
private String classPrefix;
private String componentId;
public HTMLExtension(String contextPath, String classPrefix, String componentId) {
this.contextPath = contextPath;
this.classPrefix = classPrefix;
this.componentId = componentId;
}
public void extendIDColumn(int row, ConcreteElement columnElement, a href,
PrintDataElement dataElement) {
href.addAttribute("onclick", "showColumnMenu(event, '" + dataElement.getColumnName() + "', " + row + ")");
//menu div
div menu = new div();
menu.setID(dataElement.getColumnName() + "_" + row + "_d");
menu.setStyle("position:absolute;display:none;top:0;left:0;border: 1px solid lightgray; background-color: white;");
columnElement.addElementToRegistry(menu);
//window menu item
div window = new div();
window.setStyle("padding: 3px; vertical-align: middle");
window.addAttribute("onmouseover", "this.style.backgroundColor = 'lightgray'");
window.addAttribute("onmouseout", "this.style.backgroundColor = 'white'");
href = new a("javascript:void(0)");
href.setStyle("text-decoration: none; font-size: 10px; vertical-align: middle;");
href.addAttribute("onclick", "parent.zoom('"
+ componentId + "', '"
+ dataElement.getColumnName() + "', '"
+ dataElement.getValueAsString() + "')");
window.addElement(href);
menu.addElement(window);
img image = new img("/webui/images/mWindow.png");
image.setAlign("middle");
href.addElement(image);
href.addElement(Msg.getMsg(AEnv.getLanguage(Env.getCtx()), "Window"));
//report menu item
div report = new div();
report.setStyle("padding: 3px; vertical-align: middle");
report.addAttribute("onmouseover", "this.style.backgroundColor = 'lightgray'");
report.addAttribute("onmouseout", "this.style.backgroundColor = 'white'");
href = new a("javascript:void(0)");
href.setStyle("text-decoration: none; font-size: 10px; vertical-align: middle;");
href.addAttribute("onclick", "parent.drillDown('"
+ componentId + "', '"
+ dataElement.getColumnName() + "', '"
+ dataElement.getValueAsString() + "')");
report.addElement(href);
menu.addElement(report);
image = new img("/webui/images/mReport.png");
image.setAlign("middle");
href.addElement(image);
href.addElement(Msg.getMsg(AEnv.getLanguage(Env.getCtx()), "Report").replace("&", ""));
}
public void extendRowElement(ConcreteElement row, PrintData printData) {
PrintDataElement pkey = printData.getPKey();
if (pkey != null)
{
row.addAttribute("ondblclick", "parent.drillAcross('"
+ componentId + "', '"
+ pkey.getColumnName() + "', '"
+ pkey.getValueAsString() + "')");
}
}
public String getClassPrefix() {
return classPrefix;
}
public String getScriptURL() {
return contextPath + "/js/report.js";
}
public String getStyleURL() {
return contextPath + "/css/report.css";
}
}

View File

@ -16,7 +16,6 @@
*****************************************************************************/
package org.adempiere.webui.window;
import java.awt.Point;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.StringWriter;
@ -26,8 +25,10 @@ import java.sql.SQLException;
import java.util.Properties;
import java.util.logging.Level;
import org.adempiere.exceptions.AdempiereException;
import org.adempiere.pdf.Document;
import org.adempiere.webui.apps.AEnv;
import org.adempiere.webui.apps.WReport;
import org.adempiere.webui.component.ConfirmPanel;
import org.adempiere.webui.component.Grid;
import org.adempiere.webui.component.Label;
@ -36,35 +37,38 @@ import org.adempiere.webui.component.Listbox;
import org.adempiere.webui.component.Row;
import org.adempiere.webui.component.Rows;
import org.adempiere.webui.component.Window;
import org.adempiere.webui.event.DrillEvent;
import org.adempiere.webui.event.ZoomEvent;
import org.adempiere.webui.panel.StatusBarPanel;
import org.adempiere.webui.report.HTMLExtension;
import org.adempiere.webui.session.SessionManager;
import org.compiere.model.GridField;
import org.compiere.model.MArchive;
import org.compiere.model.MClient;
import org.compiere.model.MQuery;
import org.compiere.model.MRole;
import org.compiere.model.MSysConfig;
import org.compiere.model.MUser;
import org.compiere.print.AReport;
import org.compiere.print.ArchiveEngine;
import org.compiere.print.MPrintFormat;
import org.compiere.print.ReportEngine;
import org.compiere.print.View;
import org.compiere.util.CLogger;
import org.compiere.util.DB;
import org.compiere.util.Env;
import org.compiere.util.KeyNamePair;
import org.compiere.util.Msg;
import org.zkoss.util.media.AMedia;
import org.zkoss.zk.ui.Executions;
import org.zkoss.zk.ui.event.Event;
import org.zkoss.zk.ui.event.EventListener;
import org.zkoss.zk.ui.event.Events;
import org.zkoss.zk.ui.event.MouseEvent;
import org.zkoss.zul.Div;
import org.zkoss.zul.Filedownload;
import org.zkoss.zul.Hbox;
import org.zkoss.zul.Iframe;
import org.zkoss.zul.Listitem;
import org.zkoss.zul.Menuitem;
import org.zkoss.zul.Menupopup;
import org.zkoss.zul.Separator;
import org.zkoss.zul.Toolbar;
import org.zkoss.zul.Toolbarbutton;
@ -89,22 +93,19 @@ import org.zkoss.zul.Vbox;
* @author Low Heng Sin
*/
public class ZkReportViewer extends Window implements EventListener {
/**
*
*/
private static final long serialVersionUID = 347074497359766172L;
private static final long serialVersionUID = 1492321933977608137L;
/** Window No */
private int m_WindowNo;
/** Print Context */
private Properties m_ctx;
/** View Pane */
private View m_viewPanel;
/** Setting Values */
private boolean m_setting = false;
/** Report Engine */
private ReportEngine m_reportEngine;
/** Drill Down/Across */
private boolean m_drillDown = true;
/** Table ID */
private int m_AD_Table_ID = 0;
private boolean m_isCanExport;
@ -128,6 +129,7 @@ public class ZkReportViewer extends Window implements EventListener {
private Listbox comboReport = new Listbox();
private Label labelDrill = new Label();
private Listbox comboDrill = new Listbox();
private Listbox previewType = new Listbox();
private Toolbarbutton bRefresh = new Toolbarbutton();
private Iframe iframe;
@ -154,11 +156,11 @@ public class ZkReportViewer extends Window implements EventListener {
m_isCanExport = MRole.getDefault().isCanExport(m_AD_Table_ID);
try
{
m_viewPanel = re.getView();
m_ctx = m_reportEngine.getCtx();
jbInit();
dynInit();
if (!m_viewPanel.isArchivable())
if (!ArchiveEngine.isValid(m_reportEngine.getLayout()))
log.warning("Cannot archive Document");
}
catch(Exception e)
@ -177,6 +179,26 @@ public class ZkReportViewer extends Window implements EventListener {
toolBar.setHeight("26px");
previewType.setMold("select");
previewType.appendItem("PDF", "PDF");
previewType.appendItem("HTML", "HTML");
previewType.appendItem("Excel", "XLS");
toolBar.appendChild(previewType);
previewType.addEventListener(Events.ON_SELECT, this);
toolBar.appendChild(new Separator("vertical"));
//set default type
String type = MSysConfig.getValue("ZK_REPORT_DEFAULT_OUTPUT_TYPE");
if ("PDF".equals(type))
previewType.setSelectedIndex(0);
else if ("HTML".equals(type))
previewType.setSelectedIndex(1);
else if ("XLS".equals(type))
previewType.setSelectedIndex(2);
else
previewType.setSelectedIndex(0); //fallback to PDF
labelDrill.setValue(Msg.getMsg(m_ctx, "Drill") + ": ");
toolBar.appendChild(labelDrill);
@ -237,11 +259,17 @@ public class ZkReportViewer extends Window implements EventListener {
height = height - 30;
iframe.setHeight(height + "px");
iframe.setWidth("100%");
AMedia media = new AMedia(getTitle(), "pdf", "application/pdf", m_reportEngine.createPDFData());
iframe.setContent(media);
iframe.setAutohide(true);
iframe.addEventListener(Events.ON_CLICK, this);
iframe.addEventListener(Events.ON_RIGHT_CLICK, this);
iframe.addEventListener(Events.ON_RIGHT_CLICK, this);
try {
renderReport();
} catch (Exception e) {
throw new AdempiereException("Failed to render report", e);
}
iframe.setAutohide(true);
row.appendChild(iframe);
rows.appendChild(row);
@ -249,6 +277,70 @@ public class ZkReportViewer extends Window implements EventListener {
this.appendChild(grid);
this.setBorder("normal");
this.addEventListener("onZoom", new EventListener() {
public void onEvent(Event event) throws Exception {
if (event instanceof ZoomEvent) {
ZoomEvent ze = (ZoomEvent) event;
if (ze.getData() != null && ze.getData() instanceof MQuery) {
AEnv.zoom((MQuery) ze.getData());
}
}
}
});
this.addEventListener(DrillEvent.ON_DRILL_ACROSS, new EventListener() {
public void onEvent(Event event) throws Exception {
if (event instanceof DrillEvent) {
DrillEvent de = (DrillEvent) event;
if (de.getData() != null && de.getData() instanceof MQuery) {
MQuery query = (MQuery) de.getData();
Listitem item = comboDrill.getSelectedItem();
if (item != null && item.getValue() != null && item.toString().trim().length() > 0)
{
query.setTableName(item.getValue().toString());
executeDrill(query);
}
}
}
}
});
this.addEventListener(DrillEvent.ON_DRILL_DOWN, new EventListener() {
public void onEvent(Event event) throws Exception {
if (event instanceof DrillEvent) {
DrillEvent de = (DrillEvent) event;
if (de.getData() != null && de.getData() instanceof MQuery) {
MQuery query = (MQuery) de.getData();
executeDrill(query);
}
}
}
});
}
private void renderReport() throws Exception {
AMedia media = null;
Listitem selected = previewType.getSelectedItem();
if (selected == null || "PDF".equals(selected.getValue())) {
media = new AMedia(getTitle(), "pdf", "application/pdf", m_reportEngine.createPDFData());
} else if ("HTML".equals(previewType.getSelectedItem().getValue())) {
File file = File.createTempFile(m_reportEngine.getName(), ".html");
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())) {
File file = File.createTempFile(m_reportEngine.getName(), ".html");
m_reportEngine.createXLS(file, AEnv.getLanguage(Env.getCtx()));
media = new AMedia(getTitle(), "xls", "application/vnd.ms-excel", file, true);
}
iframe.setContent(media);
}
/**
@ -371,8 +463,7 @@ public class ZkReportViewer extends Window implements EventListener {
// Report Info
setTitle(Msg.getMsg(m_ctx, "Report") + ": " + m_reportEngine.getName() + " " + Env.getHeader(m_ctx, 0));
StringBuffer sb = new StringBuffer ();
sb.append(m_viewPanel.getPaper().toString(m_ctx))
.append(" - ").append(Msg.getMsg(m_ctx, "DataCols")).append("=")
sb.append(Msg.getMsg(m_ctx, "DataCols")).append("=")
.append(m_reportEngine.getColumnCount())
.append(", ").append(Msg.getMsg(m_ctx, "DataRows")).append("=")
.append(m_reportEngine.getRowCount());
@ -387,7 +478,6 @@ public class ZkReportViewer extends Window implements EventListener {
{
Env.clearWinContext(m_WindowNo);
m_reportEngine = null;
m_viewPanel = null;
m_ctx = null;
super.onClose();
} // dispose
@ -400,8 +490,6 @@ public class ZkReportViewer extends Window implements EventListener {
exportFile();
else if(event.getName().equals(Events.ON_CLICK) || event.getName().equals(Events.ON_SELECT))
actionPerformed(event);
else if(event.getName().equals(Events.ON_RIGHT_CLICK))
mouse_clicked(event, true);
}
/**************************************************************************
@ -414,12 +502,12 @@ public class ZkReportViewer extends Window implements EventListener {
return;
if (e.getTarget() == comboReport)
cmd_report();
else if (e.getTarget() == comboDrill)
cmd_drill();
else if (e.getTarget() == bFind)
cmd_find();
else if (e.getTarget() == bExport)
cmd_export();
else if (e.getTarget() == previewType)
cmd_render();
else if (e.getTarget() == bSendMail)
cmd_sendMail();
else if (e.getTarget() == bArchive)
@ -433,84 +521,15 @@ public class ZkReportViewer extends Window implements EventListener {
cmd_window(m_ddQ);
else if (e.getTarget() == m_daM)
cmd_window(m_daQ);
//
else if (!e.getTarget().getId().equals("reportFrame"))
mouse_clicked(e, false);
} // actionPerformed
/**************************************************************************
* (Re)Set Drill Accross Cursor
*/
private void cmd_drill()
{
m_drillDown = comboDrill.getSelectedIndex() < 1; // -1 or 0
} // cmd_drill
/**
* Mouse clicked
* @param e event
* @param rightClick true if right click
*/
private void mouse_clicked (Event e, boolean rightClick)
{
MouseEvent me = (MouseEvent) e;
Point point = new Point(me.getX(), me.getY());
if (rightClick)
{
m_ddQ = m_viewPanel.getDrillDown(point);
m_daQ = m_viewPanel.getDrillAcross(point);
m_ddM = null;
m_daM = null;
if (m_ddQ == null && m_daQ == null)
return;
// Create Menu
Menupopup pop = new Menupopup();
if (m_ddQ != null)
{
m_ddM = new Menuitem(m_ddQ.getDisplayName(Env.getCtx()));
m_ddM.setTooltiptext(m_ddQ.toString());
m_ddM.addEventListener(Events.ON_CLICK, this);
pop.appendChild(m_ddM);
}
if (m_daQ != null)
{
m_daM = new Menuitem(m_ddQ.getDisplayName(Env.getCtx()));
m_daM.setTooltiptext(m_daQ.toString());
m_daM.addEventListener(Events.ON_CLICK, this);
pop.appendChild(m_daM);
}
pop.open(me.getX(), me.getY());
return;
private void cmd_render() {
try {
renderReport();
} catch (Exception e) {
throw new AdempiereException("Failed to render report", e);
}
if (m_drillDown)
{
MQuery query = m_viewPanel.getDrillDown(point);
if (query != null)
{
log.info("Drill Down: " + query.getWhereClause(true));
executeDrill(query);
}
}
else if (comboDrill.getSelectedItem() != null)
{
ListItem li = comboDrill.getSelectedItem();
if(li.getValue() != null)
{
MQuery query = m_viewPanel.getDrillAcross(point);
if (query != null)
{
query.setTableName(li.getValue().toString());
log.info("Drill Accross: " + query.getWhereClause(true));
executeDrill(query);
}
}
}
cmd_drill(); // setCursor
} // mouse_clicked
}
/**
* Execute Drill to Query
@ -525,7 +544,7 @@ public class ZkReportViewer extends Window implements EventListener {
return;
}
if (AD_Table_ID != 0)
new AReport (AD_Table_ID, null, query);
new WReport (AD_Table_ID, query);
else
log.warning("No Table found for " + query.getWhereClause(true));
} // executeDrill
@ -638,7 +657,6 @@ public class ZkReportViewer extends Window implements EventListener {
AEnv.showCenterScreen(winExportFile);
cmd_drill(); // setCursor
} // cmd_export
private void exportFile()
@ -764,12 +782,14 @@ public class ZkReportViewer extends Window implements EventListener {
}
m_reportEngine.setPrintFormat(pf);
AMedia media = new AMedia(getTitle(), "pdf", "application/pdf", m_reportEngine.createPDFData());
iframe.setContent(media);
try {
renderReport();
} catch (Exception e) {
throw new AdempiereException("Failed to render report", e);
}
revalidate();
cmd_drill(); // setCursor
} // cmd_report
/**
@ -867,13 +887,15 @@ public class ZkReportViewer extends Window implements EventListener {
if (!find.isCancel())
{
m_reportEngine.setQuery(find.getQuery());
AMedia media = new AMedia(getTitle(), "pdf", "application/pdf", m_reportEngine.createPDFData());
iframe.setContent(media);
try {
renderReport();
} catch (Exception e) {
throw new AdempiereException("Failed to render report", e);
}
revalidate();
}
find = null;
}
cmd_drill(); // setCursor
} // cmd_find
/**

38
zkwebui/css/report.css Normal file
View File

@ -0,0 +1,38 @@
.rp-href {
color: #000000;
}
.rp-table {
border-width: 1px;
border-color: #BBBBBB;
border-style: solid;
border-collapse: collapse;
width: 90%;
background-color: #EBF1EF;
}
.rp-table th {
text-align: center;
padding: 2px;
font-weight: normal;
font-size: 13px;
background-color: #C6D1CD;
border-width: 1px;
border-color: #BBBBBB;
border-style: solid;
}
.rp-table td {
border-width: 1px;
border-color: #BBBBBB;
border-style: solid;
padding: 3px;
}
}
.rp-number {
background-color: #EBF1EF;
text-align: right;
padding: 3px;
}
.rp-text, .rp-date {
background-color: #EBF1EF;
text-align: left;
padding: 3px;
}

35
zkwebui/js/report.js Normal file
View File

@ -0,0 +1,35 @@
function zoom(cmpid, column, value){
zkau.send({uuid: cmpid, cmd: 'onZoom', data: [column, value], ctl: true});
}
function drillAcross(cmpid, column, value){
zkau.send({uuid: cmpid, cmd: 'onDrillAcross', data: [column, value], ctl: true});
}
function drillDown(cmpid, column, value){
zkau.send({uuid: cmpid, cmd: 'onDrillDown', data: [column, value], ctl: true});
}
function showColumnMenu(e, columnName, row) {
var d = document.getElementById(columnName + "_" + row + "_d");
var posx = 0;
var posy = 0;
if (!e) var e = window.event;
if (e.pageX || e.pageY) {
posx = e.pageX;
posy = e.pageY;
}
else if (e.clientX || e.clientY) {
posx = e.clientX + document.body.scrollLeft
+ document.documentElement.scrollLeft;
posy = e.clientY + document.body.scrollTop
+ document.documentElement.scrollTop;
}
d.style.top = posy;
d.style.left = posx;
d.style.display = "block";
setTimeout("document.getElementById('" + columnName + "_" + row + "_d" + "').style.display='none'", 3000);
}