9223
|
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by Intevation GmbH |
|
3 * |
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
6 * documentation coming with Dive4Elements River for details. |
|
7 */ |
|
8 |
|
9 package org.dive4elements.river.artifacts.uinfo.salix; |
|
10 |
|
11 import java.util.HashMap; |
9245
|
12 import java.util.Iterator; |
|
13 import java.util.List; |
9223
|
14 import java.util.Map; |
9245
|
15 import java.util.TreeMap; |
9223
|
16 |
|
17 import org.apache.log4j.Logger; |
|
18 import org.dive4elements.artifacts.Artifact; |
|
19 import org.dive4elements.artifacts.CallContext; |
|
20 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; |
|
21 import org.dive4elements.river.artifacts.states.AddTableDataHelper; |
|
22 import org.dive4elements.river.artifacts.states.DefaultState; |
9245
|
23 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; |
|
24 import org.dive4elements.river.model.BedHeight; |
9223
|
25 import org.w3c.dom.Element; |
|
26 |
9224
|
27 public class LoadSingleEpochSelectState extends DefaultState { |
|
28 private static final long serialVersionUID = 1L; |
9223
|
29 /** The log used in this class. */ |
9224
|
30 private static Logger log = Logger.getLogger(LoadSingleEpochSelectState.class); |
9223
|
31 |
|
32 /** |
|
33 * The default constructor that initializes an empty State object. |
|
34 */ |
9224
|
35 public LoadSingleEpochSelectState() { |
9223
|
36 } |
|
37 |
|
38 @Override |
|
39 protected String getUIProvider() { |
9248
|
40 return "uinfo.salix.load_single_year_pseudo_epoch_select"; |
9223
|
41 } |
|
42 |
|
43 @Override |
|
44 protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) { |
9224
|
45 final String datakey = "singleepoch"; |
9245
|
46 |
9223
|
47 try { |
|
48 if (datakey.equals(name)) { |
9245
|
49 final SalixLineAccess access = new SalixLineAccess((UINFOArtifact) artifact); |
|
50 final List<BedHeight> bhs = BedHeight.getBedHeightEpochs(access.getRiver(), access.getLowerKm(), access.getUpperKm()); |
|
51 makeDataSourceYearEpoch(artifact, creator, select, context, bhs); |
9223
|
52 } |
|
53 } |
|
54 catch ( |
|
55 |
|
56 final IllegalArgumentException iae) { |
|
57 iae.printStackTrace(); |
|
58 } |
|
59 } |
9245
|
60 |
|
61 public static final void makeDataSourceYearEpoch(final Artifact artifact, final ElementCreator creator, final Element select, final CallContext context, |
|
62 final List<BedHeight> bedheights) { // TODO: maybe move to appropriate helper... |
|
63 |
|
64 final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); |
|
65 |
|
66 helper.addColumn(0, "pinfrom", "40", "common.client.ui.from", "ICON", "CENTER", "from"); |
|
67 helper.addColumn(1, "year", "60", "year", "INTEGER", "LEFT", null); |
|
68 helper.addColumn(2, "sounding", "500", "uinfo.salix.soundings", "STRING", "LEFT", null); |
|
69 |
|
70 final TreeMap<Integer, String> bedHeightSorted = new TreeMap<>(); |
|
71 |
|
72 for (final BedHeight bh : bedheights) { |
|
73 final int year = bh.getYear(); |
|
74 final String soundings = bedHeightSorted.containsKey(year) ? bedHeightSorted.get(year) + ", " : ""; |
|
75 bedHeightSorted.put(year, soundings + bh.getDescription()); |
|
76 } |
|
77 final Iterator<Integer> iterator = bedHeightSorted.keySet().iterator(); |
|
78 while (iterator.hasNext()) { |
|
79 final int year = iterator.next(); |
|
80 final String soundings = bedHeightSorted.get(year); |
|
81 final Map<String, String> row = new HashMap<>(); |
|
82 row.put("year", String.valueOf(year)); |
|
83 row.put("sounding", soundings); |
|
84 helper.addRow(row); |
|
85 } |
|
86 |
|
87 helper.submitMapToXml(); |
|
88 } |
|
89 |
9223
|
90 } |