|
|
|
@ -1,9 +1,13 @@
|
|
|
|
|
package info.bukova.isspst.ui.reporting;
|
|
|
|
|
|
|
|
|
|
import info.bukova.isspst.Module;
|
|
|
|
|
import info.bukova.isspst.ModuleUtils;
|
|
|
|
|
import info.bukova.isspst.data.DataModel;
|
|
|
|
|
import info.bukova.isspst.reporting.Report;
|
|
|
|
|
import info.bukova.isspst.reporting.ReportDefinition;
|
|
|
|
|
import info.bukova.isspst.reporting.ReportType;
|
|
|
|
|
import info.bukova.isspst.services.Service;
|
|
|
|
|
import info.bukova.isspst.sort.ReflectionTools;
|
|
|
|
|
import info.bukova.isspst.ui.DocumentViewModel;
|
|
|
|
|
import org.zkoss.bind.annotation.BindingParam;
|
|
|
|
|
import org.zkoss.bind.annotation.Command;
|
|
|
|
@ -11,9 +15,12 @@ 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.Sessions;
|
|
|
|
|
import org.zkoss.zk.ui.select.annotation.WireVariable;
|
|
|
|
|
import org.zkoss.zul.Window;
|
|
|
|
|
|
|
|
|
|
import javax.servlet.ServletContext;
|
|
|
|
|
import java.lang.reflect.InvocationTargetException;
|
|
|
|
|
import java.util.List;
|
|
|
|
|
|
|
|
|
|
public class ReportDialogVM extends DocumentViewModel
|
|
|
|
@ -24,7 +31,8 @@ public class ReportDialogVM extends DocumentViewModel
|
|
|
|
|
@WireVariable
|
|
|
|
|
private ReportDefinition reportDefinition;
|
|
|
|
|
private List<Object> dataList;
|
|
|
|
|
private Object singleObject;
|
|
|
|
|
private Object singleObject;
|
|
|
|
|
private ServletContext ctx;
|
|
|
|
|
|
|
|
|
|
@Init(superclass = true)
|
|
|
|
|
public void init(@ExecutionArgParam("reports") List<Report> reports,
|
|
|
|
@ -40,6 +48,8 @@ public class ReportDialogVM extends DocumentViewModel
|
|
|
|
|
dataList = data;
|
|
|
|
|
this.singleObject = singleObject;
|
|
|
|
|
reportDefinition.setService(service);
|
|
|
|
|
|
|
|
|
|
ctx = Sessions.getCurrent().getWebApp().getServletContext();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public List<Report> getReports() {
|
|
|
|
@ -59,11 +69,36 @@ public class ReportDialogVM extends DocumentViewModel
|
|
|
|
|
this.selected = selected;
|
|
|
|
|
reportDefinition.setReport(selected);
|
|
|
|
|
if (selected.isSingleRecord()) {
|
|
|
|
|
reportDefinition.setSingleObject(singleObject);
|
|
|
|
|
setObject(selected);
|
|
|
|
|
} else {
|
|
|
|
|
reportDefinition.setDataSet(dataList);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void setObject(Report report) {
|
|
|
|
|
if (report.getProperty() == null) {
|
|
|
|
|
reportDefinition.setSingleObject(singleObject);
|
|
|
|
|
} else {
|
|
|
|
|
try {
|
|
|
|
|
Object o = ReflectionTools.getGetterMethod(singleObject, report.getProperty()).invoke(singleObject);
|
|
|
|
|
reportDefinition.setSingleObject(o);
|
|
|
|
|
|
|
|
|
|
if (!(o instanceof DataModel)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Module m = ModuleUtils.getModule((DataModel)o, ctx);
|
|
|
|
|
|
|
|
|
|
if (m != null) {
|
|
|
|
|
reportDefinition.setService((Service<Object>) ModuleUtils.getServiceInstance(m, ctx));
|
|
|
|
|
}
|
|
|
|
|
} catch (IllegalAccessException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
} catch (InvocationTargetException e) {
|
|
|
|
|
e.printStackTrace();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@Command
|
|
|
|
|
public void print(@BindingParam("window") Window window) {
|
|
|
|
|