Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/states/LoadSingleYearSelectState.java @ 9264:baef46792354
Explicitely checking for ld_step, in order to misuse this component (i.e. if there are additional data items)
author | gernotbelger |
---|---|
date | Tue, 17 Jul 2018 19:48:23 +0200 |
parents | af73fdd96920 |
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; import java.util.HashMap; import java.util.List; import java.util.Map; import org.apache.log4j.Logger; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallContext; import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; import org.dive4elements.river.artifacts.D4EArtifact; import org.dive4elements.river.artifacts.access.RiverAccess; import org.dive4elements.river.artifacts.model.CollisionHibernateFactory; import org.dive4elements.river.model.sinfo.Collision; import org.w3c.dom.Element; /** State in which to fetch years for sedminent load calculation. */ public class LoadSingleYearSelectState extends DefaultState { private static final long serialVersionUID = 1L; /** The log used in this class. */ private static Logger log = Logger.getLogger(LoadSingleYearSelectState.class); /** * The default constructor that initializes an empty State object. */ public LoadSingleYearSelectState() { } /** Year Select Widget. */ @Override protected String getUIProvider() { return "common.state.load_single_year_select"; } @Override protected void appendItems(final Artifact artifact, final ElementCreator creator, final String name, final CallContext context, final Element select) { final String dataKey = "singleyear"; try { if (dataKey.equals(name)) { final AddTableDataHelper helper = new AddTableDataHelper(creator, select, "year", context.getMeta()); // pinKeycolum; nicht zu verweschseln mit // datakey..artifact. helper.addColumn(0, "pinfrom", "60", "common.client.ui.selection", "ICON", "CENTER", "from"); helper.addColumn(1, "year", "60", "year", "INTEGER", "LEFT", null); final RiverAccess access = new RiverAccess((D4EArtifact) artifact); final List<Collision> collisions = CollisionHibernateFactory.getCollisionsByRiver(access.getRiver());// TODO: DATASOURCE?! Has to be // uinfo.inundation_duration // (Überflutungsdauern Aue) irgendwas... for (final Collision coll : collisions) { final Integer year = coll.getYear(); final Map<String, String> row = new HashMap<>(); row.put("year", year.toString()); // Nullpointer-Check? helper.addRow(row); } helper.submitMapToXml(); } } catch (final IllegalArgumentException iae) { iae.printStackTrace(); } } @Override public boolean validate(final Artifact artifact) throws IllegalArgumentException { return true; // final CollisionLoadYearEpochAccess access = new CollisionLoadYearEpochAccess((D4EArtifact) artifact); // // // Second year should be later than first. // if (access.getYears() == null || access.getYears().length == 0) // return true; // TODO: richtig in CollisionLoadYear... implementieren // // throw new IllegalArgumentException("error_years_wrong"); // // return true; } }