Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/LoadSingleYearSelectState.java @ 9256:6c24c857ccf9
fixation refactoring and inputItem behaviour to interfaces
author | gernotbelger |
---|---|
date | Fri, 13 Jul 2018 12:04:21 +0200 |
parents | |
children |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/bundu/bezugswst/LoadSingleYearSelectState.java Fri Jul 13 12:04:21 2018 +0200 @@ -0,0 +1,89 @@ +/* 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.bundu.bezugswst; + +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.artifacts.states.AddTableDataHelper; +import org.dive4elements.river.artifacts.states.DefaultState; +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.show_hint"; + } + + @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; + } +} \ No newline at end of file