Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelSelectState.java @ 1180:1aba1a75beb2
Write the name of the selected waterlevels (used for the floodmap) into the static DESCRIBE.
flys-artifacts/trunk@2770 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Fri, 16 Sep 2011 08:47:09 +0000 |
parents | 1b432c260e97 |
children | 47ecf98f09eb |
comparison
equal
deleted
inserted
replaced
1179:ebb48bef3529 | 1180:1aba1a75beb2 |
---|---|
1 package de.intevation.flys.artifacts.states; | 1 package de.intevation.flys.artifacts.states; |
2 | 2 |
3 import org.apache.log4j.Logger; | 3 import org.apache.log4j.Logger; |
4 | 4 |
5 import org.w3c.dom.Element; | |
6 | |
5 import de.intevation.artifacts.Artifact; | 7 import de.intevation.artifacts.Artifact; |
6 import de.intevation.artifacts.CallContext; | 8 import de.intevation.artifacts.CallContext; |
9 import de.intevation.artifacts.CallMeta; | |
7 | 10 |
8 import de.intevation.artifactdatabase.data.DefaultStateData; | 11 import de.intevation.artifactdatabase.data.DefaultStateData; |
9 import de.intevation.artifactdatabase.data.StateData; | 12 import de.intevation.artifactdatabase.data.StateData; |
10 | 13 |
14 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
15 | |
11 import de.intevation.flys.artifacts.FLYSArtifact; | 16 import de.intevation.flys.artifacts.FLYSArtifact; |
17 import de.intevation.flys.artifacts.model.CalculationResult; | |
18 import de.intevation.flys.artifacts.model.WQKms; | |
19 import de.intevation.flys.artifacts.resources.Resources; | |
12 import de.intevation.flys.utils.FLYSUtils; | 20 import de.intevation.flys.utils.FLYSUtils; |
13 | 21 |
14 | 22 |
15 /** | 23 /** |
16 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 24 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
19 | 27 |
20 private static final Logger logger = | 28 private static final Logger logger = |
21 Logger.getLogger(WaterlevelSelectState.class); | 29 Logger.getLogger(WaterlevelSelectState.class); |
22 | 30 |
23 public static final String SPLIT_CHAR = ";"; | 31 public static final String SPLIT_CHAR = ";"; |
32 | |
33 public static final String WINFO_WSP_STATE_ID = "state.winfo.waterlevel"; | |
34 | |
35 public static final String I18N_STATIC_KEY = "wsp.selected.string"; | |
24 | 36 |
25 | 37 |
26 @Override | 38 @Override |
27 protected String getUIProvider() { | 39 protected String getUIProvider() { |
28 return "wsp_datacage_panel"; | 40 return "wsp_datacage_panel"; |
56 if (data == null) { | 68 if (data == null) { |
57 throw new IllegalArgumentException("WSP is empty"); | 69 throw new IllegalArgumentException("WSP is empty"); |
58 } | 70 } |
59 | 71 |
60 return true; | 72 return true; |
73 } | |
74 | |
75 | |
76 @Override | |
77 protected Element createStaticData( | |
78 ElementCreator creator, | |
79 CallContext cc, | |
80 String name, | |
81 String value, | |
82 String type | |
83 ) { | |
84 Element dataElement = creator.create("data"); | |
85 creator.addAttr(dataElement, "name", name, true); | |
86 creator.addAttr(dataElement, "type", type, true); | |
87 | |
88 Element itemElement = creator.create("item"); | |
89 creator.addAttr(itemElement, "value", value, true); | |
90 | |
91 String[] labels = getLabels(cc, value); | |
92 Object[] obj = new Object[] { labels[0] }; | |
93 | |
94 String attrValue = Resources.getMsg( | |
95 cc.getMeta(), I18N_STATIC_KEY, I18N_STATIC_KEY, obj); | |
96 | |
97 creator.addAttr(itemElement, "label", attrValue, true); | |
98 dataElement.appendChild(itemElement); | |
99 | |
100 return dataElement; | |
101 } | |
102 | |
103 | |
104 public static String[] getLabels(CallContext cc, String value) { | |
105 String[] parts = value.split(SPLIT_CHAR); | |
106 | |
107 FLYSArtifact artifact = FLYSUtils.getArtifact(parts[0], cc); | |
108 | |
109 CalculationResult rawData = (CalculationResult) artifact.compute( | |
110 cc, | |
111 null, | |
112 WINFO_WSP_STATE_ID, | |
113 ComputeType.ADVANCE, | |
114 false); | |
115 | |
116 WQKms[] wqkms = (WQKms[]) rawData.getData(); | |
117 | |
118 int idx = -1; | |
119 try { | |
120 idx = Integer.parseInt(parts[2]); | |
121 } | |
122 catch (NumberFormatException nfe) { /* do nothing */ } | |
123 | |
124 return new String[] { wqkms[idx].getName() }; | |
61 } | 125 } |
62 | 126 |
63 | 127 |
64 public static String strip(String value) { | 128 public static String strip(String value) { |
65 int start = value.indexOf("["); | 129 int start = value.indexOf("["); |