Mercurial > dive4elements > river
annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MultiIntArrayState.java @ 2706:d8444fcb4e44
Create chart facets for flow velocity calculation and a chart generator for this.
flys-artifacts/trunk@4424 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 16 May 2012 12:39:13 +0000 (2012-05-16) |
parents | 71f072d8b3d8 |
children | 282db12a5bdf |
rev | line source |
---|---|
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.flys.artifacts.states; |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
2 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
3 import org.w3c.dom.Element; |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
4 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
5 import org.apache.log4j.Logger; |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
6 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
7 import de.intevation.artifacts.Artifact; |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
8 import de.intevation.artifacts.CallContext; |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
9 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
11 import de.intevation.artifacts.common.model.KVP; |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 |
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
|
13 import de.intevation.flys.artifacts.FLYSArtifact; |
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
|
14 import de.intevation.flys.artifacts.resources.Resources; |
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
|
15 import de.intevation.flys.utils.FLYSUtils; |
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
|
16 |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
17 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 /** |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
19 * 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
|
20 * |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
21 * @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
|
22 */ |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
23 public abstract class MultiIntArrayState extends DefaultState { |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
24 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
25 private static final Logger logger = |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 Logger.getLogger(MultiIntArrayState.class); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
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 @Override |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 protected void appendItems( |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 Artifact artifact, |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 ElementCreator creator, |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
33 String name, |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
34 CallContext context, |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
35 Element select |
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 try { |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 creator.addAttr(select, "type", "intoptions", true); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 Element choices = creator.create("choices"); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 for (KVP kvp: getOptions(artifact, name)) { |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
43 Element item = creator.create("item"); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 creator.addAttr(item, "label", kvp.getValue().toString(), true); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
45 item.setTextContent(kvp.getKey().toString()); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 choices.appendChild(item); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 } |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 select.appendChild(choices); |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 } |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 catch (IllegalArgumentException iae) { |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 logger.warn("Illegal argument", iae); |
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 |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 |
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
|
58 @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
|
59 protected Element createStaticData( |
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
|
60 FLYSArtifact flys, |
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
|
61 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
|
62 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
|
63 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
|
64 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
|
65 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
|
66 ) { |
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 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
|
68 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
|
69 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
|
70 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
|
71 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
|
72 |
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 int[] values = FLYSUtils.intArrayFromString(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
|
74 |
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 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
|
76 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
|
77 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
|
78 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
|
79 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
|
80 |
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 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
|
82 } |
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 catch (IllegalArgumentException iae) { |
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 logger.warn("Cannot append item: " + val, iae); |
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 } |
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 |
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
|
88 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
|
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 |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
92 protected abstract KVP<Integer, String>[] getOptions( |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
93 Artifact artifact, |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
94 String parameterName |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
95 ) |
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
96 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
|
97 |
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
|
98 |
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
|
99 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
|
100 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
|
101 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
|
102 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
|
103 throws IllegalArgumentException; |
2696
1bc35de0b786
Improved the states for MINFO flow velocity calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
104 } |