ingo@137: package de.intevation.flys.artifacts.states; ingo@137: ingo@137: import org.apache.log4j.Logger; ingo@137: ingo@137: import org.w3c.dom.Element; ingo@137: ingo@313: import de.intevation.artifacts.Artifact; ingo@137: import de.intevation.artifacts.CallContext; ingo@137: ingo@137: import de.intevation.artifacts.common.utils.XMLUtils; ingo@137: ingo@137: import de.intevation.artifactdatabase.ProtocolUtils; ingo@137: import de.intevation.artifactdatabase.data.StateData; ingo@137: ingo@319: import de.intevation.flys.model.Gauge; ingo@319: import de.intevation.flys.model.River; ingo@319: import de.intevation.flys.model.Wst; ingo@319: ingo@319: import de.intevation.flys.artifacts.FLYSArtifact; ingo@319: import de.intevation.flys.artifacts.model.WstFactory; ingo@137: import de.intevation.flys.artifacts.resources.Resources; ingo@137: ingo@137: /** ingo@137: * @author Ingo Weinzierl ingo@137: */ ingo@137: public class WQSelect extends DefaultState { ingo@137: ingo@137: /** The logger used in this class.*/ ingo@137: private static Logger logger = Logger.getLogger(WQSelect.class); ingo@137: ingo@137: ingo@137: /** The default step width for Qs.*/ ingo@137: public static final String DEFAULT_STEP_Q = "50"; ingo@137: ingo@137: /** The default step width for Qs.*/ ingo@137: public static final String DEFAULT_STEP_W = "30"; ingo@137: ingo@137: /** ingo@137: * The default constructor that initializes an empty State object. ingo@137: */ ingo@137: public WQSelect() { ingo@137: } ingo@137: ingo@137: protected Element createData( ingo@137: XMLUtils.ElementCreator cr, ingo@313: Artifact artifact, ingo@137: StateData data, ingo@137: CallContext context) ingo@137: { ingo@137: Element select = ProtocolUtils.createArtNode( ingo@137: cr, "select", null, null); ingo@137: ingo@137: cr.addAttr(select, "name", data.getName(), true); ingo@137: ingo@137: Element label = ProtocolUtils.createArtNode( ingo@137: cr, "label", null, null); ingo@137: ingo@137: Element choices = ProtocolUtils.createArtNode( ingo@137: cr, "choices", null, null); ingo@137: ingo@137: label.setTextContent(Resources.getMsg( ingo@137: context.getMeta(), ingo@137: data.getName(), ingo@137: data.getName())); ingo@137: ingo@137: select.appendChild(label); ingo@137: ingo@137: return select; ingo@137: } ingo@137: ingo@137: ingo@137: protected Element[] createItems( ingo@137: XMLUtils.ElementCreator cr, ingo@313: Artifact artifact, ingo@137: String name, ingo@137: CallContext context) ingo@137: { ingo@137: // TODO Insert correct min/max values! ingo@319: double[] minmaxW = determineMinMaxW(artifact); ingo@319: double[] minmaxQ = determineMinMaxQ(artifact); ingo@137: ingo@137: if (name.equals("wq_from")) { ingo@319: Element minW = createItem( ingo@319: cr, new String[] {"minW", new Double(minmaxW[0]).toString()}); ingo@319: Element minQ = createItem( ingo@319: cr, new String[] {"minQ", new Double(minmaxQ[0]).toString()}); ingo@137: return new Element[] { minW, minQ }; ingo@137: } ingo@137: else if (name.equals("wq_to")) { ingo@319: Element maxW = createItem( ingo@319: cr, new String[] {"maxW", new Double(minmaxW[1]).toString()}); ingo@319: Element maxQ = createItem( ingo@319: cr, new String[] {"maxQ", new Double(minmaxQ[1]).toString()}); ingo@137: return new Element[] { maxW, maxQ }; ingo@137: } ingo@137: else { ingo@137: Element stepW = createItem(cr, new String[] {"stepW", DEFAULT_STEP_W}); ingo@137: Element stepQ = createItem(cr, new String[] {"stepQ", DEFAULT_STEP_Q}); ingo@137: return new Element[] { stepW, stepQ }; ingo@137: } ingo@137: } ingo@137: ingo@137: ingo@137: protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { ingo@137: Element item = ProtocolUtils.createArtNode(cr, "item", null, null); ingo@137: Element label = ProtocolUtils.createArtNode(cr, "label", null, null); ingo@137: Element value = ProtocolUtils.createArtNode(cr, "value", null, null); ingo@137: ingo@137: String[] arr = (String[]) obj; ingo@137: ingo@137: label.setTextContent(arr[0]); ingo@137: value.setTextContent(arr[1]); ingo@137: ingo@137: item.appendChild(label); ingo@137: item.appendChild(value); ingo@137: ingo@137: return item; ingo@137: } ingo@137: ingo@137: ingo@137: protected String getUIProvider() { ingo@137: return "wq_panel"; ingo@137: } ingo@319: ingo@319: ingo@319: /** ingo@319: * Determines the min and max W value for the current gauge. If no min and ingo@319: * max values could be determined, this method will return ingo@319: * [Double.MIN_VALUE, Double.MAX_VALUE]. ingo@319: * ingo@319: * @param artifact The FLYSArtifact. ingo@319: * ingo@319: * @return the min and max W values for the current gauge. ingo@319: */ ingo@319: protected double[] determineMinMaxW(Artifact artifact) { ingo@319: logger.debug("WQSelect.determineCurrentGauge"); ingo@319: ingo@319: Gauge gauge = ((FLYSArtifact) artifact).getGauge(); ingo@319: double[] minmaxW = gauge.determineMinMaxW(); ingo@319: ingo@319: double minW = minmaxW != null ? minmaxW[0] : Double.MIN_VALUE; ingo@319: double maxW = minmaxW != null ? minmaxW[1] : Double.MAX_VALUE; ingo@319: ingo@319: return new double[] { minW, maxW }; ingo@319: } ingo@319: ingo@319: ingo@319: /** ingo@319: * Determines the min and max Q value for the current gauge. If no min and ingo@319: * max values could be determined, this method will return ingo@319: * [Double.MIN_VALUE, Double.MAX_VALUE]. ingo@319: * ingo@319: * @param artifact The FLYSArtifact. ingo@319: * ingo@319: * @return the min and max Q values for the current gauge. ingo@319: */ ingo@319: protected double[] determineMinMaxQ(Artifact artifact) { ingo@319: logger.debug("WQSelect.determineMinMaxQ"); ingo@319: ingo@319: FLYSArtifact flysArtifact = (FLYSArtifact) artifact; ingo@319: ingo@319: River river = flysArtifact.getRiver(); ingo@319: Gauge gauge = flysArtifact.getGauge(); ingo@319: Wst wst = WstFactory.getWst(river); ingo@319: ingo@319: double[] minmaxQ = wst.determineMinMaxQ(gauge.getRange()); ingo@319: ingo@319: double minQ = minmaxQ != null ? minmaxQ[0] : Double.MIN_VALUE; ingo@319: double maxQ = minmaxQ != null ? minmaxQ[1] : Double.MAX_VALUE; ingo@319: ingo@319: return new double[] { minQ, maxQ }; ingo@319: } ingo@137: } ingo@137: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :