Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/states/ComputationRangeState.java @ 9580:839b2aa84dd0
minuend/subtrahend-UI-switch
author | gernotbelger |
---|---|
date | Tue, 08 Jan 2019 17:01:09 +0100 |
parents | baef46792354 |
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:
5867
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:
5867
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:
4865
diff
changeset
|
9 package org.dive4elements.river.artifacts.states; |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.apache.log4j.Logger; |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
12 import org.dive4elements.artifactdatabase.ProtocolUtils; |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
13 import org.dive4elements.artifactdatabase.data.StateData; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
14 import org.dive4elements.artifacts.Artifact; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
15 import org.dive4elements.artifacts.CallContext; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
16 import org.dive4elements.artifacts.common.utils.XMLUtils; |
5867
59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5865
diff
changeset
|
17 import org.dive4elements.river.artifacts.D4EArtifact; |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
18 import org.dive4elements.river.artifacts.access.RiverAccess; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
19 import org.dive4elements.river.artifacts.model.FacetTypes; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4865
diff
changeset
|
20 import org.dive4elements.river.artifacts.resources.Resources; |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
21 import org.w3c.dom.Element; |
2235
ee5310134463
Cosmetics/care/refac.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
2132
diff
changeset
|
22 |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 /** |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 */ |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
26 public class ComputationRangeState extends RangeState implements FacetTypes { |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
27 private static Logger log = Logger.getLogger(ComputationRangeState.class); |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 |
1685
022f62c75878
Cosmetics.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
921
diff
changeset
|
29 /** The default step width. */ |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 public static final int DEFAULT_STEP = 100; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 public ComputationRangeState() { |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 @Override |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
36 protected Element createData(final XMLUtils.ElementCreator cr, final Artifact artifact, final StateData data, final CallContext context) { |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
37 final Element select = ProtocolUtils.createArtNode(cr, "select", null, null); |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 cr.addAttr(select, "name", data.getName(), true); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
41 final Element label = ProtocolUtils.createArtNode(cr, "label", null, null); |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 |
9175
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
43 final String msg = getTitle(context); |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
44 |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
45 label.setTextContent(msg); |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
46 // VORHER: data.getName(), data.getName())) (entsprach "ld_from", "ld_to" - unterschied zu jetzt: description wird |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
47 // anders gesetzt ("Wahl der Berechnungsstrecke") |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
48 // label bleibt "ld_from", "ld_to"; unklar, wo das gesetzt wird. unklar, warum das Element "label" die Description |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
49 // beeinflusst (und scheinbar nicht das Label) |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
51 final Element description = ProtocolUtils.createArtNode(cr, "description", null, null); |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
52 description.setTextContent("TEST"); |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
53 select.appendChild(description); |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 select.appendChild(label); |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 return select; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 |
9175
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
59 // REMARK: allows to overwrite the titel which is shown on the client side. |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
60 // TODO: instead of a fixed string, we should translate the 'id', but in that case we need to change all old workflows |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
61 // (reason is, that we have different texts for the title and the 'old' title, which in turn is the translation of |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
62 // 'description'). |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
63 |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
64 protected String getTitle(final CallContext context) { |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
65 // REMARK: that is how it should be: return Resources.getMsg(context.getMeta(), getID()); |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
66 return Resources.getMsg(context.getMeta(), "state.title.distance_state"); |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
67 } |
34dc0163ad2d
DistancePanel Berechnungsstrecke->Darstellungsbereich Refactoring
gernotbelger
parents:
9164
diff
changeset
|
68 |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
69 @Override |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
70 protected Element[] createItems(final XMLUtils.ElementCreator cr, final Artifact artifact, final String name, final CallContext context) { |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
71 final double[] minmax = getMinMax(artifact); |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
72 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
73 double minVal = Double.MIN_VALUE; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
74 double maxVal = Double.MAX_VALUE; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
75 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
76 if (minmax != null) { |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
77 minVal = minmax[0]; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
78 maxVal = minmax[1]; |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
79 } else { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
80 log.warn("Could not read min/max distance values!"); |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
81 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
82 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
83 if (name.equals("ld_from")) { |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
84 final Element min = createItem(cr, new String[] { "min", new Double(minVal).toString() }); |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
85 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
86 return new Element[] { min }; |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
87 } else if (name.equals("ld_to")) { |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
88 final Element max = createItem(cr, new String[] { "max", new Double(maxVal).toString() }); |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
90 return new Element[] { max }; |
9264
baef46792354
Explicitely checking for ld_step, in order to misuse this component (i.e. if there are additional data items)
gernotbelger
parents:
9175
diff
changeset
|
91 } else if (name.contentEquals("ld_step")) { |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
92 final Element step = createItem(cr, new String[] { "step", String.valueOf(getDefaultStep()) }); |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 return new Element[] { step }; |
9264
baef46792354
Explicitely checking for ld_step, in order to misuse this component (i.e. if there are additional data items)
gernotbelger
parents:
9175
diff
changeset
|
94 } else { |
baef46792354
Explicitely checking for ld_step, in order to misuse this component (i.e. if there are additional data items)
gernotbelger
parents:
9175
diff
changeset
|
95 return new Element[] {}; |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 @Override |
9164
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
100 protected double[] getMinMax(final Artifact artifact) { |
8c0d1542c1d8
uinfo.distance_only Berechnungsstrecke -> Darstellungsbereich HACK
gernotbelger
parents:
8776
diff
changeset
|
101 return new RiverAccess((D4EArtifact) artifact).getRiver().determineMinMaxDistance(); |
921
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
102 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
103 |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 protected double getDefaultStep() { |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
105 return DEFAULT_STEP; |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
106 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
107 } |
610d0e0f4f85
#159 Modifications in the transition model to support a state with a kilometer range input only.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |