Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java @ 2205:a22e0cb6eace
Format the timerange (static ui) inserted in the 'historical discharge curves' calculation.
flys-artifacts/trunk@3829 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 30 Jan 2012 13:29:07 +0000 |
parents | 19518116a49a |
children | 4cd0eb2ebb3b |
comparison
equal
deleted
inserted
replaced
2204:45f7762767e2 | 2205:a22e0cb6eace |
---|---|
110 | 110 |
111 if (value == null) { | 111 if (value == null) { |
112 return; | 112 return; |
113 } | 113 } |
114 | 114 |
115 logger.debug("Append element '" + name + "' (" + value + ")"); | 115 String type = data.getType(); |
116 | 116 |
117 Element e = createStaticData( | 117 logger.debug( |
118 flys, cr, context, name, value, data.getType()); | 118 "Append element " + type + "'" + |
119 name + "' (" + value + ")"); | |
120 | |
121 Element e = createStaticData(flys, cr, context, name, value, type); | |
119 | 122 |
120 ui.appendChild(e); | 123 ui.appendChild(e); |
121 | 124 |
122 } | 125 } |
123 | 126 |
139 CallContext cc, | 142 CallContext cc, |
140 String name, | 143 String name, |
141 String value, | 144 String value, |
142 String type | 145 String type |
143 ) { | 146 ) { |
144 CallMeta meta = cc.getMeta(); | |
145 | |
146 Element dataElement = creator.create("data"); | 147 Element dataElement = creator.create("data"); |
147 creator.addAttr(dataElement, "name", name, true); | 148 creator.addAttr(dataElement, "name", name, true); |
148 creator.addAttr(dataElement, "type", type, true); | 149 creator.addAttr(dataElement, "type", type, true); |
149 | 150 |
150 Element itemElement = creator.create("item"); | 151 Element itemElement = creator.create("item"); |
151 creator.addAttr(itemElement, "value", value, true); | 152 creator.addAttr(itemElement, "value", value, true); |
152 | 153 |
153 String attrValue = ""; | 154 creator.addAttr( |
155 itemElement, | |
156 "label", | |
157 getLabelFor(cc, name, value, type), | |
158 true); | |
159 | |
160 dataElement.appendChild(itemElement); | |
161 | |
162 return dataElement; | |
163 } | |
164 | |
165 | |
166 /** | |
167 * @param cc | |
168 * @param name | |
169 * @param value | |
170 * @param type | |
171 * | |
172 * @return | |
173 */ | |
174 protected String getLabelFor( | |
175 CallContext cc, | |
176 String name, | |
177 String value, | |
178 String type | |
179 ) { | |
180 CallMeta meta = cc.getMeta(); | |
181 | |
154 try { | 182 try { |
155 // XXX A better way to format the output would be to use the | 183 // XXX A better way to format the output would be to use the |
156 // 'type' value of the data objects. | 184 // 'type' value of the data objects. |
157 double doubleVal = Double.valueOf(value); | 185 double doubleVal = Double.valueOf(value); |
158 Locale l = Resources.getLocale(meta); | 186 Locale l = Resources.getLocale(meta); |
159 NumberFormat nf = NumberFormat.getInstance(l); | 187 NumberFormat nf = NumberFormat.getInstance(l); |
160 | 188 |
161 attrValue = nf.format(doubleVal); | 189 return nf.format(doubleVal); |
162 } | 190 } |
163 catch (NumberFormatException nfe) { | 191 catch (NumberFormatException nfe) { |
164 attrValue = Resources.getMsg(meta, value, value); | 192 return Resources.getMsg(meta, value, value); |
165 } | 193 } |
166 | |
167 creator.addAttr(itemElement, "label", attrValue, true); | |
168 dataElement.appendChild(itemElement); | |
169 | |
170 return dataElement; | |
171 } | 194 } |
172 | 195 |
173 | 196 |
174 public Element describe( | 197 public Element describe( |
175 Artifact artifact, | 198 Artifact artifact, |
354 * @return a StateData object with <i>name</i> and <i>val</i>ue. | 377 * @return a StateData object with <i>name</i> and <i>val</i>ue. |
355 */ | 378 */ |
356 public StateData transform( | 379 public StateData transform( |
357 FLYSArtifact flys, | 380 FLYSArtifact flys, |
358 CallContext cc, | 381 CallContext cc, |
382 StateData stateData, | |
359 String name, | 383 String name, |
360 String val | 384 String val |
361 ) { | 385 ) { |
362 logger.debug("Transform data ('" + name + "','" + val + "')"); | 386 logger.debug("Transform data ('" + name + "','" + val + "')"); |
363 return new DefaultStateData(name, null, null, val); | 387 |
388 stateData.setValue(val); | |
389 | |
390 return stateData; | |
364 } | 391 } |
365 | 392 |
366 | 393 |
367 /** | 394 /** |
368 * This method validates the inserted data and returns true, if everything | 395 * This method validates the inserted data and returns true, if everything |