comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/LocationDistanceSelect.java @ 136:2e510c998adb

New state for the location/distance input and some litte modifications of the DefaultState. flys-artifacts/trunk@1512 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 18 Mar 2011 08:50:42 +0000
parents
children 89bd0417418f
comparison
equal deleted inserted replaced
135:2d6e02787d00 136:2e510c998adb
1 package de.intevation.flys.artifacts.states;
2
3 import org.apache.log4j.Logger;
4
5 import org.w3c.dom.Element;
6
7 import de.intevation.artifacts.CallContext;
8
9 import de.intevation.artifacts.common.utils.XMLUtils;
10
11 import de.intevation.artifactdatabase.ProtocolUtils;
12 import de.intevation.artifactdatabase.data.StateData;
13
14 import de.intevation.flys.artifacts.resources.Resources;
15
16 /**
17 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
18 */
19 public class LocationDistanceSelect extends DefaultState {
20
21 /** The logger used in this class.*/
22 private static Logger logger = Logger.getLogger(LocationDistanceSelect.class);
23
24
25 /** The default step width.*/
26 public static final String DEFAULT_STEP = "100";
27
28 /**
29 * The default constructor that initializes an empty State object.
30 */
31 public LocationDistanceSelect() {
32 }
33
34 protected Element createData(
35 XMLUtils.ElementCreator cr,
36 StateData data,
37 CallContext context)
38 {
39 Element select = ProtocolUtils.createArtNode(
40 cr, "select", null, null);
41
42 cr.addAttr(select, "name", data.getName(), true);
43
44 Element label = ProtocolUtils.createArtNode(
45 cr, "label", null, null);
46
47 Element choices = ProtocolUtils.createArtNode(
48 cr, "choices", null, null);
49
50 label.setTextContent(Resources.getMsg(
51 context.getMeta(),
52 data.getName(),
53 data.getName()));
54
55 select.appendChild(label);
56
57 return select;
58 }
59
60
61 protected Element[] createItems(
62 XMLUtils.ElementCreator cr,
63 String name,
64 CallContext context)
65 {
66 // TODO Insert correct min/max values!
67
68 if (name.equals("ld_from")) {
69 Element min = createItem(cr, new String[] {"min", "1"});
70 return new Element[] { min };
71 }
72 else if (name.equals("ld_to")) {
73 Element max = createItem(cr, new String[] {"max", "10"});
74 return new Element[] { max };
75 }
76 else {
77 Element step = createItem(cr, new String[] {"step", DEFAULT_STEP});
78 return new Element[] { step };
79 }
80
81 }
82
83
84 protected Element createItem(XMLUtils.ElementCreator cr, Object obj) {
85 Element item = ProtocolUtils.createArtNode(cr, "item", null, null);
86 Element label = ProtocolUtils.createArtNode(cr, "label", null, null);
87 Element value = ProtocolUtils.createArtNode(cr, "value", null, null);
88
89 String[] arr = (String[]) obj;
90
91 label.setTextContent(arr[0]);
92 value.setTextContent(arr[1]);
93
94 item.appendChild(label);
95 item.appendChild(value);
96
97 return item;
98 }
99
100
101 protected String getUIProvider() {
102 return "location_distance_panel";
103 }
104 }
105 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org