comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/BooleanChoiceState.java @ 8851:13650d8a2373

Generalized the FloodplainChoice to a reusable BooleanChoiceState
author gernotbelger
date Thu, 18 Jan 2018 18:26:30 +0100
parents
children 2323d005f9a5
comparison
equal deleted inserted replaced
8850:6823991e1ed1 8851:13650d8a2373
1 /* Copyright (C) 2011, 2012, 2017 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 package org.dive4elements.river.artifacts.states;
9
10 import org.w3c.dom.Element;
11
12 import org.apache.log4j.Logger;
13
14 import org.dive4elements.artifacts.Artifact;
15 import org.dive4elements.artifacts.CallContext;
16 import org.dive4elements.artifacts.CallMeta;
17
18 import org.dive4elements.artifacts.common.utils.XMLUtils;
19
20 import org.dive4elements.artifactdatabase.ProtocolUtils;
21
22 import org.dive4elements.river.artifacts.resources.Resources;
23
24 /**
25 * Generic state for a boolean choice. Only difference between real implementations are the human readable labels.
26 *
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
28 * @author Gernot Belger
29 */
30 public abstract class BooleanChoiceState extends DefaultState {
31
32 private String optionMsg;
33 private String activeMsg;
34 private String inactiveMsg;
35
36 public BooleanChoiceState( String optionMsg, String activeMsg, String inactiveMsg ) {
37 this.optionMsg = optionMsg;
38 this.activeMsg = activeMsg;
39 this.inactiveMsg = inactiveMsg;
40 }
41
42 private static final Logger log =
43 Logger.getLogger(BooleanChoiceState.class);
44
45 @Override
46 protected String getUIProvider() {
47 return "boolean_panel";
48 }
49
50 @Override
51 protected Element[] createItems(
52 XMLUtils.ElementCreator cr,
53 Artifact artifact,
54 String name,
55 CallContext context)
56 {
57 CallMeta meta = context.getMeta();
58
59 Element option = createItem(
60 cr,
61 new String[] { Resources.getMsg(meta, optionMsg, optionMsg), "true" });
62
63 return new Element[] { option };
64 }
65
66
67 @Override
68 protected String getLabelFor(
69 CallContext cc,
70 String name,
71 String value,
72 String type
73 ) {
74 log.debug("GET LABEL FOR '" + name + "' / '" + value + "'");
75 if (value != null && value.equals("true")) {
76 return Resources.getMsg(cc.getMeta(), activeMsg, activeMsg);
77 }
78 else {
79 return Resources.getMsg(cc.getMeta(), inactiveMsg, inactiveMsg);
80 }
81 }
82
83
84 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) {
85 Element item = ProtocolUtils.createArtNode(cr, "item", null, null);
86 Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
87 Element value = ProtocolUtils.createArtNode(cr, "value", null, null);
88
89 String[] arr = (String[]) obj;
90
91 label.setTextContent(arr[0]);
92 value.setTextContent(arr[1]);
93
94 item.appendChild(label);
95 item.appendChild(value);
96
97 return item;
98 }
99 }
100 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org