View Javadoc

1   package ar.com.fdvs.dj.test;
2   
3   import java.util.HashMap;
4   import java.util.Map;
5   
6   import net.sf.jasperreports.engine.JRDataSource;
7   import net.sf.jasperreports.engine.JRException;
8   import net.sf.jasperreports.engine.JasperPrint;
9   import net.sf.jasperreports.view.JasperViewer;
10  import ar.com.fdvs.dj.core.DJConstants;
11  import ar.com.fdvs.dj.core.DynamicJasperHelper;
12  import ar.com.fdvs.dj.core.layout.ClassicLayoutManager;
13  import ar.com.fdvs.dj.domain.builders.DynamicReportBuilder;
14  import ar.com.fdvs.dj.domain.builders.SubReportBuilder;
15  import ar.com.fdvs.dj.domain.entities.Subreport;
16  
17  /**
18   * This report shows how to add concatenated subreports that start in a new page
19   * @author Anis BEN RHOUMA 
20   *
21   */
22  public class MultiReportConcatenated {
23  
24  	/**
25  	 * @param args
26  	 */
27  	public static void main(String[] args) {
28  		
29  		Map params = new HashMap();
30  		
31  		ClassicLayoutManager layoutManager = new ClassicLayoutManager();
32  		
33  		DynamicReportBuilder drb = new DynamicReportBuilder();
34  		drb.setTitle("TEST");
35  		drb.setSubtitle("This is a report with many concatenated subreports which should start in a new page");
36  		drb.setWhenNoDataAllSectionNoDetail();
37  		for (int i = 0; i < 3; i++) {
38  			FastReportTest report = new FastReportTest();
39  
40  			try {
41  				report.dr = report.buildReport();
42  				report.dr.setTitle("REPORT N°: " + i);
43  				report.dr.setWhenNoDataType(DJConstants.WHEN_NO_DATA_TYPE_ALL_SECTIONS_NO_DETAIL);
44  				
45  				String dataSourcePath = "DataSource" + i;
46  				JRDataSource dataSource = report.getDataSource();
47  				params.put(dataSourcePath, dataSource);
48  
49  				Subreport subreport = new SubReportBuilder()
50  				.setStartInNewPage(true)
51  				.setDataSource(DJConstants.DATA_SOURCE_ORIGIN_PARAMETER, DJConstants.DATA_SOURCE_TYPE_JRDATASOURCE, dataSourcePath)
52  				.setDynamicReport(report.dr,  new ClassicLayoutManager())
53  				.build();
54  
55  				drb.addConcatenatedReport(subreport);
56  
57  			} catch (Exception e) {
58  				e.printStackTrace();
59  			}
60  			
61  		}
62  
63  		try {
64  			JasperPrint jasperPrint = DynamicJasperHelper.generateJasperPrint(drb.build(), layoutManager, params);
65  			JasperViewer.viewReport(jasperPrint);
66  			
67  		} catch (JRException e) {
68  			e.printStackTrace();
69  		}
70  		
71  	}
72  
73  }
74  
75