Mercurial > dive4elements > gnv-client
diff gnv-artifacts/src/main/java/de/intevation/gnv/state/SwitchModeState.java @ 1119:7c4f81f74c47
merged gnv-artifacts
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:00 +0200 |
parents | dec4257ad570 |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/SwitchModeState.java Fri Sep 28 12:14:00 2012 +0200 @@ -0,0 +1,136 @@ +/* + * Copyright (c) 2010 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ + +package de.intevation.gnv.state; + +import de.intevation.artifacts.common.utils.XMLUtils; + +import de.intevation.artifacts.CallContext; +import de.intevation.artifacts.CallMeta; +import de.intevation.artifacts.PreferredLocale; + +import de.intevation.gnv.artifacts.ressource.RessourceFactory; + +import org.apache.log4j.Logger; + +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; + + +/** + * This task of this <code>State</code> implementation is to switch between + * working with vector or scalar data. + * + * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> + */ +public class SwitchModeState extends StateBase { + + public static final String VECTOR_VALUE = "vector"; + public static final String SCALAR_VALUE = "scalar"; + + public static final String RESSOURCE_VECTOR = "vectorvalues"; + public static final String RESSOURCE_SCALAR = "scalarvalues"; + + private static Logger logger = Logger.getLogger(SwitchModeState.class); + + public SwitchModeState() { + } + + + @Override + protected void describeDynamic( + XMLUtils.ElementCreator artCreator, + XMLUtils.ElementCreator creator, + Document document, + Node dynamic, + CallContext context, + String uuid) + { + RessourceFactory ressource = RessourceFactory.getInstance(); + CallMeta callMeta = context.getMeta(); + PreferredLocale[] locales = callMeta.getLanguages(); + + Element selectNode = creator.create("select1"); + creator.addAttr(selectNode, "ref", dataName); + + Element labelNode = creator.create("label"); + labelNode.setTextContent(ressource.getRessource( + locales, dataName, dataName)); + selectNode.appendChild(labelNode); + + selectNode.appendChild(createChoices(creator, context)); + dynamic.appendChild(selectNode); + logger.debug("creating dynamic ui elements finished"); + } + + + protected Node createChoices( + XMLUtils.ElementCreator creator, + CallContext context) + { + RessourceFactory ressource = RessourceFactory.getInstance(); + CallMeta callMeta = context.getMeta(); + PreferredLocale[] locales = callMeta.getLanguages(); + + Element choiceNodes = creator.create("choices"); + + // add choice for scalar values + logger.debug("create choice for scalar values"); + Element scalar = creator.create("item"); + Element label = creator.create("label"); + label.setTextContent(ressource.getRessource( + locales, RESSOURCE_SCALAR, RESSOURCE_SCALAR)); + scalar.appendChild(label); + + Element value = creator.create("value"); + value.setTextContent(SCALAR_VALUE); + scalar.appendChild(value); + + // add choice for vector values + logger.debug("create choice for vector values"); + Element vector = creator.create("item"); + label = creator.create("label"); + label.setTextContent(ressource.getRessource( + locales, RESSOURCE_VECTOR, RESSOURCE_VECTOR)); + vector.appendChild(label); + + value = creator.create("value"); + value.setTextContent(VECTOR_VALUE); + vector.appendChild(value); + + choiceNodes.appendChild(scalar); + choiceNodes.appendChild(vector); + + return choiceNodes; + } + + + @Override + protected String[] getDescriptionForInputData( + InputData data, CallContext context, String uuid) + { + RessourceFactory ressource = RessourceFactory.getInstance(); + CallMeta callMeta = context.getMeta(); + PreferredLocale[] locales = callMeta.getLanguages(); + + String value = data.getValue(); + + if (value != null && value.equals(SCALAR_VALUE)) { + return new String[] { ressource.getRessource( + locales, RESSOURCE_SCALAR, RESSOURCE_SCALAR) }; + } + else if (value != null && value.equals(VECTOR_VALUE)) { + return new String[] { ressource.getRessource( + locales, RESSOURCE_VECTOR, RESSOURCE_VECTOR) }; + } + + return null; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :