Podpora pro sestavy definované přes JRXML soubory. Dynamické načítání
zul souborů pro nastavení sestavy. closes #81
This commit is contained in:
@@ -58,6 +58,6 @@ public class Constants {
|
||||
|
||||
public final static String DYNAMIC_REPORT_NAME = "Tabulková sestava";
|
||||
public final static ReportMapping REPORTS[] = {
|
||||
new ReportMapping(MOD_ADDRESSBOOK, new Report("Pokusná sestava", "report"))
|
||||
new ReportMapping(MOD_ADDRESSBOOK, new Report("Adresní karty", "address"))
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,11 +1,20 @@
|
||||
package info.bukova.isspst.reporting;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
public class GeneratorFactory {
|
||||
|
||||
@Autowired
|
||||
private ServletContext context;
|
||||
|
||||
public Generator createGenerator(ReportDefinition definition) {
|
||||
switch (definition.getReport().getType()) {
|
||||
case DYNAMIC:
|
||||
return new DynamicGenerator(definition);
|
||||
case DEFINED:
|
||||
return new PredefinedGenerator(definition, context);
|
||||
|
||||
default:
|
||||
return null;
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package info.bukova.isspst.reporting;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
|
||||
import net.sf.jasperreports.engine.JRException;
|
||||
import net.sf.jasperreports.engine.JasperReport;
|
||||
import net.sf.jasperreports.engine.JasperRunManager;
|
||||
import net.sf.jasperreports.engine.data.JRBeanCollectionDataSource;
|
||||
import net.sf.jasperreports.engine.util.JRLoader;
|
||||
import net.sf.jasperreports.engine.util.JRProperties;
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
public class PredefinedGenerator implements Generator {
|
||||
|
||||
private ReportDefinition definition;
|
||||
private ServletContext ctx;
|
||||
|
||||
public PredefinedGenerator(ReportDefinition definition, ServletContext ctx) {
|
||||
this.definition = definition;
|
||||
this.ctx = ctx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public byte[] generate() {
|
||||
byte[] bytes = null;
|
||||
|
||||
try {
|
||||
JasperReport report = (JasperReport) JRLoader.loadObject(getReportFile());
|
||||
JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Cp1250");
|
||||
bytes = JasperRunManager.runReportToPdf(report, definition.getParams(), new JRBeanCollectionDataSource(definition.getDataSet()));;
|
||||
} catch (JRException e) {
|
||||
// TODO Auto-generated catch block
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return bytes;
|
||||
}
|
||||
|
||||
protected File getReportFile() {
|
||||
return new File(ctx.getRealPath("WEB-INF/reports") + "/" + definition.getReport().getJasperFile() + ".jasper");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,16 +6,23 @@ public class Report {
|
||||
private ReportType type;
|
||||
private String name;
|
||||
private String jasperFile;
|
||||
private boolean hasSettings;
|
||||
|
||||
public Report() {
|
||||
|
||||
hasSettings = false;
|
||||
}
|
||||
|
||||
public Report(String name, String jasperFile) {
|
||||
this();
|
||||
this.type = ReportType.DEFINED;
|
||||
this.name = name;
|
||||
this.jasperFile = jasperFile;
|
||||
}
|
||||
|
||||
public Report(String name, String jasperFile, boolean hasSettings) {
|
||||
this(name, jasperFile);
|
||||
this.hasSettings = hasSettings;
|
||||
}
|
||||
|
||||
public ReportType getType() {
|
||||
return type;
|
||||
@@ -41,4 +48,12 @@ public class Report {
|
||||
this.jasperFile = jasperFile;
|
||||
}
|
||||
|
||||
public boolean isHasSettings() {
|
||||
return hasSettings;
|
||||
}
|
||||
|
||||
public void setHasSettings(boolean hasSettings) {
|
||||
this.hasSettings = hasSettings;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -301,7 +301,7 @@ public class ListViewModel<T extends DataModel> {
|
||||
Map<String, Object> params = new HashMap<String, Object>();
|
||||
params.put("reports", service.getReports());
|
||||
params.put("data", dataList);
|
||||
Window win = (Window) Executions.createComponents("/app/reportDialog.zul", null, params);
|
||||
Window win = (Window) Executions.createComponents("/app/reporting/reportDialog.zul", null, params);
|
||||
win.doModal();
|
||||
}
|
||||
|
||||
|
||||
+12
-49
@@ -1,4 +1,4 @@
|
||||
package info.bukova.isspst.ui;
|
||||
package info.bukova.isspst.ui.reporting;
|
||||
|
||||
import java.beans.BeanInfo;
|
||||
import java.beans.IntrospectionException;
|
||||
@@ -10,50 +10,27 @@ import java.util.List;
|
||||
import info.bukova.isspst.reporting.Report;
|
||||
import info.bukova.isspst.reporting.ReportDefinition;
|
||||
import info.bukova.isspst.reporting.ReportType;
|
||||
import info.bukova.isspst.ui.ListChecks;
|
||||
import info.bukova.isspst.ui.LocaleConverter;
|
||||
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.ExecutionArgParam;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
public class ReportDialogVM {
|
||||
public class ColSelectVM {
|
||||
|
||||
private List<Report> reports;
|
||||
private Report selected;
|
||||
private List<Object> data;
|
||||
@WireVariable
|
||||
private ReportDefinition reportDefinition;
|
||||
private LocaleConverter locConverter;
|
||||
|
||||
@Init
|
||||
public void init(@ExecutionArgParam("reports") List<Report> reports,
|
||||
@ExecutionArgParam("data") List<Object> data) {
|
||||
this.reports = reports;
|
||||
this.data = data;
|
||||
public void init() {
|
||||
locConverter = new LocaleConverter();
|
||||
|
||||
if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) {
|
||||
reportDefinition.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public LocaleConverter getLocConverter() {
|
||||
return locConverter;
|
||||
}
|
||||
|
||||
public List<Report> getReports() {
|
||||
return this.reports;
|
||||
}
|
||||
|
||||
public ReportDefinition getReportDefinition() {
|
||||
return reportDefinition;
|
||||
}
|
||||
|
||||
public ListChecks<String> getColumns() {
|
||||
Report selected = reportDefinition.getReport();
|
||||
List<Object> data = reportDefinition.getDataSet();
|
||||
|
||||
if (selected == null || selected.getType() != ReportType.DYNAMIC) {
|
||||
return null;
|
||||
}
|
||||
@@ -79,26 +56,12 @@ public class ReportDialogVM {
|
||||
return columns;
|
||||
}
|
||||
|
||||
public Report getSelected() {
|
||||
return selected;
|
||||
public LocaleConverter getLocConverter() {
|
||||
return locConverter;
|
||||
}
|
||||
|
||||
@NotifyChange("columns")
|
||||
public void setSelected(Report selected) {
|
||||
this.selected = selected;
|
||||
}
|
||||
|
||||
@Command
|
||||
public void print(@BindingParam("window") Window window) {
|
||||
reportDefinition.setDataSet(data);
|
||||
reportDefinition.setReport(selected);
|
||||
|
||||
if (window != null) {
|
||||
window.detach();
|
||||
}
|
||||
|
||||
Window reportWin = (Window) Executions.createComponents("/app/report.zul", null, null);
|
||||
reportWin.doModal();
|
||||
public ReportDefinition getReportDefinition() {
|
||||
return reportDefinition;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
package info.bukova.isspst.ui.reporting;
|
||||
|
||||
import info.bukova.isspst.reporting.Report;
|
||||
import info.bukova.isspst.reporting.ReportDefinition;
|
||||
import info.bukova.isspst.reporting.ReportType;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.zkoss.bind.annotation.BindingParam;
|
||||
import org.zkoss.bind.annotation.Command;
|
||||
import org.zkoss.bind.annotation.ExecutionArgParam;
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
import org.zkoss.bind.annotation.NotifyChange;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
||||
import org.zkoss.zul.Window;
|
||||
|
||||
public class ReportDialogVM {
|
||||
|
||||
private List<Report> reports;
|
||||
private Report selected;
|
||||
@WireVariable
|
||||
private ReportDefinition reportDefinition;
|
||||
|
||||
@Init
|
||||
public void init(@ExecutionArgParam("reports") List<Report> reports,
|
||||
@ExecutionArgParam("data") List<Object> data) {
|
||||
this.reports = reports;
|
||||
|
||||
if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) {
|
||||
reportDefinition.clear();
|
||||
}
|
||||
|
||||
reportDefinition.setDataSet(data);
|
||||
}
|
||||
|
||||
public List<Report> getReports() {
|
||||
return this.reports;
|
||||
}
|
||||
|
||||
public ReportDefinition getReportDefinition() {
|
||||
return reportDefinition;
|
||||
}
|
||||
|
||||
public Report getSelected() {
|
||||
return selected;
|
||||
}
|
||||
|
||||
@NotifyChange("optionsForm")
|
||||
public void setSelected(Report selected) {
|
||||
this.selected = selected;
|
||||
reportDefinition.setReport(selected);
|
||||
}
|
||||
|
||||
@Command
|
||||
public void print(@BindingParam("window") Window window) {
|
||||
if (window != null) {
|
||||
window.detach();
|
||||
}
|
||||
|
||||
Window reportWin = (Window) Executions.createComponents("/app/reporting/report.zul", null, null);
|
||||
reportWin.doModal();
|
||||
}
|
||||
|
||||
public String getOptionsForm() {
|
||||
if (selected != null && selected.getType() == ReportType.DYNAMIC) {
|
||||
return "/app/reporting/colSelect.zul";
|
||||
} else if (selected != null && selected.isHasSettings()) {
|
||||
return "/app/reporting/" + selected.getJasperFile() + ".zul";
|
||||
} else {
|
||||
return "/app/reporting/noOptions.zul";
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
package info.bukova.isspst.ui;
|
||||
package info.bukova.isspst.ui.reporting;
|
||||
|
||||
import org.zkoss.bind.annotation.Init;
|
||||
|
||||
Reference in New Issue
Block a user