Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/states/BooleanChoiceState.java @ 9638:6c1ebf2220f5
# 19b (check for usages of WaterlevelExporter.getWforGaugeAndQ) -> cleanup: removing calc.extreme.curve
author | dnt_bjoernsen <d.tironi@bjoernsen.de> |
---|---|
date | Thu, 31 Oct 2019 17:37:53 +0100 |
parents | 2323d005f9a5 |
children |
rev | line source |
---|---|
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
1 /* Copyright (C) 2011, 2012, 2017 by Bundesanstalt für Gewässerkunde |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
2 * Software engineering by Intevation GmbH |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
3 * |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
4 * This file is Free Software under the GNU AGPL (>=v3) |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
6 * documentation coming with Dive4Elements River for details. |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
7 */ |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
8 package org.dive4elements.river.artifacts.states; |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
9 |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
10 import org.apache.log4j.Logger; |
9277 | 11 import org.dive4elements.artifactdatabase.ProtocolUtils; |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
12 import org.dive4elements.artifacts.Artifact; |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
13 import org.dive4elements.artifacts.CallContext; |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
14 import org.dive4elements.artifacts.CallMeta; |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
15 import org.dive4elements.artifacts.common.utils.XMLUtils; |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
16 import org.dive4elements.river.artifacts.resources.Resources; |
9277 | 17 import org.w3c.dom.Element; |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
18 |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
19 /** |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
20 * Generic state for a boolean choice. Only difference between real implementations are the human readable labels. |
9277 | 21 * |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
23 * @author Gernot Belger |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
24 */ |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
25 public abstract class BooleanChoiceState extends DefaultState { |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
26 |
9277 | 27 private final String optionMsg; |
28 private final String activeMsg; | |
29 private final String inactiveMsg; | |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
30 |
9277 | 31 public BooleanChoiceState(final String optionMsg, final String activeMsg, final String inactiveMsg) { |
32 this.optionMsg = optionMsg; | |
33 this.activeMsg = activeMsg; | |
34 this.inactiveMsg = inactiveMsg; | |
35 } | |
36 | |
37 private static final Logger log = Logger.getLogger(BooleanChoiceState.class); | |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
38 |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
39 @Override |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
40 protected String getUIProvider() { |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
41 return "boolean_panel"; |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
42 } |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
43 |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
44 @Override |
9277 | 45 protected Element[] createItems(final XMLUtils.ElementCreator cr, final Artifact artifact, final String name, final CallContext context) { |
46 final CallMeta meta = context.getMeta(); | |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
47 |
9277 | 48 final Element option = createItem(cr, new String[] { Resources.getMsg(meta, this.optionMsg, this.optionMsg), "true" }); |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
49 |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
50 return new Element[] { option }; |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
51 } |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
52 |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
53 @Override |
9277 | 54 protected String getLabelFor(final CallContext cc, final String name, final String value, final String type) { |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
55 log.debug("GET LABEL FOR '" + name + "' / '" + value + "'"); |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
56 if (value != null && value.equals("true")) { |
9277 | 57 return Resources.getMsg(cc.getMeta(), this.activeMsg, this.activeMsg); |
58 } else { | |
59 return Resources.getMsg(cc.getMeta(), this.inactiveMsg, this.inactiveMsg); | |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
60 } |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
61 } |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
62 |
9277 | 63 protected static Element createItem(final XMLUtils.ElementCreator cr, final Object obj) { |
64 final Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
65 final Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
66 final Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
67 |
9277 | 68 final String[] arr = (String[]) obj; |
8851
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
69 |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
70 label.setTextContent(arr[0]); |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
71 value.setTextContent(arr[1]); |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
72 |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
73 item.appendChild(label); |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
74 item.appendChild(value); |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
75 |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
76 return item; |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
77 } |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
78 } |
13650d8a2373
Generalized the FloodplainChoice to a reusable BooleanChoiceState
gernotbelger
parents:
diff
changeset
|
79 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |