Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/states/RadioSelect.java @ 9648:c5a496bf1b0b
Fixed: Duplizieren einer Fixierungsanalyse schlägt fehl.
author | Gernot Belger <g.belger@bjoernsen.de> |
---|---|
date | Wed, 04 Dec 2019 16:10:28 +0100 |
parents | 1a4d2ce77423 |
children |
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde * Software engineering by * Björnsen Beratende Ingenieure GmbH * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt * * 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.LinkedHashMap; import java.util.Map; import org.dive4elements.artifacts.Artifact; import org.dive4elements.artifacts.CallContext; import org.dive4elements.artifacts.CallMeta; import org.dive4elements.artifacts.common.utils.XMLUtils; import org.dive4elements.river.artifacts.resources.Resources; import org.w3c.dom.Element; /** * @author Domenico Nardi Tironi * */ public abstract class RadioSelect extends DefaultState { private static final long serialVersionUID = 1L; private Artifact artifact; protected abstract String getDatakey(); @Override protected abstract String getUIProvider(); // force override in subs! // { // return "radio_panel"; //no generic radiopanel // } protected abstract LinkedHashMap<String, String> makeEntries(CallMeta meta, Artifact artifact); // AUSNAHMSWEISE EXPLIZITER TYP, damit Reihenfolge nicht // verrutscht @Override protected Element[] createItems(final XMLUtils.ElementCreator ec, final Artifact artifact, final String name, final CallContext context) { // REMEBER: we need it for getLabelFor later if (name.equals(getDatakey())) { this.artifact = artifact; final CallMeta meta = context.getMeta(); final Map<String, String> entries = makeEntries(meta, artifact); final Element[] elements = new Element[entries.size()]; int i = 0; for (final String key : entries.keySet()) { final String label = entries.get(key); final String labelToSet = label != null ? label : Resources.getMsg(meta, key); elements[i] = createItem(ec, new String[] { labelToSet, key }); i++; } return elements; } return super.createItems(ec, artifact, name, context); } @Override protected String getLabelFor(final CallContext cc, final String name, final String value, final String type) { // artifacts must be set in "createItems" -> createItems has to be called first final Map<String, String> entries = makeEntries(cc.getMeta(), this.artifact); final String valueToSet = entries.get(value) != null ? entries.get(value) : value; return super.getLabelFor(cc, name, valueToSet, type); } }