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; ingo@927: ingo@927: import org.w3c.dom.Element; ingo@927: ingo@2579: import org.apache.log4j.Logger; ingo@2579: teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.CallContext; teichmann@5831: import org.dive4elements.artifacts.CallMeta; ingo@927: teichmann@5831: import org.dive4elements.artifacts.common.utils.XMLUtils; ingo@927: teichmann@5831: import org.dive4elements.artifactdatabase.ProtocolUtils; ingo@927: teichmann@5831: import org.dive4elements.river.artifacts.resources.Resources; ingo@927: ingo@927: ingo@927: /** ingo@927: * @author Ingo Weinzierl ingo@927: */ ingo@927: public class FloodplainChoice extends DefaultState { ingo@927: ingo@2579: public static final String OPTION = "floodplain.option"; ingo@2579: public static final String ACTIVE = "floodplain.active"; ingo@2579: public static final String INACTIVE = "floodplain.inactive"; ingo@2579: teichmann@8202: private static final Logger log = ingo@2579: Logger.getLogger(FloodplainChoice.class); ingo@927: ingo@927: ingo@927: @Override ingo@927: protected String getUIProvider() { ingo@927: return "boolean_panel"; ingo@927: } ingo@927: ingo@927: ingo@927: @Override ingo@927: protected Element[] createItems( ingo@927: XMLUtils.ElementCreator cr, ingo@927: Artifact artifact, ingo@927: String name, ingo@927: CallContext context) ingo@927: { ingo@927: CallMeta meta = context.getMeta(); ingo@927: ingo@927: Element option = createItem( ingo@927: cr, ingo@927: new String[] { Resources.getMsg(meta, OPTION, OPTION), "true" }); ingo@927: ingo@927: return new Element[] { option }; ingo@927: } ingo@927: ingo@927: ingo@2579: @Override ingo@2579: protected String getLabelFor( ingo@2579: CallContext cc, ingo@2579: String name, ingo@2579: String value, ingo@2579: String type ingo@2579: ) { teichmann@8202: log.debug("GET LABEL FOR '" + name + "' / '" + value + "'"); ingo@2579: if (value != null && value.equals("true")) { ingo@2579: return Resources.getMsg(cc.getMeta(), ACTIVE, ACTIVE); ingo@2579: } ingo@2579: else { ingo@2579: return Resources.getMsg(cc.getMeta(), INACTIVE, INACTIVE); ingo@2579: } ingo@2579: } ingo@2579: ingo@2579: ingo@927: protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { ingo@927: Element item = ProtocolUtils.createArtNode(cr, "item", null, null); ingo@927: Element label = ProtocolUtils.createArtNode(cr, "label", null, null); ingo@927: Element value = ProtocolUtils.createArtNode(cr, "value", null, null); ingo@927: ingo@927: String[] arr = (String[]) obj; ingo@927: ingo@927: label.setTextContent(arr[0]); ingo@927: value.setTextContent(arr[1]); ingo@927: ingo@927: item.appendChild(label); ingo@927: item.appendChild(value); ingo@927: ingo@927: return item; ingo@927: } ingo@927: } ingo@927: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :