Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/states/MultiIntArrayState.java @ 8852:8f6d6d26e96f
Refaktored the DatacageTwinPanel so it is reusable.
author | gernotbelger |
---|---|
date | Thu, 18 Jan 2018 18:32:30 +0100 |
parents | e4606eae8ea5 |
children | 5e38e2924c07 |
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:
3083
diff
changeset
|
9 package org.dive4elements.river.artifacts.states; |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import org.w3c.dom.Element; |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 import org.apache.log4j.Logger; |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3083
diff
changeset
|
15 import org.dive4elements.artifacts.Artifact; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3083
diff
changeset
|
16 import org.dive4elements.artifacts.CallContext; |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3083
diff
changeset
|
18 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3083
diff
changeset
|
19 import org.dive4elements.artifacts.common.model.KVP; |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
5867
59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5865
diff
changeset
|
21 import org.dive4elements.river.artifacts.D4EArtifact; |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
3083
diff
changeset
|
22 import org.dive4elements.river.artifacts.resources.Resources; |
5865
73da40528cf2
River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
23 import org.dive4elements.river.utils.RiverUtils; |
2705
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
24 |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 /** |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 * State that holds minimun and maximum (for validation). |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 * |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 */ |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 public abstract class MultiIntArrayState extends DefaultState { |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
33 private static final Logger log = |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 Logger.getLogger(MultiIntArrayState.class); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 @Override |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 protected void appendItems( |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 Artifact artifact, |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 ElementCreator creator, |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 String name, |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 CallContext context, |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 Element select |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 ) { |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 try { |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 creator.addAttr(select, "type", "intoptions", true); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 for (KVP kvp: getOptions(artifact, name)) { |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 Element item = creator.create("item"); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 creator.addAttr(item, "label", kvp.getValue().toString(), true); |
2708
282db12a5bdf
Adapted the dynamic DESCRIBE creation of MultiIntArrayState to be able to use default mechanisms in FLYS client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2705
diff
changeset
|
51 creator.addAttr(item, "value", kvp.getKey().toString(), true); |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 |
2708
282db12a5bdf
Adapted the dynamic DESCRIBE creation of MultiIntArrayState to be able to use default mechanisms in FLYS client.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2705
diff
changeset
|
53 select.appendChild(item); |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 } |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 } |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 catch (IllegalArgumentException iae) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
57 log.warn("Illegal argument", iae); |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 } |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 } |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 |
2705
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
62 @Override |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
63 protected Element createStaticData( |
5867
59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5865
diff
changeset
|
64 D4EArtifact flys, |
2705
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
65 ElementCreator creator, |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
66 CallContext cc, |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
67 String name, |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
68 String value, |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
69 String type |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
70 ) { |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
71 Element data = creator.create("data"); |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
72 creator.addAttr(data, "name", name, true); |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
73 creator.addAttr(data, "type", type, true); |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
74 creator.addAttr(data, "label", |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
75 Resources.getMsg(cc.getMeta(), name, name), true); |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
76 |
5865
73da40528cf2
River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
77 int[] values = RiverUtils.intArrayFromString(value); |
2705
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
78 |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
79 for (int val: values) { |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
80 try { |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
81 Element item = creator.create("item"); |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
82 creator.addAttr(item, "value", String.valueOf(val), true); |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
83 creator.addAttr(item, "label", getLabelFor(cc, name, val), true); |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
84 |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
85 data.appendChild(item); |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
86 } |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
87 catch (IllegalArgumentException iae) { |
8202
e4606eae8ea5
sed src/**/*.java 's/logger/log/g'
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5994
diff
changeset
|
88 log.warn("Cannot append item: " + val, iae); |
2705
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
89 } |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
90 } |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
91 |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
92 return data; |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
93 } |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
94 |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
95 |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 protected abstract KVP<Integer, String>[] getOptions( |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
97 Artifact artifact, |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
98 String parameterName |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
99 ) |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
100 throws IllegalArgumentException; |
2705
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
101 |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
102 |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
103 protected abstract String getLabelFor( |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
104 CallContext cc, |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
105 String parameterName, |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
106 int value) |
71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2696
diff
changeset
|
107 throws IllegalArgumentException; |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
108 } |
3083
4bd3d8bbb60c
Added missing vim lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
2708
diff
changeset
|
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |