comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java @ 313:89bd0417418f

The location/distance state now writes default values into DESCRIBE. flys-artifacts/trunk@1697 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 14 Apr 2011 13:36:06 +0000
parents 2e510c998adb
children 448d0dc64357
comparison
equal deleted inserted replaced
312:0c6328c227f1 313:89bd0417418f
2 2
3 import org.apache.log4j.Logger; 3 import org.apache.log4j.Logger;
4 4
5 import org.w3c.dom.Element; 5 import org.w3c.dom.Element;
6 6
7 import de.intevation.artifacts.Artifact;
7 import de.intevation.artifacts.CallContext; 8 import de.intevation.artifacts.CallContext;
8 9
9 import de.intevation.artifacts.common.utils.XMLUtils; 10 import de.intevation.artifacts.common.utils.XMLUtils;
10 11
11 import de.intevation.artifactdatabase.ProtocolUtils; 12 import de.intevation.artifactdatabase.ProtocolUtils;
12 import de.intevation.artifactdatabase.data.StateData; 13 import de.intevation.artifactdatabase.data.StateData;
13 14
15 import de.intevation.flys.model.River;
16
17 import de.intevation.flys.artifacts.FLYSArtifact;
18 import de.intevation.flys.artifacts.model.RiverFactory;
14 import de.intevation.flys.artifacts.resources.Resources; 19 import de.intevation.flys.artifacts.resources.Resources;
15 20
16 /** 21 /**
17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> 22 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
18 */ 23 */
31 public LocationDistanceSelect() { 36 public LocationDistanceSelect() {
32 } 37 }
33 38
34 protected Element createData( 39 protected Element createData(
35 XMLUtils.ElementCreator cr, 40 XMLUtils.ElementCreator cr,
41 Artifact artifact,
36 StateData data, 42 StateData data,
37 CallContext context) 43 CallContext context)
38 { 44 {
39 Element select = ProtocolUtils.createArtNode( 45 Element select = ProtocolUtils.createArtNode(
40 cr, "select", null, null); 46 cr, "select", null, null);
58 } 64 }
59 65
60 66
61 protected Element[] createItems( 67 protected Element[] createItems(
62 XMLUtils.ElementCreator cr, 68 XMLUtils.ElementCreator cr,
69 Artifact artifact,
63 String name, 70 String name,
64 CallContext context) 71 CallContext context)
65 { 72 {
66 // TODO Insert correct min/max values! 73 double[] minmax = getMinMaxDistance(artifact);
74
75 double minVal = Double.MIN_VALUE;
76 double maxVal = Double.MAX_VALUE;
77
78 if (minmax != null) {
79 minVal = minmax[0];
80 maxVal = minmax[1];
81 }
82 else {
83 logger.warn("Could not read min/max distance values!");
84 }
67 85
68 if (name.equals("ld_from")) { 86 if (name.equals("ld_from")) {
69 Element min = createItem(cr, new String[] {"min", "1"}); 87 Element min = createItem(
88 cr,
89 new String[] {"min", new Double(minVal).toString()});
90
70 return new Element[] { min }; 91 return new Element[] { min };
71 } 92 }
72 else if (name.equals("ld_to")) { 93 else if (name.equals("ld_to")) {
73 Element max = createItem(cr, new String[] {"max", "10"}); 94 Element max = createItem(
95 cr,
96 new String[] {"max", new Double(maxVal).toString()});
97
74 return new Element[] { max }; 98 return new Element[] { max };
75 } 99 }
76 else { 100 else {
77 Element step = createItem(cr, new String[] {"step", DEFAULT_STEP}); 101 Element step = createItem(cr, new String[] {"step", DEFAULT_STEP});
78 return new Element[] { step }; 102 return new Element[] { step };
99 123
100 124
101 protected String getUIProvider() { 125 protected String getUIProvider() {
102 return "location_distance_panel"; 126 return "location_distance_panel";
103 } 127 }
128
129
130 protected double[] getMinMaxDistance(Artifact artifact) {
131 FLYSArtifact flysArtifact = (FLYSArtifact) artifact;
132 StateData data = flysArtifact.getData("river");
133
134 String name = (String) data.getValue();
135
136 logger.debug("Search for the min/max distances of '" + name + "'");
137
138 River river = RiverFactory.getRiver(name);
139
140 return river != null ? river.determineMinMaxDistance() : null;
141 }
104 } 142 }
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : 143 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org