raimund@3614: package de.intevation.flys.artifacts.states.minfo;
raimund@3614:
raimund@3614: import java.util.List;
raimund@3614:
raimund@3614: import org.w3c.dom.Element;
raimund@3614:
raimund@3614: import de.intevation.artifactdatabase.state.Facet;
raimund@3614: import de.intevation.artifacts.Artifact;
raimund@3614: import de.intevation.artifacts.CallContext;
raimund@3614: import de.intevation.artifacts.common.utils.XMLUtils;
raimund@3614: import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator;
raimund@3614: import de.intevation.flys.artifacts.FLYSArtifact;
raimund@3614: import de.intevation.flys.artifacts.access.BedHeightAccess;
raimund@3614: import de.intevation.flys.artifacts.states.DefaultState;
raimund@3614: import de.intevation.flys.utils.StringUtil;
raimund@3614:
raimund@3614: /**
raimund@3614: * @author Raimund Renkert
raimund@3614: */
raimund@3614: public class DifferenceSelect extends DefaultState {
raimund@3614:
raimund@3614: /**
raimund@3614: * The default constructor that initializes an empty State object.
raimund@3614: */
raimund@3614: public DifferenceSelect() {
raimund@3614: }
raimund@3614: /**
raimund@3614: * Specify to display nothing (this is kind of a "final" state).
raimund@3614: */
raimund@3614: @Override
raimund@3614: protected String getUIProvider() {
raimund@3614: return "bedheights_twin_panel";
raimund@3614: }
raimund@3614:
raimund@3614: /**
raimund@3614: * Overridden to do nothing.
raimund@3614: */
raimund@3614: @Override
raimund@3614: public Object computeAdvance(
raimund@3614: FLYSArtifact artifact,
raimund@3614: String hash,
raimund@3614: CallContext context,
raimund@3614: List facets,
raimund@3614: Object old
raimund@3614: ) {
raimund@3614: //Get data and do stuff, do not calculate
raimund@3614: return "";
raimund@3614: }
raimund@3614:
raimund@3614: @Override
raimund@3614: protected Element[] createItems(
raimund@3614: XMLUtils.ElementCreator ec,
raimund@3614: Artifact artifact,
raimund@3614: String name,
raimund@3614: CallContext context)
raimund@3614: {
raimund@3614: Element[] elements = new Element[1];
raimund@3614: BedHeightAccess bha = new BedHeightAccess((FLYSArtifact)artifact);
raimund@3614: String time = bha.getYearEpoch();
raimund@3614: elements[0] = createItem(
raimund@3614: ec,
raimund@3614: new String[] {"year-epoch", time});
raimund@3614:
raimund@3614: return elements;
raimund@3614: }
raimund@3614:
raimund@3614: /**
raimund@3614: * Creates the data element used for the static part of DESCRIBE document.
raimund@3614: */
raimund@3614: @Override
raimund@3614: protected Element createStaticData(
raimund@3614: FLYSArtifact flys,
raimund@3614: ElementCreator creator,
raimund@3614: CallContext cc,
raimund@3614: String name,
raimund@3614: String value,
raimund@3614: String type
raimund@3614: ) {
raimund@3614: Element dataElement = creator.create("data");
raimund@3614: creator.addAttr(dataElement, "name", name, true);
raimund@3614: creator.addAttr(dataElement, "type", type, true);
raimund@3614:
raimund@3614: Element itemElement = creator.create("item");
raimund@3614: creator.addAttr(itemElement, "value", value, true);
raimund@3614:
raimund@3614: String[] labels = getLabels(cc, value);
raimund@3614:
raimund@3614: creator.addAttr(
raimund@3614: itemElement,
raimund@3614: "label",
raimund@3614: labels[0],
raimund@3614: true);
raimund@3614: dataElement.appendChild(itemElement);
raimund@3614:
raimund@3614: return dataElement;
raimund@3614: }
raimund@3614:
raimund@3614:
raimund@3614: /**
raimund@3614: * Get name to display for selected watelerlevels (for example "Q=123")
raimund@3614: * from the CalculationResult.
raimund@3614: */
raimund@3614: public static String[] getLabels(CallContext cc, String value) {
raimund@3614: String[] recommendations = value.split("#");
raimund@3614: String displayString = "";
raimund@3614:
raimund@3614: // Walk over all selected recommendations and create label
raimund@3614: for (int i = 0; i < recommendations.length; i+=2) {
raimund@3614: String[] minuendParts = StringUtil
raimund@3614: .unbracket(recommendations[i+0])
raimund@3614: .split(";");
raimund@3614: if(minuendParts.length >= 4) {
raimund@3614: displayString += "(" + minuendParts[3];
raimund@3614: }
raimund@3614: else {
raimund@3614: displayString += "([error]";
raimund@3614: }
raimund@3614:
raimund@3614: displayString += " - ";
raimund@3614:
raimund@3614: String[] subtrahendParts = StringUtil
raimund@3614: .unbracket(recommendations[i+1])
raimund@3614: .split(";");
raimund@3614: if(subtrahendParts.length >= 4) {
raimund@3614: displayString += subtrahendParts[3] + ") ";
raimund@3614: }
raimund@3614: else {
raimund@3614: displayString += "[error])";
raimund@3614: }
raimund@3614: }
raimund@3614:
raimund@3614: return new String[] { displayString };
raimund@3614: }
raimund@3614: }
raimund@3614: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :