view gnv-artifacts/src/main/java/de/intevation/gnv/state/SwitchModeState.java @ 1068:a4e490e0af5b

Enable GetFeatureInforRequests on all layer gnv-artifacts/trunk@1163 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Tim Englich <tim.englich@intevation.de>
date Mon, 07 Jun 2010 12:17:57 +0000
parents 9981452c7e75
children f953c9a559d8
line wrap: on
line source
package de.intevation.gnv.state;

import de.intevation.artifactdatabase.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 :

http://dive4elements.wald.intevation.org