view gnv-artifacts/src/main/java/de/intevation/gnv/state/SwitchModeState.java @ 1050:7f3154331bc1

Use the chart size/height to export it to pdf. The chart's aspect ratio keeps alive if the size exceeds the maximum page size (issue290). gnv-artifacts/trunk@1124 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 25 May 2010 15:41:31 +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