Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/states/minfo/BedQualityDistanceSelect.java @ 8613:39ce099a6551
(issue1755) Add good defaults for bedquality distance selection
author | Andre Heinecke <andre.heinecke@intevation.de> |
---|---|
date | Tue, 24 Mar 2015 18:17:23 +0100 |
parents | |
children | 5102733c4567 |
comparison
equal
deleted
inserted
replaced
8612:b5854a9b101c | 8613:39ce099a6551 |
---|---|
1 /* Copyright (C) 2011, 2012, 2013, 2015 by Bundesanstalt für Gewässerkunde | |
2 * Software engineering by Intevation GmbH | |
3 * | |
4 * This file is Free Software under the GNU AGPL (>=v3) | |
5 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
6 * documentation coming with Dive4Elements River for details. | |
7 */ | |
8 | |
9 package org.dive4elements.river.artifacts.states.minfo; | |
10 | |
11 import java.util.Date; | |
12 import java.util.List; | |
13 | |
14 import org.w3c.dom.Element; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 | |
18 import org.dive4elements.river.artifacts.D4EArtifact; | |
19 import org.dive4elements.river.artifacts.access.RiverAccess; | |
20 import org.dive4elements.river.artifacts.states.DistanceSelect; | |
21 import org.dive4elements.river.utils.KMIndex; | |
22 | |
23 import org.dive4elements.river.artifacts.model.minfo.BedOverview; | |
24 import org.dive4elements.river.artifacts.model.minfo.BedOverviewFactory; | |
25 | |
26 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
27 import org.dive4elements.artifacts.Artifact; | |
28 import org.dive4elements.artifacts.CallContext; | |
29 | |
30 import org.dive4elements.artifactdatabase.data.StateData; | |
31 | |
32 /** Extended Distance Select with default values appropiate for BedQuality */ | |
33 public class BedQualityDistanceSelect extends DistanceSelect { | |
34 | |
35 private static Logger log = Logger.getLogger(BedQualityDistanceSelect.class); | |
36 | |
37 /** | |
38 * The default constructor that initializes an empty State object. | |
39 */ | |
40 public BedQualityDistanceSelect() { | |
41 } | |
42 | |
43 @Override | |
44 protected Element createData( | |
45 XMLUtils.ElementCreator cr, | |
46 Artifact artifact, | |
47 StateData data, | |
48 CallContext context) | |
49 { | |
50 Element ele = super.createData(cr, artifact, data, context); | |
51 if (!data.getName().equals("ld_from") && !data.getName().equals("ld_to")) { | |
52 return ele; | |
53 } | |
54 | |
55 D4EArtifact arti = (D4EArtifact) artifact; | |
56 RiverAccess access = new RiverAccess(arti); | |
57 | |
58 /* Bit of an overkill here but it will be cached and accessed | |
59 * in the next state anyway. */ | |
60 BedOverview overview = BedOverviewFactory.getOverview(access.getRiverName()); | |
61 | |
62 if (overview == null) { | |
63 log.warn("No overview found for river '" + access.getRiverName() + "'"); | |
64 return ele; | |
65 } | |
66 | |
67 KMIndex<List<Date>> entries = overview.filter(BedOverview.ACCEPT); | |
68 entries.sort(); | |
69 | |
70 if (data.getName().equals("ld_from")) { | |
71 cr.addAttr(ele, "defaultLabel", data.getName(), true); | |
72 cr.addAttr(ele, "defaultValue", Double.toString(entries.get(0).getKm()), true); | |
73 } else if (data.getName().equals("ld_to")) { | |
74 cr.addAttr(ele, "defaultLabel", data.getName(), true); | |
75 cr.addAttr(ele, "defaultValue", Double.toString(entries.get(entries.size()-1).getKm()), true); | |
76 } | |
77 | |
78 return ele; | |
79 } | |
80 } |