view artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/salix/LoadScenarioSelectLimit5.java @ 9321:a978b601a034

Salix: Fixed ArrrayoutOfBoundsException; minor cleanup
author gernotbelger
date Fri, 27 Jul 2018 10:25:09 +0200
parents 1b2623dff742
children 3b188c34d422
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.uinfo.salix;

import java.util.HashMap;
import java.util.Map;

import org.dive4elements.artifactdatabase.data.StateData;
import org.dive4elements.artifacts.Artifact;
import org.dive4elements.artifacts.CallContext;
import org.dive4elements.artifacts.common.utils.XMLUtils;
import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator;
import org.dive4elements.river.artifacts.states.AddTableDataHelper;
import org.dive4elements.river.artifacts.states.DefaultState;
import org.w3c.dom.Element;

/** State in which to fetch years for sedminent load calculation. */
public class LoadScenarioSelectLimit5 extends DefaultState {

    private static final long serialVersionUID = 1L;

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

    /** Year Select Widget. */
    @Override
    protected String getUIProvider() {
        return "uinfo.sedimentheight_select.limit5";
    }

    @Override
    protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) {

        // the client is expecting helper input. bad abstraction. the table does not appear, only because no columns are added.
        // TODO Implement abstraction without helper on client side and then delete this method
        final String datakey = "sedimentheight";
        try {
            if (datakey.equals(name)) {

                final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "cm", context.getMeta());
                for (int i = -200; i < -100; i = i + 10) {
                    final Map<String, String> row = new HashMap<>();
                    row.put("cm", Integer.toString(i));
                    helper.addRow(row);
                }
                helper.submitMapToXml();
            }
        }
        catch (final IllegalArgumentException iae) {
            iae.printStackTrace();
        }
    }

    @Override
    protected Element createData(final XMLUtils.ElementCreator cr, final Artifact artifact, final StateData data, final CallContext context) {
        return ScenarioTypeState.changeHeaderForCurrentState("state.uinfo.inundation.scenario.regional", data.getName(), cr, context);
    }
}

http://dive4elements.wald.intevation.org