Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java @ 126:b18aebd1342f
Added an abstract base class DefaultState for States.
flys-artifacts/trunk@1466 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Mon, 14 Mar 2011 15:43:12 +0000 |
parents | 47a4bc7a9ddf |
children | 8be4a837f20a |
comparison
equal
deleted
inserted
replaced
125:25593857b8f8 | 126:b18aebd1342f |
---|---|
1 package de.intevation.flys.artifacts.states; | 1 package de.intevation.flys.artifacts.states; |
2 | 2 |
3 import java.util.Collection; | |
4 import java.util.List; | 3 import java.util.List; |
5 import java.util.Map; | |
6 | 4 |
7 import org.apache.log4j.Logger; | 5 import org.apache.log4j.Logger; |
8 | 6 |
9 import org.w3c.dom.Document; | |
10 import org.w3c.dom.Element; | 7 import org.w3c.dom.Element; |
11 import org.w3c.dom.Node; | 8 import org.w3c.dom.Node; |
12 | 9 |
13 import de.intevation.artifacts.CallContext; | 10 import de.intevation.artifacts.CallContext; |
14 import de.intevation.artifacts.ArtifactNamespaceContext; | |
15 | 11 |
16 import de.intevation.artifacts.common.utils.XMLUtils; | 12 import de.intevation.artifacts.common.utils.XMLUtils; |
17 | 13 |
18 import de.intevation.artifactdatabase.ProtocolUtils; | 14 import de.intevation.artifactdatabase.ProtocolUtils; |
19 import de.intevation.artifactdatabase.data.StateData; | 15 import de.intevation.artifactdatabase.data.StateData; |
20 import de.intevation.artifactdatabase.state.AbstractState; | |
21 | 16 |
22 import de.intevation.flys.artifacts.model.River; | 17 import de.intevation.flys.artifacts.model.River; |
23 import de.intevation.flys.artifacts.model.RiverFactory; | 18 import de.intevation.flys.artifacts.model.RiverFactory; |
19 import de.intevation.flys.artifacts.resources.Resources; | |
24 | 20 |
25 | 21 |
26 /** | 22 /** |
27 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | 23 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> |
28 */ | 24 */ |
29 public class RiverSelect extends AbstractState { | 25 public class RiverSelect extends DefaultState { |
30 | 26 |
31 /** The logger used in this class. */ | 27 /** The logger used in this class. */ |
32 private static Logger logger = Logger.getLogger(RiverSelect.class); | 28 private static Logger logger = Logger.getLogger(RiverSelect.class); |
33 | 29 |
34 /** | 30 /** |
35 * The default constructor that initializes an empty State object. | 31 * The default constructor that initializes an empty State object. |
36 */ | 32 */ |
37 public RiverSelect() { | 33 public RiverSelect() { |
38 super(null, null); | |
39 } | 34 } |
40 | 35 |
41 | 36 |
42 /** | 37 /** |
43 * Initialize the state based on the state node in the configuration. | 38 * Initialize the state based on the state node in the configuration. |
47 public void setup(Node config) { | 42 public void setup(Node config) { |
48 super.setup(config); | 43 super.setup(config); |
49 } | 44 } |
50 | 45 |
51 | 46 |
52 /** | 47 protected Element createData( |
53 * This method creates the UI part of the artifact's describe document. The | 48 XMLUtils.ElementCreator cr, |
54 * ui part consists of a static - representing previous inserted data - and | 49 StateData data, |
55 * a dynamic part - representing data that is necessary to be inserted in | 50 CallContext context) |
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 */ | |
63 public void describe( | |
64 Document document, | |
65 Node root, | |
66 CallContext context, | |
67 String uuid) | |
68 { | 51 { |
69 XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( | 52 Element select = ProtocolUtils.createArtNode( |
70 document, | 53 cr, "select", |
71 ArtifactNamespaceContext.NAMESPACE_URI, | 54 new String[] { "uiprovider" }, |
72 ArtifactNamespaceContext.NAMESPACE_PREFIX); | 55 new String[] { "select_with_map" }); |
56 cr.addAttr(select, "name", data.getName()); | |
73 | 57 |
74 Element ui = ProtocolUtils.createArtNode( | 58 Element label = ProtocolUtils.createArtNode( |
75 creator, "ui", null, null); | 59 cr, "label", null, null); |
76 | 60 |
77 Element staticUI = ProtocolUtils.createArtNode( | 61 Element choices = ProtocolUtils.createArtNode( |
78 creator, "static", null, null); | 62 cr, "choices", null, null); |
79 | 63 |
80 // TODO Add the static data | 64 label.setTextContent(Resources.getMsg( |
81 logger.error("TODO: ADD STATIC DATA TO DESCRIBE DOCUMENT."); | 65 context.getMeta(), |
66 getID(), | |
67 getID())); | |
82 | 68 |
83 Element dynamicUI = ProtocolUtils.createArtNode( | 69 return select; |
84 creator, "dynamic", null, null); | 70 } |
85 | 71 |
86 Map<String, StateData> data = getData(); | |
87 | 72 |
88 if (data != null) { | 73 protected Element[] createItems( |
89 Collection<StateData> items = data.values(); | 74 XMLUtils.ElementCreator cr, |
75 String name, | |
76 CallContext context) | |
77 { | |
78 List<River> rivers = RiverFactory.getRivers(); | |
79 Element[] items = new Element[rivers.size()]; | |
90 | 80 |
91 for (StateData item: items) { | 81 int idx = 0; |
92 Element select = ProtocolUtils.createArtNode( | 82 for (River river: rivers) { |
93 creator, "select", | 83 items[idx++] = createRiverItem(cr, river); |
94 new String[] { "uiprovider" }, | |
95 new String[] { "select_with_map" }); | |
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 } | 84 } |
117 | 85 |
118 ui.appendChild(staticUI); | 86 return items; |
119 ui.appendChild(dynamicUI); | |
120 | |
121 root.appendChild(ui); | |
122 } | 87 } |
123 | 88 |
124 | 89 |
125 /** | 90 /** |
126 * This method creates a node that represents a river item. This node | 91 * This method creates a node that represents a river item. This node |