Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/AbstractYearEpochUrlState.java @ 9481:787fc085459b
TSV introduced; uinfo.inundationWMS-Config
author | gernotbelger |
---|---|
date | Wed, 12 Sep 2018 10:55:09 +0200 |
parents | artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/inundationduration/LoadSingleYearSelectState.java@dace17e26d33 |
children | 6dd539efebb1 |
comparison
equal
deleted
inserted
replaced
9480:7228bd10a8cc | 9481:787fc085459b |
---|---|
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.inundationduration; | |
10 | |
11 import java.io.IOException; | |
12 import java.util.Collection; | |
13 import java.util.HashMap; | |
14 import java.util.Map; | |
15 | |
16 import org.dive4elements.artifactdatabase.data.StateData; | |
17 import org.dive4elements.artifacts.Artifact; | |
18 import org.dive4elements.artifacts.CallContext; | |
19 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
20 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
21 import org.dive4elements.river.artifacts.sinfo.tkhstate.TsvHelper.TsvReaderException; | |
22 import org.dive4elements.river.artifacts.states.AddTableDataHelper; | |
23 import org.dive4elements.river.artifacts.states.DefaultState; | |
24 import org.dive4elements.river.artifacts.uinfo.UINFOArtifact; | |
25 import org.dive4elements.river.artifacts.uinfo.inundationduration.UedauernConfiguration.YearType; | |
26 import org.dive4elements.river.artifacts.uinfo.salix.ScenarioTypeState; | |
27 import org.w3c.dom.Element; | |
28 | |
29 /** State in which to fetch years for sedminent load calculation. */ | |
30 public abstract class AbstractYearEpochUrlState extends DefaultState { | |
31 private static final long serialVersionUID = 1L; | |
32 private final YearType type; | |
33 | |
34 /** | |
35 * The default constructor that initializes an empty State object. | |
36 * | |
37 * @param jahre | |
38 */ | |
39 public AbstractYearEpochUrlState(final YearType type) { | |
40 this.type = type; | |
41 } | |
42 | |
43 @Override | |
44 protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) { | |
45 final String dataKey = "year_epoch_select"; | |
46 try { | |
47 if (dataKey.equals(name)) { | |
48 | |
49 final InundationDurationAccess access = new InundationDurationAccess((UINFOArtifact) artifact); | |
50 final UedauernConfiguration properties = UedauernConfiguration.getInstance(access.getRiverName(), this.type); | |
51 final Collection<String> items = properties.getLabels(); | |
52 | |
53 final String columnType = "STRING"; | |
54 final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "select_key", context.getMeta()); // pinKeycolum; nicht zu | |
55 | |
56 helper.addColumn(0, "pinfrom", "60", "common.client.ui.selection", "ICON", "CENTER", "from"); | |
57 helper.addColumn(1, "select_key", "240", yearOrEpoch(), columnType, "LEFT", null); | |
58 | |
59 for (final String year : items) { | |
60 final Map<String, String> row = new HashMap<>(); | |
61 row.put("select_key", year); | |
62 helper.addRow(row); | |
63 | |
64 } | |
65 helper.submitMapToXml(); | |
66 } | |
67 } | |
68 catch (final IllegalArgumentException iae) { | |
69 iae.printStackTrace(); | |
70 } | |
71 catch (final IOException e) { | |
72 e.printStackTrace(); | |
73 } | |
74 catch (final TsvReaderException e) { | |
75 e.printStackTrace(); | |
76 } | |
77 } | |
78 | |
79 private String yearOrEpoch() { | |
80 switch (this.type) { | |
81 case jahre: | |
82 return "year"; | |
83 | |
84 case mittel: | |
85 return "state.uinfo.epoch"; | |
86 | |
87 default: | |
88 throw new IllegalStateException(); | |
89 } | |
90 } | |
91 | |
92 @Override | |
93 protected Element createData(final XMLUtils.ElementCreator cr, final Artifact artifact, final StateData data, final CallContext context) { | |
94 return ScenarioTypeState.changeHeaderForCurrentState(yearOrEpoch(), data.getName(), cr, context); | |
95 } | |
96 } |