Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/states/RadioSelect.java @ 9369:1a4d2ce77423
radio choice fix
author | gernotbelger |
---|---|
date | Thu, 02 Aug 2018 17:39:13 +0200 |
parents | c7e5285d434f |
children |
rev | line source |
---|---|
9053 | 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.states; | |
11 | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
12 import java.util.LinkedHashMap; |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
13 import java.util.Map; |
9053 | 14 |
15 import org.dive4elements.artifacts.Artifact; | |
16 import org.dive4elements.artifacts.CallContext; | |
17 import org.dive4elements.artifacts.CallMeta; | |
18 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
19 import org.dive4elements.river.artifacts.resources.Resources; | |
20 import org.w3c.dom.Element; | |
21 | |
22 /** | |
23 * @author Domenico Nardi Tironi | |
24 * | |
25 */ | |
26 public abstract class RadioSelect extends DefaultState { | |
27 | |
28 private static final long serialVersionUID = 1L; | |
9184 | 29 private Artifact artifact; |
9053 | 30 |
9369 | 31 protected abstract String getDatakey(); |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
32 |
9369 | 33 @Override |
34 protected abstract String getUIProvider(); // force override in subs! | |
35 // { | |
36 // return "radio_panel"; //no generic radiopanel | |
37 // } | |
9053 | 38 |
9184 | 39 protected abstract LinkedHashMap<String, String> makeEntries(CallMeta meta, Artifact artifact); // AUSNAHMSWEISE EXPLIZITER TYP, damit Reihenfolge nicht |
40 // verrutscht | |
9053 | 41 |
42 @Override | |
43 protected Element[] createItems(final XMLUtils.ElementCreator ec, final Artifact artifact, final String name, final CallContext context) { | |
9184 | 44 |
45 // REMEBER: we need it for getLabelFor later | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
46 |
9369 | 47 if (name.equals(getDatakey())) { |
48 this.artifact = artifact; | |
49 | |
50 final CallMeta meta = context.getMeta(); | |
51 final Map<String, String> entries = makeEntries(meta, artifact); | |
52 | |
53 final Element[] elements = new Element[entries.size()]; | |
54 int i = 0; | |
55 for (final String key : entries.keySet()) { | |
56 final String label = entries.get(key); | |
57 final String labelToSet = label != null ? label : Resources.getMsg(meta, key); | |
58 elements[i] = createItem(ec, new String[] { labelToSet, key }); | |
59 i++; | |
60 } | |
61 return elements; | |
9053 | 62 } |
9369 | 63 return super.createItems(ec, artifact, name, context); |
9053 | 64 } |
65 | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
66 @Override |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
67 protected String getLabelFor(final CallContext cc, final String name, final String value, final String type) { |
9184 | 68 // artifacts must be set in "createItems" -> createItems has to be called first |
69 final Map<String, String> entries = makeEntries(cc.getMeta(), this.artifact); | |
9178
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
70 |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
71 final String valueToSet = entries.get(value) != null ? entries.get(value) : value; |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
72 return super.getLabelFor(cc, name, valueToSet, type); |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
73 } |
2f5052835b76
uinfo inundationduration langjähr. Mittel, Uedauern.properties, Meldung
gernotbelger
parents:
9053
diff
changeset
|
74 } |