Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/states/ReferenceGaugeState.java @ 5994:af13ceeba52a
Removed trailing whitespace.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 12 May 2013 18:13:50 +0200 |
parents | 59ff03ff48f1 |
children |
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:
4433
diff
changeset
|
9 package org.dive4elements.river.artifacts.states; |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
10 |
4174
eaf83d4ae6b1
Sorted gauges for reference gauge selection in historical discharge calculation based on their name.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
4049
diff
changeset
|
11 import java.util.Collections; |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
12 import java.util.List; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
13 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
14 import org.w3c.dom.Element; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
15 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4433
diff
changeset
|
16 import org.dive4elements.artifacts.Artifact; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4433
diff
changeset
|
17 import org.dive4elements.artifacts.CallContext; |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
18 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4433
diff
changeset
|
19 import org.dive4elements.artifacts.common.utils.XMLUtils; |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
20 |
5831
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4433
diff
changeset
|
21 import org.dive4elements.river.model.Gauge; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4433
diff
changeset
|
22 import org.dive4elements.river.model.River; |
bd047b71ab37
Repaired internal references
Sascha L. Teichmann <teichmann@intevation.de>
parents:
4433
diff
changeset
|
23 |
5867
59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5865
diff
changeset
|
24 import org.dive4elements.river.artifacts.D4EArtifact; |
5865
73da40528cf2
River artifacts: Renamed FLYSUtils to RiverUtils.
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5863
diff
changeset
|
25 import org.dive4elements.river.utils.RiverUtils; |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
26 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
27 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
28 /** |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
29 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
30 */ |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
31 public class ReferenceGaugeState extends DefaultState { |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
32 |
2207
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
33 public static final String DATA_NAME = "reference_gauge"; |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
34 |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
35 |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
36 @Override |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
37 protected Element[] createItems( |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
38 XMLUtils.ElementCreator cr, |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
39 Artifact artifact, |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
40 String name, |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
41 CallContext context) |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
42 { |
5867
59ff03ff48f1
River artifacts: Renamed FLYSArtifact(Collection) to D4EArtifact(Collection).
Sascha L. Teichmann <teichmann@intevation.de>
parents:
5865
diff
changeset
|
43 River river = RiverUtils.getRiver((D4EArtifact) artifact); |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
44 List<Gauge> gauges = river.getGauges(); |
4433
5b8919ef601d
Backed out changeset e8a4d2fd25cc
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents:
4432
diff
changeset
|
45 Collections.sort(gauges); |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
46 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
47 int num = gauges != null ? gauges.size() : 0; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
48 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
49 Element[] opts = new Element[num]; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
50 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
51 for (int i = 0; i < num; i++ ) { |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
52 Gauge g = gauges.get(i); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
53 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
54 String gaugeName = g.getName(); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
55 long officialNumber = g.getOfficialNumber(); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
56 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
57 opts[i] = createItem( |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
58 cr, new String[] { gaugeName, String.valueOf(officialNumber) }); |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
59 } |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
60 |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
61 return opts; |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
62 } |
2207
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
63 |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
64 |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
65 @Override |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
66 protected String getLabelFor( |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
67 CallContext cc, |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
68 String name, |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
69 String value, |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
70 String type |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
71 ) { |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
72 if (name.equals(DATA_NAME)) { |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
73 try { |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
74 long number = Long.valueOf(value); |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
75 Gauge gauge = Gauge.getGaugeByOfficialNumber(number); |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
76 |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
77 if (gauge != null) { |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
78 return gauge.getName(); |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
79 } |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
80 } |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
81 catch (NumberFormatException nfe) { |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
82 // do nothing |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
83 } |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
84 } |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
85 |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
86 return super.getLabelFor(cc, name, value, type); |
a38f43f626f5
Display the name of the reference gauge in the static ui of 'historical discharge curves' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
2191
diff
changeset
|
87 } |
2191
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
88 } |
f28844a57fed
Added states (work is not finished yet) for the 'historical discharge curve' calculation.
Ingo Weinzierl <ingo.weinzierl@intevation.de>
parents:
diff
changeset
|
89 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |