view artifacts/src/main/java/org/dive4elements/river/artifacts/states/fixation/EventSelect.java @ 9415:9744ce3c3853

Rework of fixanalysis computation and dWt and WQ facets. Got rid of strange remapping and bitshifting code by explicitely saving the column information and using it in the facets. The facets also put the valid station range into their xml-metadata
author gernotbelger
date Thu, 16 Aug 2018 16:27:53 +0200
parents c7e5285d434f
children
line wrap: on
line source
/* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde
 * Software engineering by Intevation GmbH
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */

package org.dive4elements.river.artifacts.states.fixation;

import java.util.List;

import org.apache.log4j.Logger;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
import org.dive4elements.river.artifacts.D4EArtifact;
import org.dive4elements.river.artifacts.model.fixings.FixingColumn;
import org.dive4elements.river.artifacts.model.fixings.FixingsOverview;
import org.dive4elements.river.artifacts.model.fixings.FixingsOverviewFactory;
import org.dive4elements.river.artifacts.model.fixings.FixingsOverview.IdFilter;
import org.dive4elements.river.artifacts.states.DefaultState;
import org.dive4elements.river.utils.RiverUtils;
import org.w3c.dom.Element;

/**
 * @author <a href="mailto:raimund.renkert@intevation.de">Raimund Renkert</a>
 */
public class EventSelect extends DefaultState {

    /** The log used in this class. */
    private static Logger log = Logger.getLogger(EventSelect.class);

    /**
     * The default constructor that initializes an empty State object.
     */
    public EventSelect() {
    }

    @Override
    protected String getUIProvider() {
        return "fix.event_panel";
    }

    @Override
    protected Element createStaticData(final D4EArtifact flys, final ElementCreator creator, final CallContext cc, final String name, final String value,
            final String type) {
        return this.createStaticDataPublic(flys, creator, cc, name, value, type);
    }

    public final static Element createStaticDataPublic(final D4EArtifact flys, final ElementCreator creator, final CallContext cc, final String name,
            final String value, final String type) {
        final int[] array = RiverUtils.intArrayFromString(value);

        final Element dataElement = creator.create("data");
        creator.addAttr(dataElement, "name", name, true);
        creator.addAttr(dataElement, "type", type, true);

        final String river = RiverUtils.getRiver(flys).getName();

        final FixingsOverview overview = FixingsOverviewFactory.getOverview(river);

        for (final int element : array) {
            final Element itemElement = creator.create("item");
            creator.addAttr(itemElement, "value", String.valueOf(element), true);

            creator.addAttr(itemElement, "label", getLabelForEvent(cc, element, overview), true);
            dataElement.appendChild(itemElement);
        }
        return dataElement;
    }

    private static final String getLabelForEvent(final CallContext cc, final int value, final FixingsOverview overview) {
        log.debug("Create label for value: " + value);

        final IdFilter filter = new IdFilter(value);
        final List<FixingColumn> columns = overview.filter(null, filter);
        return columns.isEmpty() ? "" : columns.get(0).getDescription();
    }
}
// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :

http://dive4elements.wald.intevation.org