teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.states.fixation; raimund@2668: raimund@2719: import java.util.List; raimund@2719: raimund@2668: import org.apache.log4j.Logger; raimund@2668: raimund@2719: import org.w3c.dom.Element; raimund@2719: teichmann@5831: import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; raimund@2719: teichmann@5831: import org.dive4elements.artifacts.CallContext; raimund@2719: teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState; teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@5865: import org.dive4elements.river.utils.RiverUtils; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.model.FixingsOverview; teichmann@5831: import org.dive4elements.river.artifacts.model.FixingsOverviewFactory; teichmann@5831: import org.dive4elements.river.artifacts.model.FixingsOverview.IdFilter; teichmann@5831: import org.dive4elements.river.artifacts.model.FixingsOverview.Fixing; raimund@2719: raimund@2668: raimund@2668: /** raimund@2668: * @author Raimund Renkert raimund@2668: */ raimund@2668: public class EventSelect extends DefaultState { raimund@2668: raimund@2668: /** The logger used in this class. */ raimund@2668: private static Logger logger = Logger.getLogger(EventSelect.class); raimund@2668: raimund@2668: raimund@2668: /** raimund@2668: * The default constructor that initializes an empty State object. raimund@2668: */ raimund@2668: public EventSelect() { raimund@2668: } raimund@2668: raimund@2668: @Override raimund@2668: protected String getUIProvider() { raimund@2668: return "fix.event_panel"; raimund@2668: } raimund@2719: raimund@2719: @Override raimund@2719: protected Element createStaticData( teichmann@5867: D4EArtifact flys, raimund@2719: ElementCreator creator, raimund@2719: CallContext cc, raimund@2719: String name, raimund@2719: String value, raimund@2719: String type raimund@2719: ) { teichmann@5865: int[] array = RiverUtils.intArrayFromString(value); raimund@2719: raimund@2719: Element dataElement = creator.create("data"); raimund@2719: creator.addAttr(dataElement, "name", name, true); raimund@2719: creator.addAttr(dataElement, "type", type, true); raimund@2719: teichmann@5865: String river = RiverUtils.getRiver(flys).getName(); raimund@2719: raimund@2719: FixingsOverview overview = FixingsOverviewFactory.getOverview(river); raimund@2719: raimund@2719: for (int i = 0; i < array.length; i++) { raimund@2719: Element itemElement = creator.create("item"); raimund@2719: creator.addAttr( raimund@2719: itemElement, raimund@2719: "value", raimund@2719: String.valueOf(array[i]), raimund@2719: true); raimund@2719: raimund@2719: creator.addAttr( raimund@2719: itemElement, raimund@2719: "label", raimund@2719: getLabel(cc, array[i], overview), raimund@2719: true); raimund@2719: dataElement.appendChild(itemElement); raimund@2719: } raimund@2719: return dataElement; raimund@2719: } raimund@2719: raimund@2719: raimund@2719: public static String getLabel( raimund@2719: CallContext cc, raimund@2719: int value, raimund@2719: FixingsOverview overview raimund@2719: ) { raimund@2719: logger.debug("Create label for value: " + value); raimund@2719: raimund@2719: IdFilter filter = new IdFilter(value); raimund@2719: List columns = overview.filter(null, filter); teichmann@4051: return columns.isEmpty() teichmann@4051: ? "" teichmann@4051: : columns.get(0).getDescription(); raimund@2719: } raimund@2668: } raimund@2668: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :