ingo@109: package de.intevation.flys.artifacts.states; ingo@109: ingo@115: import java.util.List; ingo@115: ingo@109: import org.apache.log4j.Logger; ingo@109: ingo@115: import org.w3c.dom.Element; ingo@109: import org.w3c.dom.Node; ingo@109: ingo@109: import de.intevation.artifacts.CallContext; ingo@109: ingo@115: import de.intevation.artifacts.common.utils.XMLUtils; ingo@115: ingo@115: import de.intevation.artifactdatabase.ProtocolUtils; ingo@115: import de.intevation.artifactdatabase.data.StateData; ingo@109: sascha@132: import de.intevation.flys.model.River; sascha@132: ingo@115: import de.intevation.flys.artifacts.model.RiverFactory; sascha@132: ingo@126: import de.intevation.flys.artifacts.resources.Resources; ingo@115: ingo@109: ingo@109: /** ingo@109: * @author Ingo Weinzierl ingo@109: */ ingo@126: public class RiverSelect extends DefaultState { ingo@109: ingo@109: /** The logger used in this class. */ ingo@109: private static Logger logger = Logger.getLogger(RiverSelect.class); ingo@109: ingo@109: /** ingo@109: * The default constructor that initializes an empty State object. ingo@109: */ ingo@109: public RiverSelect() { ingo@109: } ingo@109: ingo@109: ingo@109: /** ingo@109: * Initialize the state based on the state node in the configuration. ingo@109: * ingo@109: * @param config The state configuration node. ingo@109: */ ingo@109: public void setup(Node config) { ingo@109: super.setup(config); ingo@109: } ingo@109: ingo@109: ingo@126: protected Element createData( ingo@126: XMLUtils.ElementCreator cr, ingo@126: StateData data, ingo@126: CallContext context) ingo@109: { ingo@126: Element select = ProtocolUtils.createArtNode( ingo@126: cr, "select", ingo@126: new String[] { "uiprovider" }, ingo@126: new String[] { "select_with_map" }); ingo@126: cr.addAttr(select, "name", data.getName()); ingo@115: ingo@126: Element label = ProtocolUtils.createArtNode( ingo@126: cr, "label", null, null); ingo@115: ingo@126: Element choices = ProtocolUtils.createArtNode( ingo@126: cr, "choices", null, null); ingo@115: ingo@126: label.setTextContent(Resources.getMsg( ingo@126: context.getMeta(), ingo@126: getID(), ingo@126: getID())); ingo@115: ingo@126: return select; ingo@126: } ingo@115: ingo@126: ingo@126: protected Element[] createItems( ingo@126: XMLUtils.ElementCreator cr, ingo@126: String name, ingo@126: CallContext context) ingo@126: { ingo@126: List rivers = RiverFactory.getRivers(); ingo@126: Element[] items = new Element[rivers.size()]; ingo@126: ingo@126: int idx = 0; ingo@126: for (River river: rivers) { ingo@126: items[idx++] = createRiverItem(cr, river); ingo@115: } ingo@115: ingo@126: return items; ingo@115: } ingo@115: ingo@115: ingo@115: /** ingo@115: * This method creates a node that represents a river item. This node ingo@115: * contains the label and the value that describe the river. ingo@115: * ingo@115: * @param cr The ElementCreator. ingo@115: * @param river The river. ingo@115: * ingo@115: * @return the element that contains the information about the river. ingo@115: */ ingo@115: protected Element createRiverItem(XMLUtils.ElementCreator cr, River river) { ingo@115: Element item = ProtocolUtils.createArtNode(cr, "item", null, null); ingo@115: Element label = ProtocolUtils.createArtNode(cr, "label", null, null); ingo@115: Element value = ProtocolUtils.createArtNode(cr, "value", null, null); ingo@115: ingo@115: label.setTextContent(river.getName()); ingo@115: value.setTextContent(river.getName()); ingo@115: ingo@115: item.appendChild(label); ingo@115: item.appendChild(value); ingo@115: ingo@115: return item; ingo@109: } ingo@109: } ingo@109: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :