Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/states/RiverSelect.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/RiverSelect.java@8e66293c5369 |
children |
comparison
equal
deleted
inserted
replaced
5830:160f53ee0870 | 5831:bd047b71ab37 |
---|---|
1 package org.dive4elements.river.artifacts.states; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.w3c.dom.Element; | |
8 import org.w3c.dom.Node; | |
9 | |
10 import org.dive4elements.artifacts.Artifact; | |
11 import org.dive4elements.artifacts.CallContext; | |
12 | |
13 import org.dive4elements.artifacts.common.utils.XMLUtils; | |
14 | |
15 import org.dive4elements.artifactdatabase.ProtocolUtils; | |
16 import org.dive4elements.artifactdatabase.data.StateData; | |
17 | |
18 import org.dive4elements.river.model.River; | |
19 | |
20 import org.dive4elements.river.artifacts.FLYSArtifact; | |
21 import org.dive4elements.river.artifacts.model.RiverFactory; | |
22 import org.dive4elements.river.artifacts.resources.Resources; | |
23 | |
24 | |
25 /** | |
26 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
27 */ | |
28 public class RiverSelect extends DefaultState { | |
29 | |
30 /** The logger used in this class. */ | |
31 private static Logger logger = Logger.getLogger(RiverSelect.class); | |
32 | |
33 /** Error message that is thrown if no river was found based on a given | |
34 * name.*/ | |
35 public static final String ERROR_NO_SUCH_RIVER = | |
36 "error_feed_no_such_river"; | |
37 | |
38 /** Error message that is thrown if no river was found based on a given | |
39 * name.*/ | |
40 public static final String ERROR_NO_RIVER_SELECTED = | |
41 "error_feed_no_river_selected"; | |
42 | |
43 | |
44 /** | |
45 * The default constructor that initializes an empty State object. | |
46 */ | |
47 public RiverSelect() { | |
48 } | |
49 | |
50 | |
51 /** | |
52 * Initialize the state based on the state node in the configuration. | |
53 * | |
54 * @param config The state configuration node. | |
55 */ | |
56 public void setup(Node config) { | |
57 super.setup(config); | |
58 } | |
59 | |
60 | |
61 protected Element createData( | |
62 XMLUtils.ElementCreator cr, | |
63 Artifact artifact, | |
64 StateData data, | |
65 CallContext context) | |
66 { | |
67 Element select = ProtocolUtils.createArtNode( | |
68 cr, "select", | |
69 new String[] { "uiprovider" }, | |
70 new String[] { "select_with_map" }); | |
71 cr.addAttr(select, "name", data.getName(), true); | |
72 | |
73 Element label = ProtocolUtils.createArtNode( | |
74 cr, "label", null, null); | |
75 | |
76 | |
77 // XXX: DEAD CODE | |
78 /* | |
79 Element choices = ProtocolUtils.createArtNode( | |
80 cr, "choices", null, null); | |
81 */ | |
82 | |
83 select.appendChild(label); | |
84 | |
85 label.setTextContent(Resources.getMsg( | |
86 context.getMeta(), | |
87 getID(), | |
88 getID())); | |
89 | |
90 return select; | |
91 } | |
92 | |
93 | |
94 @Override | |
95 protected Element[] createItems( | |
96 XMLUtils.ElementCreator cr, | |
97 Artifact artifact, | |
98 String name, | |
99 CallContext context) | |
100 { | |
101 List<River> rivers = RiverFactory.getRivers(); | |
102 Element[] items = new Element[rivers.size()]; | |
103 | |
104 int idx = 0; | |
105 for (River river: rivers) { | |
106 items[idx++] = createRiverItem(cr, river); | |
107 } | |
108 | |
109 return items; | |
110 } | |
111 | |
112 | |
113 /** | |
114 * This method creates a node that represents a river item. This node | |
115 * contains the label and the value that describe the river. | |
116 * | |
117 * @param cr The ElementCreator. | |
118 * @param river The river. | |
119 * | |
120 * @return the element that contains the information about the river. | |
121 */ | |
122 protected Element createRiverItem(XMLUtils.ElementCreator cr, River river) { | |
123 Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
124 Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
125 Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
126 | |
127 label.setTextContent(river.getName()); | |
128 value.setTextContent(river.getName()); | |
129 | |
130 item.appendChild(label); | |
131 item.appendChild(value); | |
132 | |
133 return item; | |
134 } | |
135 | |
136 | |
137 @Override | |
138 public boolean validate(Artifact artifact) | |
139 throws IllegalArgumentException | |
140 { | |
141 logger.debug("RiverSelect.validate"); | |
142 | |
143 FLYSArtifact flys = (FLYSArtifact) artifact; | |
144 | |
145 StateData dRiver = getData(flys, "river"); | |
146 | |
147 if (dRiver == null || dRiver.getValue() == null) { | |
148 throw new IllegalArgumentException(ERROR_NO_RIVER_SELECTED); | |
149 } | |
150 | |
151 River river = RiverFactory.getRiver((String) dRiver.getValue()); | |
152 | |
153 if (river == null) { | |
154 throw new IllegalArgumentException(ERROR_NO_SUCH_RIVER); | |
155 } | |
156 | |
157 return true; | |
158 } | |
159 | |
160 | |
161 @Override | |
162 protected String getUIProvider() { | |
163 return "river_panel"; | |
164 } | |
165 } | |
166 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |