annotate artifacts/src/main/java/org/dive4elements/river/artifacts/states/DefaultState.java @ 9277:2323d005f9a5

compile error fix
author gernotbelger
date Fri, 20 Jul 2018 10:39:02 +0200
parents 7d1a32a543cb
children
rev   line source
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
1 /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
2 * Software engineering by Intevation GmbH
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
3 *
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5909
diff changeset
4 * This file is Free Software under the GNU AGPL (>=v3)
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the
5994
af13ceeba52a Removed trailing whitespace.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5909
diff changeset
6 * documentation coming with Dive4Elements River for details.
5863
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
7 */
4897a58c8746 River artifacts: Added new copyright headers.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5838
diff changeset
8
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4155
diff changeset
9 package org.dive4elements.river.artifacts.states;
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
10
669
23fced04ffdb #103 PART 1: The numbers which are written into the static DESCRIBE part are i18n formatted now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 660
diff changeset
11 import java.text.NumberFormat;
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
12 import java.util.List;
669
23fced04ffdb #103 PART 1: The numbers which are written into the static DESCRIBE part are i18n formatted now.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 660
diff changeset
13 import java.util.Locale;
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
14 import java.util.Map;
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
15
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
17 import org.dive4elements.artifactdatabase.ProtocolUtils;
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
18 import org.dive4elements.artifactdatabase.data.StateData;
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
19 import org.dive4elements.artifactdatabase.state.AbstractState;
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
20 import org.dive4elements.artifactdatabase.state.Facet;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4155
diff changeset
21 import org.dive4elements.artifacts.Artifact;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4155
diff changeset
22 import org.dive4elements.artifacts.ArtifactNamespaceContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4155
diff changeset
23 import org.dive4elements.artifacts.CallContext;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4155
diff changeset
24 import org.dive4elements.artifacts.CallMeta;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4155
diff changeset
25 import org.dive4elements.artifacts.common.utils.XMLUtils;
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4155
diff changeset
26 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
5867
59ff03ff48f1 River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5863
diff changeset
27 import org.dive4elements.river.artifacts.D4EArtifact;
5831
bd047b71ab37 Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents: 4155
diff changeset
28 import org.dive4elements.river.artifacts.resources.Resources;
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
29 import org.w3c.dom.Document;
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
30 import org.w3c.dom.Element;
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
31 import org.w3c.dom.Node;
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
32
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
33 /**
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
34 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
35 */
8275
97e148487186 The default state is no more abstract.
Raimund Renkert <rrenkert@intevation.de>
parents: 8202
diff changeset
36 public class DefaultState extends AbstractState {
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
37
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6052
diff changeset
38 /** The log that is used in this class. */
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6052
diff changeset
39 private static Logger log = Logger.getLogger(DefaultState.class);
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
40
1768
41ba2276d785 Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1743
diff changeset
41 /** The three possible compute types. */
697
b972eba2ed8a Removed ComputeCallback because this was thought too complicated. Fixed issue with facets not be re-generated if same state is entered again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 687
diff changeset
42 public static enum ComputeType {
942
796c54058dc4 Added artifacts/states for WMS background an river axis and a configuration for the output-defaults.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 941
diff changeset
43 FEED, ADVANCE, INIT
697
b972eba2ed8a Removed ComputeCallback because this was thought too complicated. Fixed issue with facets not be re-generated if same state is entered again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 687
diff changeset
44 }
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
45
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
46 protected StateData getData(final D4EArtifact artifact, final String name) {
624
929137ee8154 ISSUE-62 (part I/II) States are no longer filled with data - if a state needs user input, it needs to query the owner artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 379
diff changeset
47 return artifact.getData(name);
929137ee8154 ISSUE-62 (part I/II) States are no longer filled with data - if a state needs user input, it needs to query the owner artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 379
diff changeset
48 }
929137ee8154 ISSUE-62 (part I/II) States are no longer filled with data - if a state needs user input, it needs to query the owner artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 379
diff changeset
49
1136
8da5f5a9ed3c Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
50 /**
8da5f5a9ed3c Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
51 * Append to a node and return xml description relevant for gui.
8da5f5a9ed3c Cosmetics, docs.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1050
diff changeset
52 */
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
53 public Element describeStatic(final Artifact artifact, final Document document, final Node root, final CallContext context, final String uuid) {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
54 final ElementCreator creator = new ElementCreator(document, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX);
134
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
55
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
56 final CallMeta meta = context.getMeta();
142
b43671a551d1 Append human readable strings of the selected values to the DESCRIBE output.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 136
diff changeset
57
5909
6dfd967dcae9 D4E river: Fixed substitution on help URL.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
58 String helpText = getHelpText();
6dfd967dcae9 D4E river: Fixed substitution on help URL.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
59 if (helpText != null) {
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
60 helpText = replaceHelpUrl(Resources.getMsg(meta, helpText, helpText));
5909
6dfd967dcae9 D4E river: Fixed substitution on help URL.
Sascha L. Teichmann <teichmann@intevation.de>
parents: 5867
diff changeset
61 }
2661
17927c60ac1c Added 'helpText' fields to the transition model.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2214
diff changeset
62
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
63 final String label = Resources.getMsg(meta, getID(), getID());
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
64 final Element ui = ProtocolUtils.createArtNode(creator, "state", new String[] { "name", "uiprovider", "label", "helpText" },
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
65 new String[] { getID(), getUIProvider(), label, helpText });
134
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
66
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
67 final Map<String, StateData> theData = getData();
134
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
68 if (theData == null) {
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
69 return ui;
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
70 }
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
71
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
72 final D4EArtifact flys = (D4EArtifact) artifact;
134
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
73
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
74 for (final String name : theData.keySet()) {
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
75 appendStaticData(flys, context, creator, ui, name);
134
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
76 }
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
77
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
78 return ui;
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
79 }
f3dfa188d8b2 Let the states describe the static ui part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 129
diff changeset
80
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
81 protected void appendStaticData(final D4EArtifact flys, final CallContext context, final ElementCreator cr, final Element ui, final String name) {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
82 final StateData data = getData(flys, name);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
83 final String value = (data != null) ? (String) data.getValue() : null;
1159
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
84
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
85 if (value == null) {
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
86 return;
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
87 }
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
88
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
89 final String type = data.getType();
1159
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
90
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6052
diff changeset
91 if (log.isDebugEnabled()) {
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
92 log.debug("Append element " + type + "'" + name + "' (" + value + ")");
3732
fe29b0226faf More iterator code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3414
diff changeset
93 }
2205
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
94
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
95 final Element e = createStaticData(flys, cr, context, name, value, type);
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
96
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
97 ui.appendChild(e);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
98
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
99 }
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
100
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
101 /**
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
102 * Creates a <i>data</i> element used in the static part of the DESCRIBE
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
103 * document.
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
104 *
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
105 * @param creator
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
106 * The ElementCreator that is used to build new Elements.
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
107 * @param cc
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
108 * The CallContext object used for nested i18n retrieval.
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
109 * @param name
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
110 * The name of the data item.
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
111 * @param value
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
112 * The value as string.
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
113 *
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
114 * @return an Element.
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
115 */
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
116 protected Element createStaticData(final D4EArtifact flys, final ElementCreator creator, final CallContext cc, final String name, final String value,
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
117 final String type) {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
118 final Element dataElement = creator.create("data");
1159
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
119 creator.addAttr(dataElement, "name", name, true);
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
120 creator.addAttr(dataElement, "type", type, true);
1159
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
121
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
122 final Element itemElement = creator.create("item");
1159
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
123 creator.addAttr(itemElement, "value", value, true);
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
124
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
125 creator.addAttr(itemElement, "label", getLabelFor(cc, name, value, type), true);
2205
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
126
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
127 dataElement.appendChild(itemElement);
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
128
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
129 return dataElement;
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
130 }
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
131
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
132 /**
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
133 * @param cc
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
134 * @param name
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
135 * @param value
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
136 * @param type
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
137 *
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
138 * @return
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
139 */
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
140 protected String getLabelFor(final CallContext cc, final String name, final String value, final String type) {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
141 final CallMeta meta = cc.getMeta();
2205
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
142
1159
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
143 try {
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
144 // XXX A better way to format the output would be to use the
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
145 // 'type' value of the data objects.
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
146 final double doubleVal = Double.parseDouble(value);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
147 final Locale l = Resources.getLocale(meta);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
148 final NumberFormat nf = NumberFormat.getInstance(l);
1159
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
149
2205
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
150 return nf.format(doubleVal);
1159
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
151 }
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
152 catch (final NumberFormatException nfe) {
2205
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
153 return Resources.getMsg(meta, value, value);
1159
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
154 }
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
155 }
fb5a7ff9feb8 Suppress the GeoJSON string for the FloodMap creation to be included in the static DESCRIBE part.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1136
diff changeset
156
3407
70e9d56e21fc Set default value of MINFO SQ relation's outliers parameter to 3.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3284
diff changeset
157 /**
8615
054d1b57ae4a (issue1755) Clarify how default mecahnism works and remove unused config value.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8275
diff changeset
158 * This method returns the default value and label for <i>data</i>.
054d1b57ae4a (issue1755) Clarify how default mecahnism works and remove unused config value.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8275
diff changeset
159 *
054d1b57ae4a (issue1755) Clarify how default mecahnism works and remove unused config value.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8275
diff changeset
160 * Override this method in a subclass to set an appropiate default
054d1b57ae4a (issue1755) Clarify how default mecahnism works and remove unused config value.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8275
diff changeset
161 * value.
054d1b57ae4a (issue1755) Clarify how default mecahnism works and remove unused config value.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8275
diff changeset
162 * The default label can be ignored by the client (e.g. the gwt-client).
054d1b57ae4a (issue1755) Clarify how default mecahnism works and remove unused config value.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8275
diff changeset
163 * but shall not be null.
054d1b57ae4a (issue1755) Clarify how default mecahnism works and remove unused config value.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8275
diff changeset
164 *
054d1b57ae4a (issue1755) Clarify how default mecahnism works and remove unused config value.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8275
diff changeset
165 * Example implementation:
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
166 * if (data != null && data.getName().equals("the_answer")) {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
167 * return new String[] {"42", "the_answer"};
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
168 * }
8615
054d1b57ae4a (issue1755) Clarify how default mecahnism works and remove unused config value.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8275
diff changeset
169 *
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
170 * @param context
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
171 * The CallContext used for i18n.
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
172 * @param data
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
173 * The data objects that the defaults are for.
3407
70e9d56e21fc Set default value of MINFO SQ relation's outliers parameter to 3.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3284
diff changeset
174 * @return a String[] with [default value, default label].
70e9d56e21fc Set default value of MINFO SQ relation's outliers parameter to 3.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3284
diff changeset
175 */
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
176 protected String[] getDefaultsFor(final CallContext context, final StateData data) {
3407
70e9d56e21fc Set default value of MINFO SQ relation's outliers parameter to 3.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3284
diff changeset
177 return null;
70e9d56e21fc Set default value of MINFO SQ relation's outliers parameter to 3.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3284
diff changeset
178 }
70e9d56e21fc Set default value of MINFO SQ relation's outliers parameter to 3.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3284
diff changeset
179
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
180 @Override
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
181 public Element describe(final Artifact artifact, final Document document, final Node root, final CallContext context, final String uuid) {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
182 final ElementCreator creator = new ElementCreator(document, ArtifactNamespaceContext.NAMESPACE_URI, ArtifactNamespaceContext.NAMESPACE_PREFIX);
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
183
6052
799af7909e8d Expand the Help Url also in the describe method
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
184 String helpText = getHelpText();
799af7909e8d Expand the Help Url also in the describe method
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
185 if (helpText != null) {
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
186 helpText = replaceHelpUrl(Resources.getMsg(context.getMeta(), helpText, helpText));
6052
799af7909e8d Expand the Help Url also in the describe method
Andre Heinecke <aheinecke@intevation.de>
parents: 5994
diff changeset
187 }
2661
17927c60ac1c Added 'helpText' fields to the transition model.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2214
diff changeset
188
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
189 Element ui = null;
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
190 final String uiprovider = getUIProvider();
135
2d6e02787d00 Added a method to retrieve the UIProvider for a state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 134
diff changeset
191 if (uiprovider != null) {
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
192 ui = ProtocolUtils.createArtNode(creator, "dynamic", new String[] { "uiprovider", "helpText" }, new String[] { uiprovider, helpText });
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
193 } else {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
194 ui = ProtocolUtils.createArtNode(creator, "dynamic", new String[] { "helpText" }, new String[] { helpText });
135
2d6e02787d00 Added a method to retrieve the UIProvider for a state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 134
diff changeset
195 }
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
196
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
197 final Map<String, StateData> theData = getData();
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
198 if (theData == null) {
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
199 return ui;
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
200 }
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
201
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
202 final D4EArtifact flys = (D4EArtifact) artifact;
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
203
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
204 for (final String name : theData.keySet()) {
624
929137ee8154 ISSUE-62 (part I/II) States are no longer filled with data - if a state needs user input, it needs to query the owner artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 379
diff changeset
205 StateData data = getData(flys, name);
929137ee8154 ISSUE-62 (part I/II) States are no longer filled with data - if a state needs user input, it needs to query the owner artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 379
diff changeset
206
3732
fe29b0226faf More iterator code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3414
diff changeset
207 if (data == null) {
fe29b0226faf More iterator code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3414
diff changeset
208 data = getData(name);
fe29b0226faf More iterator code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3414
diff changeset
209 }
624
929137ee8154 ISSUE-62 (part I/II) States are no longer filled with data - if a state needs user input, it needs to query the owner artifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 379
diff changeset
210
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
211 final Element select = createData(creator, artifact, data, context);
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
212
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
213 final String[] defaults = getDefaultsFor(context, data);
3407
70e9d56e21fc Set default value of MINFO SQ relation's outliers parameter to 3.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3284
diff changeset
214 if (defaults != null && defaults.length > 1) {
70e9d56e21fc Set default value of MINFO SQ relation's outliers parameter to 3.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3284
diff changeset
215 creator.addAttr(select, "defaultValue", defaults[0], true);
70e9d56e21fc Set default value of MINFO SQ relation's outliers parameter to 3.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 3284
diff changeset
216 creator.addAttr(select, "defaultLabel", defaults[1], true);
630
40d3039f85ac ISSUE-40 (part I/II) Write values that the user had former selected / inserted into DESCRIBE document to preselect such data in the UI.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
217 }
40d3039f85ac ISSUE-40 (part I/II) Write values that the user had former selected / inserted into DESCRIBE document to preselect such data in the UI.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 624
diff changeset
218
2189
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
219 appendItems(artifact, creator, name, context, select);
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
220 ui.appendChild(select);
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
221 }
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
222
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
223 return ui;
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
224 }
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
225
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
226 /**
2189
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
227 * @param artifact
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
228 * @param creator
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
229 * @param name
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
230 * @param context
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
231 * @param select
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
232 */
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
233 protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
234 final Element choices = ProtocolUtils.createArtNode(creator, "choices", null, null);
2189
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
235
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
236 select.appendChild(choices);
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
237
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
238 final Element[] items = createItems(creator, artifact, name, context);
2189
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
239 if (items != null) {
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
240 for (final Element item : items) {
2189
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
241 choices.appendChild(item);
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
242 }
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
243 }
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
244 }
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
245
19518116a49a Refactored some code in DefaultState to better override the base class.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2015
diff changeset
246 /**
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
247 * This method creates the root node that contains the list of selectable
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
248 * items.
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
249 *
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
250 * @param cr
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
251 * The ElementCreator.
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
252 *
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
253 * @return the root node of the item list.
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
254 */
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
255 protected Element createData(final ElementCreator cr, final Artifact artifact, final StateData data, final CallContext context) {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
256 final Element select = ProtocolUtils.createArtNode(cr, "select", null, null);
129
b06cd117b565 Appended a missing node to the DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 128
diff changeset
257 cr.addAttr(select, "name", data.getName(), true);
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
258
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
259 final Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
260
129
b06cd117b565 Appended a missing node to the DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 128
diff changeset
261 select.appendChild(label);
b06cd117b565 Appended a missing node to the DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 128
diff changeset
262
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
263 label.setTextContent(Resources.getMsg(context.getMeta(), getID(), getID()));
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
264
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
265 return select;
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
266 }
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
267
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
268 /**
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
269 * This method creates a list of items. These items represent the amount of
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
270 * input data that is possible for this state.
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
271 *
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
272 * @param cr
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
273 * The ElementCreator.
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
274 * @param name
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
275 * The name of the amount of data.
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
276 *
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
277 * @return a list of items.
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
278 */
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
279 protected Element[] createItems(final ElementCreator cr, final Artifact artifact, final String name, final CallContext context) {
660
627be3ca1ab6 code clean up in states
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 635
diff changeset
280 return null;
627be3ca1ab6 code clean up in states
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 635
diff changeset
281 }
135
2d6e02787d00 Added a method to retrieve the UIProvider for a state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 134
diff changeset
282
322
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 313
diff changeset
283 /**
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
284 * This method is used to create an <i>item</i> Element that contains two
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
285 * further elements <i>label</i> and <i>value</i>. The label and value
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
286 * elements both have text nodes.
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
287 *
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
288 * @param cr
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
289 * The ElementCreator used to build new Elements.
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
290 * @param obj
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
291 * This implementation awaits a String array with [0] = label and
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
292 * [1] = value.
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
293 *
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
294 * @return an Element.
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
295 */
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
296 protected static Element createItem(final XMLUtils.ElementCreator cr, final Object obj) {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
297 final Element item = ProtocolUtils.createArtNode(cr, "item", null, null);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
298 final Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
299 final Element value = ProtocolUtils.createArtNode(cr, "value", null, null);
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
300
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
301 final String[] arr = (String[]) obj;
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
302
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
303 label.setTextContent(arr[0]);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
304 value.setTextContent(arr[1]);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
305
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
306 item.appendChild(label);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
307 item.appendChild(value);
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
308
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
309 return item;
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
310 }
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
311
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
312 // protected static Element createItem(final XMLUtils.ElementCreator cr, final Object obj) {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
313 // final Element item = ProtocolUtils.createArtNode(cr, "item", null, null);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
314 // final Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
315 // final Element value = ProtocolUtils.createArtNode(cr, "value", null, null);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
316 //
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
317 // final String[] arr = (String[]) obj;
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
318 //
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
319 // label.setTextContent(arr[0]);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
320 // value.setTextContent(arr[1]);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
321 //
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
322 // item.appendChild(label);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
323 // item.appendChild(value);
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
324 //
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
325 // return item;
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
326 // }
1180
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
327
1aba1a75beb2 Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1176
diff changeset
328 /**
1176
28154920e0b3 Introduced the possibility for States to transform/modify input before the data is added to FLYSArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1159
diff changeset
329 * This method transform a given value into a StateData object.
28154920e0b3 Introduced the possibility for States to transform/modify input before the data is added to FLYSArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1159
diff changeset
330 *
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
331 * @param flys
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
332 * The D4EArtifact.
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
333 * @param name
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
334 * The name of the data object.
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
335 * @param val
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
336 * The value of the data object.
1176
28154920e0b3 Introduced the possibility for States to transform/modify input before the data is added to FLYSArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1159
diff changeset
337 *
28154920e0b3 Introduced the possibility for States to transform/modify input before the data is added to FLYSArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1159
diff changeset
338 * @return a StateData object with <i>name</i> and <i>val</i>ue.
28154920e0b3 Introduced the possibility for States to transform/modify input before the data is added to FLYSArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1159
diff changeset
339 */
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
340 public StateData transform(final D4EArtifact flys, final CallContext cc, final StateData stateData, final String name, final String val) {
8202
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6052
diff changeset
341 if (log.isDebugEnabled()) {
e4606eae8ea5 sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents: 6052
diff changeset
342 log.debug("Transform data ('" + name + "','" + val + "')");
3732
fe29b0226faf More iterator code simplification.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 3414
diff changeset
343 }
2205
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
344
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
345 stateData.setValue(val);
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
346
a22e0cb6eace Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 2189
diff changeset
347 return stateData;
1176
28154920e0b3 Introduced the possibility for States to transform/modify input before the data is added to FLYSArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1159
diff changeset
348 }
28154920e0b3 Introduced the possibility for States to transform/modify input before the data is added to FLYSArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1159
diff changeset
349
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
350 /**
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
351 * Override this to do validation.
8636
7d1a32a543cb (issue1755) Extend validation to allow localized error messages.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8615
diff changeset
352 *
7d1a32a543cb (issue1755) Extend validation to allow localized error messages.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8615
diff changeset
353 * Throw an IllegalArgumentException with a localized
7d1a32a543cb (issue1755) Extend validation to allow localized error messages.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8615
diff changeset
354 * error message that should be presented to the user in case
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
355 * the date provided is invalid.
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
356 */
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
357 public void validate(final Artifact artifact, final CallContext context) throws IllegalArgumentException {
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
358 validate(artifact); /*
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
359 * For compatibility so that classes that
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
360 * override this method still work.
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
361 */
8636
7d1a32a543cb (issue1755) Extend validation to allow localized error messages.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8615
diff changeset
362 }
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
363
1176
28154920e0b3 Introduced the possibility for States to transform/modify input before the data is added to FLYSArtifact.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 1159
diff changeset
364 /**
8636
7d1a32a543cb (issue1755) Extend validation to allow localized error messages.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8615
diff changeset
365 * This method is deprecated.
7d1a32a543cb (issue1755) Extend validation to allow localized error messages.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8615
diff changeset
366 * Override the function with the callcontext instead to do
7d1a32a543cb (issue1755) Extend validation to allow localized error messages.
Andre Heinecke <andre.heinecke@intevation.de>
parents: 8615
diff changeset
367 * localization of error.s
322
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 313
diff changeset
368 */
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
369 public boolean validate(final Artifact artifact) throws IllegalArgumentException {
322
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 313
diff changeset
370 return true;
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 313
diff changeset
371 }
448d0dc64357 The inserted ranges (distance and WQ ranges) are validated in the feed() operation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 313
diff changeset
372
1691
17648043429f Cosmetics, docs, annotations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1180
diff changeset
373 /**
17648043429f Cosmetics, docs, annotations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1180
diff changeset
374 * Returns which UIProvider shall be used to aid user input.
17648043429f Cosmetics, docs, annotations.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 1180
diff changeset
375 */
135
2d6e02787d00 Added a method to retrieve the UIProvider for a state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 134
diff changeset
376 protected String getUIProvider() {
2d6e02787d00 Added a method to retrieve the UIProvider for a state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 134
diff changeset
377 return null;
2d6e02787d00 Added a method to retrieve the UIProvider for a state.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 134
diff changeset
378 }
687
06689035024c Added a compute() method to WINFOArtifact which acts as a dispatcher for different computations. It triggers a calculation based on ComputeCallbacks that are generated by the current states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 669
diff changeset
379
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
380 public Object computeAdvance(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) {
697
b972eba2ed8a Removed ComputeCallback because this was thought too complicated. Fixed issue with facets not be re-generated if same state is entered again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 687
diff changeset
381 return null;
b972eba2ed8a Removed ComputeCallback because this was thought too complicated. Fixed issue with facets not be re-generated if same state is entered again.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 687
diff changeset
382 }
687
06689035024c Added a compute() method to WINFOArtifact which acts as a dispatcher for different computations. It triggers a calculation based on ComputeCallbacks that are generated by the current states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 669
diff changeset
383
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
384 public Object computeFeed(final D4EArtifact artifact, final String hash, final CallContext context, final List<Facet> facets, final Object old) {
687
06689035024c Added a compute() method to WINFOArtifact which acts as a dispatcher for different computations. It triggers a calculation based on ComputeCallbacks that are generated by the current states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 669
diff changeset
385 return null;
06689035024c Added a compute() method to WINFOArtifact which acts as a dispatcher for different computations. It triggers a calculation based on ComputeCallbacks that are generated by the current states.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 669
diff changeset
386 }
941
1b509e4cf99b Added a computeInit() method to intialize data/facets after creating new artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 742
diff changeset
387
9277
2323d005f9a5 compile error fix
gernotbelger
parents: 8636
diff changeset
388 public Object computeInit(final D4EArtifact artifact, final String hash, final Object context, final CallMeta meta, final List<Facet> facets) {
941
1b509e4cf99b Added a computeInit() method to intialize data/facets after creating new artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 742
diff changeset
389 return null;
1b509e4cf99b Added a computeInit() method to intialize data/facets after creating new artifacts.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents: 742
diff changeset
390 }
126
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
391 }
b18aebd1342f Added an abstract base class DefaultState for States.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff changeset
392 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org