Podpora tisku. Implementace tisku dynamických sestav.
							parent
							
								
									34c4144f46
								
							
						
					
					
						commit
						25a4d2dfb7
					
				@ -0,0 +1,44 @@
 | 
			
		||||
package info.bukova.isspst.reporting;
 | 
			
		||||
 | 
			
		||||
import java.util.Arrays;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
 | 
			
		||||
public class DefinitionFiller {
 | 
			
		||||
	
 | 
			
		||||
	@Autowired
 | 
			
		||||
	ReportDefinition definition;
 | 
			
		||||
	
 | 
			
		||||
	@SuppressWarnings("unchecked")
 | 
			
		||||
	private void setData(Object data) {
 | 
			
		||||
		if (data instanceof List) {
 | 
			
		||||
			definition.setDataSet((List<Object>)data);
 | 
			
		||||
		} else {
 | 
			
		||||
			definition.setSingleObject(data);
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void fillDefinition(Report report, Object data) {
 | 
			
		||||
		definition.clear();
 | 
			
		||||
		definition.setReport(report);
 | 
			
		||||
		setData(data);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void fillDefinition(Report report, Object data, Map<String, Object> params) {
 | 
			
		||||
		fillDefinition(report, data);
 | 
			
		||||
		definition.setParams(params);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void fillDefinition(Report report, Object data, String[] columns) {
 | 
			
		||||
		fillDefinition(report, data);
 | 
			
		||||
		definition.setFieldsToPrint(Arrays.asList(columns));
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void fillDefinition(Report report, Object data, String[] columns, Map<String, Object> params) {
 | 
			
		||||
		fillDefinition(report, data, params);
 | 
			
		||||
		definition.setFieldsToPrint(Arrays.asList(columns));
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,101 @@
 | 
			
		||||
package info.bukova.isspst.reporting;
 | 
			
		||||
 | 
			
		||||
import java.lang.reflect.InvocationTargetException;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
import net.sf.jasperreports.engine.JRDataSource;
 | 
			
		||||
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.JRProperties;
 | 
			
		||||
 | 
			
		||||
import org.apache.commons.beanutils.PropertyUtils;
 | 
			
		||||
 | 
			
		||||
import ar.com.fdvs.dj.core.DynamicJasperHelper;
 | 
			
		||||
import ar.com.fdvs.dj.core.layout.ClassicLayoutManager;
 | 
			
		||||
import ar.com.fdvs.dj.domain.DynamicReport;
 | 
			
		||||
import ar.com.fdvs.dj.domain.builders.ColumnBuilderException;
 | 
			
		||||
import ar.com.fdvs.dj.domain.builders.FastReportBuilder;
 | 
			
		||||
 | 
			
		||||
@SuppressWarnings("deprecation")
 | 
			
		||||
public class DynamicGenerator implements Generator {
 | 
			
		||||
	
 | 
			
		||||
	private ReportDefinition definition;
 | 
			
		||||
	private static Map<Class<?>,Class<?>> primitiveMap = new HashMap<Class<?>,Class<?>>();
 | 
			
		||||
    static {
 | 
			
		||||
    	primitiveMap.put(boolean.class, Boolean.class);
 | 
			
		||||
    	primitiveMap.put(byte.class, Byte.class);
 | 
			
		||||
    	primitiveMap.put(char.class, Character.class);
 | 
			
		||||
    	primitiveMap.put(short.class, Short.class);
 | 
			
		||||
    	primitiveMap.put(int.class, Integer.class);
 | 
			
		||||
    	primitiveMap.put(long.class, Long.class);
 | 
			
		||||
    	primitiveMap.put(float.class, Float.class);
 | 
			
		||||
    	primitiveMap.put(double.class, Double.class);
 | 
			
		||||
    }
 | 
			
		||||
	
 | 
			
		||||
	public DynamicGenerator(ReportDefinition definition) {
 | 
			
		||||
		this.definition = definition;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public byte[] generate() {
 | 
			
		||||
		FastReportBuilder rb = new FastReportBuilder();
 | 
			
		||||
		DynamicReport dr;
 | 
			
		||||
		
 | 
			
		||||
		for (String col : definition.getFieldsToPrint()) {
 | 
			
		||||
			Class<?> clazz = colClass(col);
 | 
			
		||||
			if (clazz != null) {
 | 
			
		||||
				try {
 | 
			
		||||
					rb.addColumn(col, col, clazz, 30, false);
 | 
			
		||||
				} catch (ColumnBuilderException e) {
 | 
			
		||||
					// TODO Auto-generated catch block
 | 
			
		||||
					e.printStackTrace();
 | 
			
		||||
				} catch (ClassNotFoundException e) {
 | 
			
		||||
					// TODO Auto-generated catch block
 | 
			
		||||
					e.printStackTrace();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		rb.setTitle(definition.getReportTitle());
 | 
			
		||||
		rb.setUseFullPageWidth(true);
 | 
			
		||||
		dr = rb.build();
 | 
			
		||||
		
 | 
			
		||||
		JRProperties.setProperty("net.sf.jasperreports.default.pdf.encoding", "Cp1250");
 | 
			
		||||
		JRDataSource ds = new JRBeanCollectionDataSource(definition.getDataSet());
 | 
			
		||||
		try {
 | 
			
		||||
			JasperReport report = DynamicJasperHelper.generateJasperReport(dr, new ClassicLayoutManager(), definition.getParams());
 | 
			
		||||
			return JasperRunManager.runReportToPdf(report, definition.getParams(), ds);
 | 
			
		||||
		} catch (JRException e) {
 | 
			
		||||
			// TODO Auto-generated catch block
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	private Class<?> colClass(String col) {
 | 
			
		||||
		List<Object> data = definition.getDataSet();
 | 
			
		||||
		if (data != null && data.size() > 0) {
 | 
			
		||||
			try {
 | 
			
		||||
				Class<?> clazz = PropertyUtils.getPropertyType(data.get(0), col);
 | 
			
		||||
				if (clazz.isPrimitive()) {
 | 
			
		||||
					clazz = primitiveMap.get(clazz);
 | 
			
		||||
				}
 | 
			
		||||
				return clazz;
 | 
			
		||||
			} catch (IllegalAccessException e) {
 | 
			
		||||
				return null;
 | 
			
		||||
			} catch (InvocationTargetException e) {
 | 
			
		||||
				return null;
 | 
			
		||||
			} catch (NoSuchMethodException e) {
 | 
			
		||||
				return null;
 | 
			
		||||
			} 
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,7 @@
 | 
			
		||||
package info.bukova.isspst.reporting;
 | 
			
		||||
 | 
			
		||||
public interface Generator {
 | 
			
		||||
	
 | 
			
		||||
	byte[] generate();
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,15 @@
 | 
			
		||||
package info.bukova.isspst.reporting;
 | 
			
		||||
 | 
			
		||||
public class GeneratorFactory {
 | 
			
		||||
	
 | 
			
		||||
	public Generator createGenerator(ReportDefinition definition) {
 | 
			
		||||
		switch (definition.getReport().getType()) {
 | 
			
		||||
		case DYNAMIC:
 | 
			
		||||
			return new DynamicGenerator(definition);
 | 
			
		||||
 | 
			
		||||
		default:
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,44 @@
 | 
			
		||||
package info.bukova.isspst.reporting;
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
public class Report {
 | 
			
		||||
 | 
			
		||||
	private ReportType type;
 | 
			
		||||
	private String name;
 | 
			
		||||
	private String jasperFile;
 | 
			
		||||
	
 | 
			
		||||
	public Report() {
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public Report(String name, String jasperFile) {
 | 
			
		||||
		this.type = ReportType.DEFINED;
 | 
			
		||||
		this.name = name;
 | 
			
		||||
		this.jasperFile = jasperFile;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ReportType getType() {
 | 
			
		||||
		return type;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setType(ReportType type) {
 | 
			
		||||
		this.type = type;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getName() {
 | 
			
		||||
		return name;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setName(String name) {
 | 
			
		||||
		this.name = name;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getJasperFile() {
 | 
			
		||||
		return jasperFile;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setJasperFile(String jasperFile) {
 | 
			
		||||
		this.jasperFile = jasperFile;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,63 @@
 | 
			
		||||
package info.bukova.isspst.reporting;
 | 
			
		||||
 | 
			
		||||
import java.io.IOException;
 | 
			
		||||
 | 
			
		||||
import javax.servlet.ServletOutputStream;
 | 
			
		||||
import javax.servlet.http.HttpServletResponse;
 | 
			
		||||
 | 
			
		||||
import org.springframework.beans.factory.annotation.Autowired;
 | 
			
		||||
import org.springframework.stereotype.Controller;
 | 
			
		||||
import org.springframework.web.bind.annotation.RequestMapping;
 | 
			
		||||
 | 
			
		||||
@Controller
 | 
			
		||||
public class ReportController {
 | 
			
		||||
	
 | 
			
		||||
	@Autowired
 | 
			
		||||
	private ReportDefinition reportDefinition;
 | 
			
		||||
	@Autowired
 | 
			
		||||
	private GeneratorFactory factory;
 | 
			
		||||
	
 | 
			
		||||
	@RequestMapping("report.pdf")
 | 
			
		||||
	public void pdfReport(HttpServletResponse response) {
 | 
			
		||||
		Generator gen = factory.createGenerator(reportDefinition);
 | 
			
		||||
		byte[] data = gen.generate();
 | 
			
		||||
		String contentType = "application/pdf";
 | 
			
		||||
		
 | 
			
		||||
		ServletOutputStream os = null;
 | 
			
		||||
		
 | 
			
		||||
		try {
 | 
			
		||||
			os = response.getOutputStream();
 | 
			
		||||
		} catch (IOException e1) {
 | 
			
		||||
			e1.printStackTrace();
 | 
			
		||||
			return;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
//		if (reportDefinition.getReport() == null || reportDefinition.getDataSet() == null) {
 | 
			
		||||
//			writeError(os, "Definition is null");
 | 
			
		||||
//			return;
 | 
			
		||||
//		}
 | 
			
		||||
		
 | 
			
		||||
		response.setContentType(contentType);
 | 
			
		||||
		response.setContentLength(data.length);
 | 
			
		||||
				
 | 
			
		||||
		try {
 | 
			
		||||
			os.write(data, 0, data.length);
 | 
			
		||||
			os.flush();
 | 
			
		||||
			os.close();
 | 
			
		||||
		} catch (IOException e) {
 | 
			
		||||
			e.printStackTrace();
 | 
			
		||||
//		} catch (ReportException e) {
 | 
			
		||||
//			writeError(os, e);
 | 
			
		||||
		} finally {
 | 
			
		||||
			if (os != null) {
 | 
			
		||||
				try {
 | 
			
		||||
					os.flush();
 | 
			
		||||
					os.close();
 | 
			
		||||
				} catch (IOException e) {
 | 
			
		||||
					e.printStackTrace();
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,101 @@
 | 
			
		||||
package info.bukova.isspst.reporting;
 | 
			
		||||
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.HashMap;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
import java.util.Map;
 | 
			
		||||
 | 
			
		||||
public class ReportDefinition implements Serializable {
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * 
 | 
			
		||||
	 */
 | 
			
		||||
	private static final long serialVersionUID = 995511957163031085L;
 | 
			
		||||
	private Report report;
 | 
			
		||||
	private List<Object> dataSet;
 | 
			
		||||
	private Map<String, Object> params;
 | 
			
		||||
	private List<String> fieldsToPrint;
 | 
			
		||||
	private String reportTitle;
 | 
			
		||||
 | 
			
		||||
 	public ReportDefinition() {
 | 
			
		||||
 		params = new HashMap<String, Object>();
 | 
			
		||||
 		fieldsToPrint = new ArrayList<String>();
 | 
			
		||||
 	}
 | 
			
		||||
	
 | 
			
		||||
	public List<Object> getDataSet() {
 | 
			
		||||
		return dataSet;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setDataSet(List<Object> dataSet) {
 | 
			
		||||
		this.dataSet = dataSet;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void setSingleObject(Object o) {
 | 
			
		||||
		if (this.dataSet != null) {
 | 
			
		||||
			dataSet.clear();
 | 
			
		||||
		} else {
 | 
			
		||||
			dataSet = new ArrayList<Object>();
 | 
			
		||||
		}
 | 
			
		||||
	
 | 
			
		||||
		dataSet.add(o);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public Map<String, Object> getParams() {
 | 
			
		||||
		return params;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setParams(Map<String, Object> params) {
 | 
			
		||||
		this.params.clear();
 | 
			
		||||
		this.params.putAll(params);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public void setParam(String key, Object value) {
 | 
			
		||||
		this.params.put(key, value);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public Object getParam(String key) {
 | 
			
		||||
		return this.params.get(key);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public List<String> getFieldsToPrint() {
 | 
			
		||||
		return fieldsToPrint;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setFieldsToPrint(List<String> fieldsToPrint) {
 | 
			
		||||
		this.fieldsToPrint = fieldsToPrint;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public Report getReport() {
 | 
			
		||||
		return report;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setReport(Report report) {
 | 
			
		||||
		this.report = report;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public Class<?> gatDataClass() {
 | 
			
		||||
		if (dataSet != null && dataSet.size() > 0) {
 | 
			
		||||
			return dataSet.get(0).getClass();
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		return null;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void clear() {
 | 
			
		||||
		report = null;
 | 
			
		||||
		fieldsToPrint.clear();
 | 
			
		||||
		dataSet = null;
 | 
			
		||||
		reportTitle = "";
 | 
			
		||||
		params.clear();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getReportTitle() {
 | 
			
		||||
		return reportTitle;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setReportTitle(String reportTitle) {
 | 
			
		||||
		this.reportTitle = reportTitle;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,29 @@
 | 
			
		||||
package info.bukova.isspst.reporting;
 | 
			
		||||
 | 
			
		||||
public class ReportMapping {
 | 
			
		||||
 | 
			
		||||
	private Report report;
 | 
			
		||||
	private String module;
 | 
			
		||||
 | 
			
		||||
	public ReportMapping(String module, Report report) {
 | 
			
		||||
		this.module = module;
 | 
			
		||||
		this.report = report;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public Report getReport() {
 | 
			
		||||
		return report;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setReport(Report report) {
 | 
			
		||||
		this.report = report;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getModule() {
 | 
			
		||||
		return module;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setModule(String module) {
 | 
			
		||||
		this.module = module;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,8 @@
 | 
			
		||||
package info.bukova.isspst.reporting;
 | 
			
		||||
 | 
			
		||||
public enum ReportType {
 | 
			
		||||
	
 | 
			
		||||
	DYNAMIC,
 | 
			
		||||
	DEFINED
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,40 @@
 | 
			
		||||
package info.bukova.isspst.ui;
 | 
			
		||||
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class Check<T> {
 | 
			
		||||
 | 
			
		||||
	private T member;
 | 
			
		||||
	private List<T> list;
 | 
			
		||||
	private boolean checked;
 | 
			
		||||
	
 | 
			
		||||
	public Check(List<T> list, T member) {
 | 
			
		||||
		this.member = member;
 | 
			
		||||
		this.list = list;
 | 
			
		||||
		if (list.contains(member)) {
 | 
			
		||||
			checked = true;
 | 
			
		||||
		} else {
 | 
			
		||||
			checked = false;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public boolean isChecked() {
 | 
			
		||||
		return checked;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setChecked(boolean checked) {
 | 
			
		||||
		if (checked && !list.contains(member)) {
 | 
			
		||||
			list.add(member);
 | 
			
		||||
		} else {
 | 
			
		||||
			list.remove(member);
 | 
			
		||||
		}
 | 
			
		||||
		this.checked = checked;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public T getMember() {
 | 
			
		||||
		return member;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,21 @@
 | 
			
		||||
package info.bukova.isspst.ui;
 | 
			
		||||
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
public class ListChecks<T> {
 | 
			
		||||
	
 | 
			
		||||
	private List<Check<T>> checks;
 | 
			
		||||
	
 | 
			
		||||
	public ListChecks(List<T> destList, List<T> sourceList) {
 | 
			
		||||
		checks = new ArrayList<Check<T>>();
 | 
			
		||||
		for (T member : sourceList) {
 | 
			
		||||
			checks.add(new Check<T>(destList, member));
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public List<Check<T>> getChecks() {
 | 
			
		||||
		return checks;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,96 @@
 | 
			
		||||
package info.bukova.isspst.ui;
 | 
			
		||||
 | 
			
		||||
import java.beans.BeanInfo;
 | 
			
		||||
import java.beans.IntrospectionException;
 | 
			
		||||
import java.beans.Introspector;
 | 
			
		||||
import java.beans.PropertyDescriptor;
 | 
			
		||||
import java.util.ArrayList;
 | 
			
		||||
import java.util.List;
 | 
			
		||||
 | 
			
		||||
import info.bukova.isspst.reporting.Report;
 | 
			
		||||
import info.bukova.isspst.reporting.ReportDefinition;
 | 
			
		||||
import info.bukova.isspst.reporting.ReportType;
 | 
			
		||||
 | 
			
		||||
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;
 | 
			
		||||
	private List<Object> data;
 | 
			
		||||
	@WireVariable
 | 
			
		||||
	private ReportDefinition reportDefinition;
 | 
			
		||||
	
 | 
			
		||||
	@Init
 | 
			
		||||
	public void init(@ExecutionArgParam("reports") List<Report> reports, 
 | 
			
		||||
			@ExecutionArgParam("data") List<Object> data) {
 | 
			
		||||
		this.reports = reports;
 | 
			
		||||
		this.data = data;
 | 
			
		||||
		
 | 
			
		||||
		if (data != null && data.size() > 0 && data.get(0).getClass() != reportDefinition.gatDataClass()) {
 | 
			
		||||
			reportDefinition.clear();
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public List<Report> getReports() {
 | 
			
		||||
		return this.reports;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public ReportDefinition getReportDefinition() {
 | 
			
		||||
		return reportDefinition;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public ListChecks<String> getColumns() {
 | 
			
		||||
		if (selected == null || selected.getType() != ReportType.DYNAMIC) {
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
		if (data == null || data.size() == 0) {
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		BeanInfo beanInfo;
 | 
			
		||||
		try {
 | 
			
		||||
			beanInfo = Introspector.getBeanInfo(data.get(0).getClass());
 | 
			
		||||
		} catch (IntrospectionException e) {
 | 
			
		||||
			return null;
 | 
			
		||||
		}
 | 
			
		||||
	    PropertyDescriptor[] pds = beanInfo.getPropertyDescriptors();
 | 
			
		||||
	    List<String> properties = new ArrayList<String>();
 | 
			
		||||
	    for (PropertyDescriptor pd : pds) {
 | 
			
		||||
	    	properties.add(pd.getName());
 | 
			
		||||
	    }
 | 
			
		||||
		ListChecks<String> columns = new ListChecks<String>(reportDefinition.getFieldsToPrint(), properties);
 | 
			
		||||
		
 | 
			
		||||
		return columns;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public Report getSelected() {
 | 
			
		||||
		return selected;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@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();
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,12 @@
 | 
			
		||||
package info.bukova.isspst.ui;
 | 
			
		||||
 | 
			
		||||
import org.zkoss.bind.annotation.Init;
 | 
			
		||||
 | 
			
		||||
public class ReportVM {
 | 
			
		||||
	
 | 
			
		||||
	@Init
 | 
			
		||||
	public void init() {
 | 
			
		||||
		
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
@ -0,0 +1,10 @@
 | 
			
		||||
<?page title="${labels.ReportReport}" contentType="text/html;charset=UTF-8"?>
 | 
			
		||||
<zk>
 | 
			
		||||
<window title="${labels.ReportReport}" border="normal" closable="true" apply="org.zkoss.bind.BindComposer"
 | 
			
		||||
	viewModel="@id('vm') @init('info.bukova.isspst.ui.ReportVM')">
 | 
			
		||||
	<toolbar>
 | 
			
		||||
		<toolbarbutton image="/img/send.png" tooltiptext="${labels.ReportSend}"/>
 | 
			
		||||
	</toolbar>
 | 
			
		||||
	<iframe width="800px" height="680px" src="/api/report.pdf"/>
 | 
			
		||||
</window>
 | 
			
		||||
</zk>
 | 
			
		||||
@ -0,0 +1,32 @@
 | 
			
		||||
<?page title="${labels.ReportReports}" contentType="text/html;charset=UTF-8"?>
 | 
			
		||||
<zk>
 | 
			
		||||
<window id="reportDialog" title="${labels.ReportReports}" border="normal" apply="org.zkoss.bind.BindComposer"
 | 
			
		||||
	viewModel="@id('vm') @init('info.bukova.isspst.ui.ReportDialogVM')"
 | 
			
		||||
	closable="true" width="550px">
 | 
			
		||||
	
 | 
			
		||||
	<hbox>
 | 
			
		||||
	<listbox model="@load(vm.reports)" width="250px" height="350px" selectedItem="@bind(vm.selected)">
 | 
			
		||||
		<template name="model">
 | 
			
		||||
			<listitem>
 | 
			
		||||
				<listcell><label value="@load(each.name)"/></listcell>
 | 
			
		||||
			</listitem>
 | 
			
		||||
		</template>
 | 
			
		||||
	</listbox>
 | 
			
		||||
	<groupbox mold="3d" closable="false" width="270px">
 | 
			
		||||
		<caption label="${labels.ReportOptions}"></caption>
 | 
			
		||||
		<hbox>
 | 
			
		||||
			<label value="${labels.ReportTitle}"/> <textbox value="@bind(vm.reportDefinition.reportTitle)"/>
 | 
			
		||||
		</hbox>
 | 
			
		||||
		<vbox children="@load(vm.columns.checks)">
 | 
			
		||||
			<template name="children">
 | 
			
		||||
				<checkbox label="@load(each.member)" checked="@bind(each.checked)"/>
 | 
			
		||||
			</template>		
 | 
			
		||||
		</vbox>
 | 
			
		||||
	</groupbox>
 | 
			
		||||
	</hbox>
 | 
			
		||||
	<hbox>
 | 
			
		||||
		<button label="${labels.ReportPrint}" onClick="@command('print', window=reportDialog)"/> <button label="${labels.ButtonStorno}" onClick="reportDialog.detach()"/>
 | 
			
		||||
	</hbox>
 | 
			
		||||
	
 | 
			
		||||
</window>
 | 
			
		||||
</zk>
 | 
			
		||||
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 3.7 KiB  | 
											
												Binary file not shown.
											
										
									
								| 
		 After Width: | Height: | Size: 3.7 KiB  | 
					Loading…
					
					
				
		Reference in New Issue