Mercurial > dive4elements > river
changeset 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 | 394b9580ceae |
children | 47a4bc7a9ddf |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java |
diffstat | 3 files changed, 115 insertions(+), 5 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Tue Feb 08 09:02:18 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Feb 08 09:11:25 2011 +0000 @@ -1,3 +1,14 @@ +2011-02-08 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: The + RiverSelect state is called to create the UI part of the describe + document. + + * src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java: + Implemented the dynamic UI part of describe(). The static part is not + inserted into the describe document at the moment. We need a reference to + the previous states for this. + 2011-02-08 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/model/RiverFactory.java,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Feb 08 09:02:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Tue Feb 08 09:11:25 2011 +0000 @@ -124,13 +124,13 @@ ArtifactNamespaceContext.NAMESPACE_PREFIX); Element root = ProtocolUtils.createRootNode(creator); + description.appendChild(root); + ProtocolUtils.appendDescribeHeader(creator, root, identifier(), hash()); ProtocolUtils.appendState(creator, root, currentState); ProtocolUtils.appendReachableStates(creator, root, reachable); - logger.warn("TODO: Implement the model and ui description!"); - description.appendChild(root); - + currentState.describe(description, root, context, identifier()); return description; }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java Tue Feb 08 09:02:18 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/RiverSelect.java Tue Feb 08 09:11:25 2011 +0000 @@ -1,14 +1,27 @@ package de.intevation.flys.artifacts.states; +import java.util.Collection; +import java.util.List; +import java.util.Map; + import org.apache.log4j.Logger; import org.w3c.dom.Document; +import org.w3c.dom.Element; import org.w3c.dom.Node; import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.ArtifactNamespaceContext; +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifactdatabase.ProtocolUtils; +import de.intevation.artifactdatabase.data.StateData; import de.intevation.artifactdatabase.state.AbstractState; +import de.intevation.flys.artifacts.model.River; +import de.intevation.flys.artifacts.model.RiverFactory; + /** * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> @@ -36,14 +49,100 @@ } + /** + * This method creates the UI part of the artifact's describe document. The + * ui part consists of a static - representing previous inserted data - and + * a dynamic part - representing data that is necessary to be inserted in + * the current state. + * + * @param document The describe document. + * @param root The root node of the describe document. + * @param context The CallContext. + * @param uuid The uuid of the artifact. + */ public void describe( Document document, Node root, CallContext context, String uuid) { - // TODO Implement me - logger.error("Currently not implemented."); + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element ui = ProtocolUtils.createArtNode( + creator, "ui", null, null); + + Element staticUI = ProtocolUtils.createArtNode( + creator, "static", null, null); + + // TODO Add the static data + logger.error("TODO: ADD STATIC DATA TO DESCRIBE DOCUMENT."); + + Element dynamicUI = ProtocolUtils.createArtNode( + creator, "dynamic", null, null); + + Map<String, StateData> data = getData(); + + if (data != null) { + Collection<StateData> items = data.values(); + + for (StateData item: items) { + Element select = ProtocolUtils.createArtNode( + creator, "select", + new String[] { "special" }, + new String[] { "river" }); + + Element label = ProtocolUtils.createArtNode( + creator, "label", null, null); + + Element choices = ProtocolUtils.createArtNode( + creator, "choices", null, null); + + label.setTextContent("River"); + + select.appendChild(label); + select.appendChild(choices); + + List<River> rivers = RiverFactory.getRivers(); + + for (River river: rivers) { + choices.appendChild(createRiverItem(creator, river)); + } + + dynamicUI.appendChild(select); + } + } + + ui.appendChild(staticUI); + ui.appendChild(dynamicUI); + + root.appendChild(ui); + } + + + /** + * This method creates a node that represents a river item. This node + * contains the label and the value that describe the river. + * + * @param cr The ElementCreator. + * @param river The river. + * + * @return the element that contains the information about the river. + */ + protected Element createRiverItem(XMLUtils.ElementCreator cr, River river) { + Element item = ProtocolUtils.createArtNode(cr, "item", null, null); + Element label = ProtocolUtils.createArtNode(cr, "label", null, null); + Element value = ProtocolUtils.createArtNode(cr, "value", null, null); + + label.setTextContent(river.getName()); + value.setTextContent(river.getName()); + + item.appendChild(label); + item.appendChild(value); + + return item; } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :