Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/common/JasperDesigner.java @ 9005:460fcc128794
jasper multiple
author | gernotbelger |
---|---|
date | Tue, 17 Apr 2018 13:19:56 +0200 |
parents | |
children | e6b63b2b41b9 |
comparison
equal
deleted
inserted
replaced
9004:4635872e7117 | 9005:460fcc128794 |
---|---|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.common; | |
11 | |
12 import net.sf.jasperreports.engine.JRBand; | |
13 import net.sf.jasperreports.engine.JRChild; | |
14 import net.sf.jasperreports.engine.JRElement; | |
15 import net.sf.jasperreports.engine.design.JasperDesign; | |
16 | |
17 /** | |
18 * @author Domenico Nardi Tironi | |
19 */ | |
20 public class JasperDesigner { | |
21 | |
22 private final JasperDesign design; | |
23 private final MetaAndTableJRDataSource source; | |
24 private int startpageOffset = 0; | |
25 | |
26 public JasperDesigner(final JasperDesign design, final MetaAndTableJRDataSource source) { | |
27 this.design = design; | |
28 this.source = source; | |
29 } | |
30 | |
31 public void removeColumn(final String key) { | |
32 | |
33 final JRBand colchildren = this.design.getColumnHeader(); | |
34 final JRBand datachildren = this.design.getDetailSection().getBands()[0]; | |
35 int width = 0; | |
36 if (colchildren != null && datachildren != null) { | |
37 | |
38 final JRElement elementCol = colchildren.getElementByKey(key); | |
39 final JRElement elementData = datachildren.getElementByKey(key); | |
40 if (elementCol != null && elementData != null) { | |
41 width = elementCol.getWidth() + width; | |
42 final int indexCol = colchildren.getChildren().indexOf(elementCol); | |
43 final int indexData = datachildren.getChildren().indexOf(elementData); | |
44 | |
45 elementCol.getElementGroup().getChildren().remove(elementCol); | |
46 elementData.getElementGroup().getChildren().remove(elementData); | |
47 | |
48 for (int j = indexCol; j < colchildren.getChildren().size(); j++) { | |
49 final JRChild element = colchildren.getChildren().get(j); | |
50 if (element instanceof JRElement) { | |
51 ((JRElement) element).setX(((JRElement) element).getX() - width); | |
52 } | |
53 } | |
54 for (int j = indexData; j < datachildren.getChildren().size(); j++) { | |
55 final JRChild element = datachildren.getChildren().get(j); | |
56 if (element instanceof JRElement) { | |
57 ((JRElement) element).setX(((JRElement) element).getX() - width); | |
58 } | |
59 } | |
60 } | |
61 | |
62 // width auf letzte spalte schlagen | |
63 final JRElement elementColLast = colchildren.getElements()[colchildren.getElements().length - 1]; | |
64 if (elementColLast != null) { | |
65 elementColLast.setWidth(elementColLast.getWidth() + width); | |
66 } | |
67 final JRElement elementDataLast = datachildren.getElements()[datachildren.getElements().length - 1]; | |
68 if (elementDataLast != null) { | |
69 elementDataLast.setWidth(elementDataLast.getWidth() + width); | |
70 } | |
71 } else { | |
72 // TODO: LOG | |
73 System.out.print("Column not found for key: " + key); | |
74 } | |
75 | |
76 } | |
77 | |
78 JasperDesign getDesign() { | |
79 return this.design; | |
80 } | |
81 | |
82 public MetaAndTableJRDataSource getSource() { | |
83 return this.source; | |
84 } | |
85 | |
86 public void setPagesCount(final int pagesCount) { | |
87 this.startpageOffset = pagesCount; | |
88 } | |
89 | |
90 public int getPagesCount() { | |
91 | |
92 return this.startpageOffset; | |
93 } | |
94 } |