Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/common/MetaAndTableJRDataSource.java @ 9005:460fcc128794
jasper multiple
author | gernotbelger |
---|---|
date | Tue, 17 Apr 2018 13:19:56 +0200 |
parents | artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/util/MetaAndTableJRDataSource.java@5d5d482da3e9 |
children | e6b63b2b41b9 |
rev | line source |
---|---|
8854 | 1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
2 * Software engineering by |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
3 * Björnsen Beratende Ingenieure GmbH |
8854 | 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 */ | |
9005 | 10 package org.dive4elements.river.artifacts.common; |
8854 | 11 |
12 import java.util.ArrayList; | |
13 import java.util.HashMap; | |
14 import java.util.List; | |
15 import java.util.Map; | |
16 | |
17 import net.sf.jasperreports.engine.JRDataSource; | |
18 import net.sf.jasperreports.engine.JRException; | |
19 import net.sf.jasperreports.engine.JRField; | |
20 | |
21 /** | |
22 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a> | |
23 */ | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
24 public final class MetaAndTableJRDataSource implements JRDataSource { |
8854 | 25 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
26 private final List<String[]> data = new ArrayList<>(); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
27 |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
28 private final Map<String, String> metaData = new HashMap<>(); |
8854 | 29 |
30 private int index = -1; | |
31 | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
32 public void addData(final String[] row) { |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
33 this.data.add(row); |
8854 | 34 } |
35 | |
36 public void addMetaData(final String key, final String value) { | |
37 this.metaData.put(key, value); | |
38 } | |
39 | |
40 @Override | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
41 public boolean next() throws JRException { |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
42 this.index++; |
8854 | 43 |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
44 return this.index < this.data.size(); |
8854 | 45 } |
46 | |
47 @Override | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
48 public Object getFieldValue(final JRField field) throws JRException { |
8854 | 49 final String fieldName = field.getName(); |
50 | |
8946
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
51 if (fieldName.startsWith("meta:")) |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
52 return this.metaData.get(fieldName.substring("meta:".length())); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
53 |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
54 if (fieldName.startsWith("data:")) { |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
55 final int column = Integer.valueOf(fieldName.substring("data:".length())); |
5d5d482da3e9
Implementing SINFO - FlowDepthMinMax calculation
gernotbelger
parents:
8854
diff
changeset
|
56 return this.data.get(this.index)[column]; |
8854 | 57 } |
58 return null; | |
59 } | |
9005 | 60 |
61 public JRDataSource withPagePageOffsets(final int startpageoffset, final int totalpagesoffset) { | |
62 | |
63 final MetaAndTableJRDataSource newSource = new MetaAndTableJRDataSource(); | |
64 newSource.data.addAll(this.data); | |
65 newSource.metaData.putAll(this.metaData); | |
66 | |
67 newSource.addMetaData("meta:startpageoffset", "" + startpageoffset); | |
68 newSource.addMetaData("meta:totalpagesoffset", "" + totalpagesoffset); | |
69 | |
70 return newSource; | |
71 } | |
8854 | 72 } |