view flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DGMSelect.java @ 1873:841af55d5e53

Added new WMSFixpointsArtifact for displaying fixpoints in maps. flys-artifacts/trunk@3227 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Thu, 10 Nov 2011 14:25:56 +0000
parents 8a2cbf947395
children 9d5f339d83a3
line wrap: on
line source
package de.intevation.flys.artifacts.states;

import java.io.File;

import org.w3c.dom.Element;

import org.apache.log4j.Logger;

import de.intevation.artifacts.CallContext;

import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;

import de.intevation.flys.artifacts.FLYSArtifact;
import de.intevation.flys.model.DGM;


/**
 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a>
 */
public class DGMSelect extends DefaultState {

    private static final Logger logger = Logger.getLogger(DGMSelect.class);


    @Override
    protected String getUIProvider() {
        return "dgm_datacage_panel";
    }


    @Override
    protected Element createStaticData(
        FLYSArtifact   flys,
        ElementCreator creator,
        CallContext    cc,
        String         name,
        String         value,
        String         type
    ) {
        Element dataElement = creator.create("data");
        creator.addAttr(dataElement, "name", name, true);
        creator.addAttr(dataElement, "type", type, true);

        Element itemElement = creator.create("item");
        creator.addAttr(itemElement, "value", value, true);

        creator.addAttr(itemElement, "label", getLabel(cc, value), true);
        dataElement.appendChild(itemElement);

        return dataElement;
    }


    public static String getLabel(CallContext cc, String value) {
        logger.debug("Create label for value: " + value);

        try {
            DGM dgm = DGM.getDGM(Integer.parseInt(value));

            File file = new File(dgm.getPath());
            return file.getName();
        }
        catch (NumberFormatException nfe) {
            logger.warn("Cannot parse int value: '" + value + "'");
        }

        return "";
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org