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