Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java @ 115:b51e92fef704
The RiverSelect state creates the dynamic UI part for the describe document now.
flys-artifacts/trunk@1304 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 08 Feb 2011 09:11:25 +0000 |
parents | 9891d133f08d |
children | 47a4bc7a9ddf |
comparison
equal
deleted
inserted
replaced
114:394b9580ceae | 115:b51e92fef704 |
---|---|
1 package de.intevation.flys.artifacts.states; | 1 package de.intevation.flys.artifacts.states; |
2 | |
3 import java.util.Collection; | |
4 import java.util.List; | |
5 import java.util.Map; | |
2 | 6 |
3 import org.apache.log4j.Logger; | 7 import org.apache.log4j.Logger; |
4 | 8 |
5 import org.w3c.dom.Document; | 9 import org.w3c.dom.Document; |
10 import org.w3c.dom.Element; | |
6 import org.w3c.dom.Node; | 11 import org.w3c.dom.Node; |
7 | 12 |
8 import de.intevation.artifacts.CallContext; | 13 import de.intevation.artifacts.CallContext; |
14 import de.intevation.artifacts.ArtifactNamespaceContext; | |
9 | 15 |
16 import de.intevation.artifacts.common.utils.XMLUtils; | |
17 | |
18 import de.intevation.artifactdatabase.ProtocolUtils; | |
19 import de.intevation.artifactdatabase.data.StateData; | |
10 import de.intevation.artifactdatabase.state.AbstractState; | 20 import de.intevation.artifactdatabase.state.AbstractState; |
21 | |
22 import de.intevation.flys.artifacts.model.River; | |
23 import de.intevation.flys.artifacts.model.RiverFactory; | |
11 | 24 |
12 | 25 |
13 /** | 26 /** |
14 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
15 */ | 28 */ |
34 public void setup(Node config) { | 47 public void setup(Node config) { |
35 super.setup(config); | 48 super.setup(config); |
36 } | 49 } |
37 | 50 |
38 | 51 |
52 /** | |
53 * This method creates the UI part of the artifact's describe document. The | |
54 * ui part consists of a static - representing previous inserted data - and | |
55 * a dynamic part - representing data that is necessary to be inserted in | |
56 * the current state. | |
57 * | |
58 * @param document The describe document. | |
59 * @param root The root node of the describe document. | |
60 * @param context The CallContext. | |
61 * @param uuid The uuid of the artifact. | |
62 */ | |
39 public void describe( | 63 public void describe( |
40 Document document, | 64 Document document, |
41 Node root, | 65 Node root, |
42 CallContext context, | 66 CallContext context, |
43 String uuid) | 67 String uuid) |
44 { | 68 { |
45 // TODO Implement me | 69 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( |
46 logger.error("Currently not implemented."); | 70 document, |
71 ArtifactNamespaceContext.NAMESPACE_URI, | |
72 ArtifactNamespaceContext.NAMESPACE_PREFIX); | |
73 | |
74 Element ui = ProtocolUtils.createArtNode( | |
75 creator, "ui", null, null); | |
76 | |
77 Element staticUI = ProtocolUtils.createArtNode( | |
78 creator, "static", null, null); | |
79 | |
80 // TODO Add the static data | |
81 logger.error("TODO: ADD STATIC DATA TO DESCRIBE DOCUMENT."); | |
82 | |
83 Element dynamicUI = ProtocolUtils.createArtNode( | |
84 creator, "dynamic", null, null); | |
85 | |
86 Map<String, StateData> data = getData(); | |
87 | |
88 if (data != null) { | |
89 Collection<StateData> items = data.values(); | |
90 | |
91 for (StateData item: items) { | |
92 Element select = ProtocolUtils.createArtNode( | |
93 creator, "select", | |
94 new String[] { "special" }, | |
95 new String[] { "river" }); | |
96 | |
97 Element label = ProtocolUtils.createArtNode( | |
98 creator, "label", null, null); | |
99 | |
100 Element choices = ProtocolUtils.createArtNode( | |
101 creator, "choices", null, null); | |
102 | |
103 label.setTextContent("River"); | |
104 | |
105 select.appendChild(label); | |
106 select.appendChild(choices); | |
107 | |
108 List<River> rivers = RiverFactory.getRivers(); | |
109 | |
110 for (River river: rivers) { | |
111 choices.appendChild(createRiverItem(creator, river)); | |
112 } | |
113 | |
114 dynamicUI.appendChild(select); | |
115 } | |
116 } | |
117 | |
118 ui.appendChild(staticUI); | |
119 ui.appendChild(dynamicUI); | |
120 | |
121 root.appendChild(ui); | |
122 } | |
123 | |
124 | |
125 /** | |
126 * This method creates a node that represents a river item. This node | |
127 * contains the label and the value that describe the river. | |
128 * | |
129 * @param cr The ElementCreator. | |
130 * @param river The river. | |
131 * | |
132 * @return the element that contains the information about the river. | |
133 */ | |
134 protected Element createRiverItem(XMLUtils.ElementCreator cr, River river) { | |
135 Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
136 Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
137 Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
138 | |
139 label.setTextContent(river.getName()); | |
140 value.setTextContent(river.getName()); | |
141 | |
142 item.appendChild(label); | |
143 item.appendChild(value); | |
144 | |
145 return item; | |
47 } | 146 } |
48 } | 147 } |
49 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 148 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |