Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/ReferenceGaugeState.java @ 5831:bd047b71ab37
Repaired internal references
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:06:39 +0200 |
parents | flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/ReferenceGaugeState.java@5b8919ef601d |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.states; | |
2 | |
3 import java.util.Collections; | |
4 import java.util.List; | |
5 | |
6 import org.w3c.dom.Element; | |
7 | |
8 import org.dive4elements.artifacts.Artifact; | |
9 import org.dive4elements.artifacts.CallContext; | |
10 | |
11 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
12 | |
13 import org.dive4elements.river.model.Gauge; | |
14 import org.dive4elements.river.model.River; | |
15 | |
16 import org.dive4elements.river.artifacts.FLYSArtifact; | |
17 import org.dive4elements.river.utils.FLYSUtils; | |
18 | |
19 | |
20 /** | |
21 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
22 */ | |
23 public class ReferenceGaugeState extends DefaultState { | |
24 | |
25 public static final String DATA_NAME = "reference_gauge"; | |
26 | |
27 | |
28 @Override | |
29 protected Element[] createItems( | |
30 XMLUtils.ElementCreator cr, | |
31 Artifact artifact, | |
32 String name, | |
33 CallContext context) | |
34 { | |
35 River river = FLYSUtils.getRiver((FLYSArtifact) artifact); | |
36 List<Gauge> gauges = river.getGauges(); | |
37 Collections.sort(gauges); | |
38 | |
39 int num = gauges != null ? gauges.size() : 0; | |
40 | |
41 Element[] opts = new Element[num]; | |
42 | |
43 for (int i = 0; i < num; i++ ) { | |
44 Gauge g = gauges.get(i); | |
45 | |
46 String gaugeName = g.getName(); | |
47 long officialNumber = g.getOfficialNumber(); | |
48 | |
49 opts[i] = createItem( | |
50 cr, new String[] { gaugeName, String.valueOf(officialNumber) }); | |
51 } | |
52 | |
53 return opts; | |
54 } | |
55 | |
56 | |
57 @Override | |
58 protected String getLabelFor( | |
59 CallContext cc, | |
60 String name, | |
61 String value, | |
62 String type | |
63 ) { | |
64 if (name.equals(DATA_NAME)) { | |
65 try { | |
66 long number = Long.valueOf(value); | |
67 Gauge gauge = Gauge.getGaugeByOfficialNumber(number); | |
68 | |
69 if (gauge != null) { | |
70 return gauge.getName(); | |
71 } | |
72 } | |
73 catch (NumberFormatException nfe) { | |
74 // do nothing | |
75 } | |
76 } | |
77 | |
78 return super.getLabelFor(cc, name, value, type); | |
79 } | |
80 } | |
81 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |