Mercurial > dive4elements > river
changeset 134:f3dfa188d8b2
Let the states describe the static ui part.
flys-artifacts/trunk@1502 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Thu, 17 Mar 2011 16:03:36 +0000 |
parents | d6197a05a87c |
children | 2d6e02787d00 |
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/DefaultState.java |
diffstat | 3 files changed, 73 insertions(+), 33 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Mar 17 12:17:37 2011 +0000 +++ b/flys-artifacts/ChangeLog Thu Mar 17 16:03:36 2011 +0000 @@ -1,3 +1,14 @@ +2011-03-17 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java: + The static UI part is created by the previous states now. This makes it + possible to group the data objects (which is necessary to group the + objects in the ui). + + * src/main/java/de/intevation/flys/artifacts/states/DefaultState.java: + Added a describeStatic() method that creates a node that contains the + data of that state. + 2011-03-17 Ingo Weinzierl <ingo@intevation.de> * src/main/java/de/intevation/flys/artifacts/services/RiverService.java:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Thu Mar 17 12:17:37 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/WINFOArtifact.java Thu Mar 17 16:03:36 2011 +0000 @@ -1,9 +1,7 @@ package de.intevation.flys.artifacts; import java.util.List; -import java.util.Set; - -import javax.xml.xpath.XPathConstants; +import java.util.Vector; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -15,15 +13,14 @@ import de.intevation.artifacts.CallContext; import de.intevation.artifactdatabase.ProtocolUtils; -import de.intevation.artifactdatabase.data.StateData; import de.intevation.artifactdatabase.state.State; import de.intevation.artifactdatabase.state.StateEngine; import de.intevation.artifactdatabase.transition.TransitionEngine; import de.intevation.artifacts.common.utils.XMLUtils; +import de.intevation.flys.artifacts.states.DefaultState; import de.intevation.flys.artifacts.context.FLYSContext; -import de.intevation.flys.artifacts.resources.Resources; /** @@ -100,7 +97,7 @@ Element staticUI = ProtocolUtils.createArtNode( creator, "static", null, null); - appendStaticUI(creator, staticUI, context); + appendStaticUI(description, staticUI, context, identifier()); Element dynamic = current.describe( description, @@ -130,39 +127,29 @@ * This method appends the static data - that has already been inserted by * the user - to the static node of the DESCRIBE document. * - * @param cr The ElementCreator that is used to create new elements. - * @param ui The static ui node. + * @param doc The document. + * @param ui The root node. + * @param context The CallContext. + * @param uuid The identifier of the artifact. */ protected void appendStaticUI( - XMLUtils.ElementCreator cr, - Node ui, - CallContext context) + Document doc, + Node ui, + CallContext context, + String uuid) { - Set<String> keys = data.keySet(); + Vector<String> stateIds = getPreviousStateIds(); - // XXX This just handles single selection string values. If we need more - // complex (maybe multiselect) objects we should introduce a data - // structure for this - this structure should have a method that returns - // a <data> node that contains its items. - for (String k: keys) { - logger.debug("The key = " + k); - StateData d = getData(k); - String name = Resources.getMsg( - context.getMeta(), - d.getName(), - d.getName()); + FLYSContext flysContext = getFlysContext(context); + StateEngine engine = (StateEngine) flysContext.get( + FLYSContext.STATE_ENGINE_KEY); - Element dataElement = cr.create("data"); - cr.addAttr(dataElement, "name", name, true); - cr.addAttr(dataElement, "type", d.getType(), true); + for (String stateId: stateIds) { + logger.debug("Append static data for state: " + stateId); + DefaultState state = (DefaultState) engine.getState(stateId); + ui.appendChild(state.describeStatic(doc, ui, context, uuid)); + } - Element itemElement = cr.create("item"); - cr.addAttr(itemElement, "value", (String) d.getValue(), true); - // TODO Description (human readable) is missing - - dataElement.appendChild(itemElement); - ui.appendChild(dataElement); - } } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java Thu Mar 17 12:17:37 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DefaultState.java Thu Mar 17 16:03:36 2011 +0000 @@ -30,6 +30,48 @@ private static Logger logger = Logger.getLogger(DefaultState.class); + public Element describeStatic( + Document document, + Node root, + CallContext context, + String uuid) + { + XMLUtils.ElementCreator creator = new XMLUtils.ElementCreator( + document, + ArtifactNamespaceContext.NAMESPACE_URI, + ArtifactNamespaceContext.NAMESPACE_PREFIX); + + Element ui = ProtocolUtils.createArtNode( + creator, "state", + new String[] { "name" }, + new String[] { getID() }); + + Map<String, StateData> theData = getData(); + if (theData == null) { + return ui; + } + + Collection<StateData> dataItems = theData.values(); + + for (StateData data: dataItems) { + String name = data.getName(); + + Element dataElement = creator.create("data"); + creator.addAttr(dataElement, "name", name, true); + creator.addAttr(dataElement, "type", data.getType(), true); + + Element itemElement = creator.create("item"); + creator.addAttr(itemElement, "value", (String) data.getValue(), true); + // TODO Description (human readable) is missing + + dataElement.appendChild(itemElement); + ui.appendChild(dataElement); + } + + return ui; + } + + public Element describe( Document document, Node root,