Mercurial > dive4elements > river
view artifacts/src/main/java/org/dive4elements/river/artifacts/states/RadioSelect.java @ 9184:dace17e26d33
code review uinfo.inundationduration
author | gernotbelger |
---|---|
date | Wed, 27 Jun 2018 14:07:02 +0200 |
parents | 2f5052835b76 |
children | c7e5285d434f |
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; public RadioSelect() { } protected abstract LinkedHashMap<String, String> makeEntries(CallMeta meta, Artifact artifact); // AUSNAHMSWEISE EXPLIZITER TYP, damit Reihenfolge nicht // verrutscht @Override protected final String getUIProvider() { return "radio_panel"; } @Override protected Element[] createItems(final XMLUtils.ElementCreator ec, final Artifact artifact, final String name, final CallContext context) { // REMEBER: we need it for getLabelFor later 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; } @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); } }