ingo@921: package de.intevation.flys.artifacts.states; ingo@921: ingo@921: import org.apache.log4j.Logger; ingo@921: ingo@921: import org.w3c.dom.Element; ingo@921: ingo@921: import de.intevation.artifacts.Artifact; ingo@921: import de.intevation.artifacts.CallContext; ingo@921: ingo@921: import de.intevation.artifacts.common.utils.XMLUtils; ingo@921: ingo@921: import de.intevation.artifactdatabase.ProtocolUtils; ingo@921: import de.intevation.artifactdatabase.data.StateData; ingo@921: ingo@921: import de.intevation.flys.artifacts.FLYSArtifact; raimund@2132: ingo@921: import de.intevation.flys.artifacts.model.FacetTypes; ingo@921: import de.intevation.flys.artifacts.resources.Resources; ingo@921: felix@2235: import de.intevation.flys.utils.FLYSUtils; felix@2235: felix@2235: ingo@921: /** ingo@921: * @author Ingo Weinzierl ingo@921: */ ingo@921: public class ComputationRangeState ingo@921: extends RangeState ingo@921: implements FacetTypes ingo@921: { ingo@921: private static Logger logger = ingo@921: Logger.getLogger(ComputationRangeState.class); ingo@921: ingo@921: /** The name of the 'from' field. */ ingo@921: public static final String FROM = "ld_from"; ingo@921: ingo@921: /** The name of the 'to' field. */ ingo@921: public static final String TO = "ld_to"; ingo@921: ingo@921: /** The name of the 'step' field. */ ingo@921: public static final String STEP = "ld_step"; ingo@921: felix@1685: /** The default step width. */ ingo@921: public static final int DEFAULT_STEP = 100; ingo@921: ingo@921: ingo@921: public ComputationRangeState() { ingo@921: } ingo@921: ingo@921: ingo@921: @Override ingo@921: protected Element createData( ingo@921: XMLUtils.ElementCreator cr, ingo@921: Artifact artifact, ingo@921: StateData data, ingo@921: CallContext context) ingo@921: { ingo@921: Element select = ProtocolUtils.createArtNode( ingo@921: cr, "select", null, null); ingo@921: ingo@921: cr.addAttr(select, "name", data.getName(), true); ingo@921: ingo@921: Element label = ProtocolUtils.createArtNode( ingo@921: cr, "label", null, null); ingo@921: ingo@921: Element choices = ProtocolUtils.createArtNode( ingo@921: cr, "choices", null, null); ingo@921: ingo@921: label.setTextContent(Resources.getMsg( ingo@921: context.getMeta(), ingo@921: data.getName(), ingo@921: data.getName())); ingo@921: ingo@921: select.appendChild(label); ingo@921: ingo@921: return select; ingo@921: } ingo@921: ingo@921: ingo@921: @Override ingo@921: protected Element[] createItems( ingo@921: XMLUtils.ElementCreator cr, ingo@921: Artifact artifact, ingo@921: String name, ingo@921: CallContext context) ingo@921: { ingo@921: double[] minmax = getMinMax(artifact); ingo@921: ingo@921: double minVal = Double.MIN_VALUE; ingo@921: double maxVal = Double.MAX_VALUE; ingo@921: ingo@921: if (minmax != null) { ingo@921: minVal = minmax[0]; ingo@921: maxVal = minmax[1]; ingo@921: } ingo@921: else { ingo@921: logger.warn("Could not read min/max distance values!"); ingo@921: } ingo@921: ingo@921: if (name.equals("ld_from")) { ingo@921: Element min = createItem( ingo@921: cr, ingo@921: new String[] {"min", new Double(minVal).toString()}); ingo@921: ingo@921: return new Element[] { min }; ingo@921: } ingo@921: else if (name.equals("ld_to")) { ingo@921: Element max = createItem( ingo@921: cr, ingo@921: new String[] {"max", new Double(maxVal).toString()}); ingo@921: ingo@921: return new Element[] { max }; ingo@921: } ingo@921: else { ingo@921: Element step = createItem( ingo@921: cr, ingo@921: new String[] {"step", String.valueOf(getDefaultStep())}); ingo@921: return new Element[] { step }; ingo@921: } ingo@921: ingo@921: } ingo@921: ingo@921: ingo@921: protected Element createItem(XMLUtils.ElementCreator cr, Object obj) { ingo@921: Element item = ProtocolUtils.createArtNode(cr, "item", null, null); ingo@921: Element label = ProtocolUtils.createArtNode(cr, "label", null, null); ingo@921: Element value = ProtocolUtils.createArtNode(cr, "value", null, null); ingo@921: ingo@921: String[] arr = (String[]) obj; ingo@921: ingo@921: label.setTextContent(arr[0]); ingo@921: value.setTextContent(arr[1]); ingo@921: ingo@921: item.appendChild(label); ingo@921: item.appendChild(value); ingo@921: ingo@921: return item; ingo@921: } ingo@921: ingo@921: ingo@921: @Override ingo@921: protected double[] getMinMax(Artifact artifact) { ingo@921: FLYSArtifact flysArtifact = (FLYSArtifact) artifact; felix@2235: return FLYSUtils.getRiverMinMax(flysArtifact); ingo@921: } ingo@921: ingo@921: ingo@921: protected double getDefaultStep() { ingo@921: return DEFAULT_STEP; ingo@921: } ingo@921: ingo@921: ingo@921: @Override ingo@921: protected String getLowerField() { ingo@921: return FROM; ingo@921: } ingo@921: ingo@921: ingo@921: @Override ingo@921: protected String getUpperField() { ingo@921: return TO; ingo@921: } ingo@921: ingo@921: ingo@921: @Override ingo@921: protected String getStepField() { ingo@921: return STEP; ingo@921: } ingo@921: } ingo@921: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :