# HG changeset patch # User Ingo Weinzierl # Date 1262619689 0 # Node ID b8080695ea62ad554b75acb95a98909dde082f1c # Parent 363236fc462d4c5bf014e075d5679baf81c6721c Splitted code pathes of dynamic and static nodes. Static nodes contain the selected value only instead of transfering the whole stack of options again. gnv-artifacts/trunk@506 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 363236fc462d -r b8080695ea62 gnv-artifacts/ChangeLog --- a/gnv-artifacts/ChangeLog Mon Jan 04 15:27:33 2010 +0000 +++ b/gnv-artifacts/ChangeLog Mon Jan 04 15:41:29 2010 +0000 @@ -1,13 +1,23 @@ +2010-01-04 Ingo Weinzierl + + * src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java: Declared + method to create a new xforms element as static to be able to use it + without instantiating an object of this class. + + * src/main/java/de/intevation/gnv/state/StateBase.java: Splitted code pathes + of static and dynamic nodes. Static nodes contain the selected value + only instead of transfering the complete stack of possible values again. + 2010-01-04 Tim Englich - * src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java (process): - Changed the XYDepth-Interface-Implementation to QueriedXYDepth - * doc/conf/queries.properties: - Added the Query for Rasterdataaccess. - * src/main/java/de/intevation/gnv/math/QueriedXYDepth.java (QueriedXYDepth): - Added Implementation of the XYDepth-Interface for Querying the height - of an Position using the geo-backend interface. - It is only nessesary to add a Query with the id rasterQuery to the query-Properties. + * src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/VerticalCrossSectionOutputState.java (process): + Changed the XYDepth-Interface-Implementation to QueriedXYDepth + * doc/conf/queries.properties: + Added the Query for Rasterdataaccess. + * src/main/java/de/intevation/gnv/math/QueriedXYDepth.java (QueriedXYDepth): + Added Implementation of the XYDepth-Interface for Querying the height + of an Position using the geo-backend interface. + It is only nessesary to add a Query with the id rasterQuery to the query-Properties. 2010-01-04 Sascha L. Teichmann diff -r 363236fc462d -r b8080695ea62 gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Mon Jan 04 15:27:33 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java Mon Jan 04 15:41:29 2010 +0000 @@ -42,6 +42,7 @@ /** * @author Tim Englich + * @author Ingo Weinzierl * */ public abstract class StateBase implements State { @@ -527,168 +528,276 @@ rootNode.appendChild(staticNode); rootNode.appendChild(dynamic); while (it.hasNext()) { - Object o = it.next(); - if (o instanceof Collection) { - String name = null; - boolean multiselect = false; - if (o instanceof NamedCollection) { - NamedCollection nc = ((NamedCollection) o); - name = nc.getName(); - multiselect = nc.isMultiSelect(); - } else { - Object[] names = this.inputValueNames.toArray(); - name = names[names.length - 1].toString(); - } - - Element selectNode = xmlutilities.createXFormElement( - document, multiselect ? "select" : "select1"); - selectNode.setAttribute("ref", name); - - Element lableNode = xmlutilities.createXFormElement( - document, "label"); - lableNode.setTextContent(RessourceFactory.getInstance() - .getRessource(callMeta.getLanguages(), name, name)); - Element choiceNode = xmlutilities.createXFormElement( - document, "choices"); - - Collection values = (Collection) o; - Iterator resultIt = values.iterator(); - while (resultIt.hasNext()) { - KeyValueDescibeData result = resultIt.next(); - Element itemNode = xmlutilities.createXFormElement( - document, "item"); - - if (result.isSelected()) { - itemNode.setAttribute("selected", "true"); - } - - Element choiceLableNode = xmlutilities - .createXFormElement(document, "label"); - choiceLableNode.setTextContent(result.getValue()); - itemNode.appendChild(choiceLableNode); - - Element choicValueNode = xmlutilities - .createXFormElement(document, "value"); - choicValueNode.setTextContent("" + result.getKey()); - itemNode.appendChild(choicValueNode); - choiceNode.appendChild(itemNode); - } - selectNode.appendChild(lableNode); - selectNode.appendChild(choiceNode); - - if (!it.hasNext() && this.dataName != null) { - dynamic.appendChild(selectNode); - } else { - staticNode.appendChild(selectNode); - } - - } else if (o instanceof MinMaxDescribeData) { - MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o; - Object min = minMaxDescibeData.getMinValue(); - Object max = minMaxDescibeData.getMaxValue(); - if (min instanceof GregorianCalendar) { - Date d = ((GregorianCalendar) min).getTime(); - min = DateUtils.getPatternedDateAmer(d); - } + if ((!it.hasNext() && dataName != null)) { + appendToDynamicNode(document, dynamic, callMeta, o); + } + else { + appendToStaticNode(document, staticNode, callMeta, o); + } + } + } + } - if (max instanceof GregorianCalendar) { - Date d = ((GregorianCalendar) max).getTime(); - max = DateUtils.getPatternedDateAmer(d); - } - - Element groupNode = xmlutilities.createXFormElement( - document, "group"); - groupNode.setAttribute("ref", minMaxDescibeData.getName()); - Element groupNodeLableNode = xmlutilities - .createXFormElement(document, "label"); - groupNodeLableNode.setTextContent(RessourceFactory - .getInstance().getRessource( - callMeta.getLanguages(), - minMaxDescibeData.getName(), - minMaxDescibeData.getName())); - groupNode.appendChild(groupNodeLableNode); - - Element inputMinNode = xmlutilities.createXFormElement( - document, "input"); - inputMinNode.setAttribute("ref", MINVALUEFIELDNAME); - Element inputMinLableNode = xmlutilities - .createXFormElement(document, "label"); - inputMinLableNode.setTextContent(RessourceFactory - .getInstance().getRessource( - callMeta.getLanguages(), MINVALUEFIELDNAME, - MINVALUEFIELDNAME)); - inputMinNode.appendChild(inputMinLableNode); - - Element inputMinValueNode = xmlutilities - .createXFormElement(document, "value"); - inputMinValueNode.setTextContent(min.toString()); - inputMinNode.appendChild(inputMinValueNode); - - Element inputMaxNode = xmlutilities.createXFormElement( - document, "input"); - inputMaxNode.setAttribute("ref", MAXVALUEFIELDNAME); - Element inputMaxLableNode = xmlutilities - .createXFormElement(document, "label"); - inputMaxLableNode.setTextContent(RessourceFactory - .getInstance().getRessource( - callMeta.getLanguages(), MAXVALUEFIELDNAME, - MAXVALUEFIELDNAME)); - inputMaxNode.appendChild(inputMaxLableNode); - Element inputMaxValueNode = xmlutilities - .createXFormElement(document, "value"); - inputMaxValueNode.setTextContent(max.toString()); - inputMaxNode.appendChild(inputMaxValueNode); - - groupNode.appendChild(inputMinNode); - groupNode.appendChild(inputMaxNode); - - if (!it.hasNext() && this.dataName != null) { - dynamic.appendChild(groupNode); - } else { - staticNode.appendChild(groupNode); - } - } else if (o instanceof SingleValueDescribeData) { + protected void appendToStaticNode( + Document document, + Node staticNode, + CallMeta callMeta, + Object o + ) { + if (o instanceof Collection) { + String name = null; + boolean multiselect = false; + if (o instanceof NamedCollection) { + NamedCollection nc = ((NamedCollection) o); + name = nc.getName(); + multiselect = nc.isMultiSelect(); + } else { + Object[] names = this.inputValueNames.toArray(); + name = names[names.length - 1].toString(); + } - SingleValueDescribeData svdb = (SingleValueDescribeData) o; - - Element groupNode = xmlutilities.createXFormElement( - document, "group"); - groupNode.setAttribute("ref", svdb.getName()); - Element groupNodeLableNode = xmlutilities - .createXFormElement(document, "label"); - groupNodeLableNode.setTextContent(RessourceFactory - .getInstance().getRessource( - callMeta.getLanguages(), - svdb.getName(), - svdb.getName())); - groupNode.appendChild(groupNodeLableNode); + log.debug("Name of attribute: " + name); + Element selectNode = ArtifactXMLUtilities.createXFormElement( + document, multiselect ? "select" : "select1"); + selectNode.setAttribute("ref", name); - Element inputNode = xmlutilities.createXFormElement( - document, "input"); - inputNode.setAttribute("ref", svdb.getName()); - - Element inputLableNode = xmlutilities.createXFormElement( - document, "label"); - inputLableNode.setTextContent(""); - inputNode.appendChild(inputLableNode); + Element lableNode = ArtifactXMLUtilities.createXFormElement( + document, "label"); + lableNode.setTextContent(RessourceFactory.getInstance() + .getRessource(callMeta.getLanguages(), name, name)); + Element choiceNode = ArtifactXMLUtilities.createXFormElement( + document, "choices"); - Element inputValueNode = xmlutilities.createXFormElement( - document, "value"); - inputValueNode.setTextContent(svdb.getValue()); - inputNode.appendChild(inputValueNode); + Collection values = (Collection) o; + Iterator resultIt = values.iterator(); + while (resultIt.hasNext()) { + KeyValueDescibeData result = resultIt.next(); - groupNode.appendChild(inputNode); - if (!it.hasNext() && this.dataName != null) { - dynamic.appendChild(groupNode); - } else { - staticNode.appendChild(groupNode); - } + if (result.isSelected()) { + Element itemNode = ArtifactXMLUtilities.createXFormElement( + document, "item"); + + itemNode.setAttribute("selected", "true"); + + Element choiceLableNode = + ArtifactXMLUtilities.createXFormElement( + document, "label"); + choiceLableNode.setTextContent(result.getValue()); + itemNode.appendChild(choiceLableNode); + + Element choicValueNode = + ArtifactXMLUtilities.createXFormElement( + document, "value"); + choicValueNode.setTextContent("" + result.getKey()); + itemNode.appendChild(choicValueNode); + choiceNode.appendChild(itemNode); + } + } + selectNode.appendChild(lableNode); + selectNode.appendChild(choiceNode); + + staticNode.appendChild(selectNode); + } + else if (o instanceof MinMaxDescribeData) { + appendMinMaxDescribeData( + document, + staticNode, + callMeta, + o); + } + else if (o instanceof SingleValueDescribeData) { + appendSingleValueDescribeData( + document, + staticNode, + callMeta, + o); + } + } + + + protected void appendToDynamicNode( + Document document, + Node dynamicNode, + CallMeta callMeta, + Object o + ) { + if (o instanceof Collection) { + String name = null; + boolean multiselect = false; + if (o instanceof NamedCollection) { + NamedCollection nc = ((NamedCollection) o); + name = nc.getName(); + multiselect = nc.isMultiSelect(); + } else { + Object[] names = this.inputValueNames.toArray(); + name = names[names.length - 1].toString(); + } + + Element selectNode = ArtifactXMLUtilities.createXFormElement( + document, multiselect ? "select" : "select1"); + selectNode.setAttribute("ref", name); + + Element lableNode = ArtifactXMLUtilities.createXFormElement( + document, "label"); + lableNode.setTextContent(RessourceFactory.getInstance() + .getRessource(callMeta.getLanguages(), name, name)); + Element choiceNode = ArtifactXMLUtilities.createXFormElement( + document, "choices"); + + Collection values = (Collection) o; + Iterator resultIt = values.iterator(); + while (resultIt.hasNext()) { + KeyValueDescibeData result = resultIt.next(); + Element itemNode = ArtifactXMLUtilities.createXFormElement( + document, "item"); + + if (result.isSelected()) { + itemNode.setAttribute("selected", "true"); } + Element choiceLableNode = + ArtifactXMLUtilities.createXFormElement(document, "label"); + choiceLableNode.setTextContent(result.getValue()); + itemNode.appendChild(choiceLableNode); + + Element choicValueNode = ArtifactXMLUtilities.createXFormElement( + document, "value"); + choicValueNode.setTextContent("" + result.getKey()); + itemNode.appendChild(choicValueNode); + choiceNode.appendChild(itemNode); } + selectNode.appendChild(lableNode); + selectNode.appendChild(choiceNode); + + dynamicNode.appendChild(selectNode); } + else if (o instanceof MinMaxDescribeData) { + appendMinMaxDescribeData( + document, + dynamicNode, + callMeta, + o); + } + else if (o instanceof SingleValueDescribeData) { + appendSingleValueDescribeData( + document, + dynamicNode, + callMeta, + o); + } + } + + + protected void appendMinMaxDescribeData( + Document document, + Node node, + CallMeta callMeta, + Object o + ) { + MinMaxDescribeData minMaxDescibeData = (MinMaxDescribeData) o; + Object min = minMaxDescibeData.getMinValue(); + Object max = minMaxDescibeData.getMaxValue(); + if (min instanceof GregorianCalendar) { + Date d = ((GregorianCalendar) min).getTime(); + min = DateUtils.getPatternedDateAmer(d); + } + + if (max instanceof GregorianCalendar) { + Date d = ((GregorianCalendar) max).getTime(); + max = DateUtils.getPatternedDateAmer(d); + } + + Element groupNode = ArtifactXMLUtilities.createXFormElement( + document, "group"); + groupNode.setAttribute("ref", minMaxDescibeData.getName()); + Element groupNodeLableNode = + ArtifactXMLUtilities.createXFormElement(document, "label"); + groupNodeLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), + minMaxDescibeData.getName(), + minMaxDescibeData.getName())); + groupNode.appendChild(groupNodeLableNode); + + Element inputMinNode = ArtifactXMLUtilities.createXFormElement( + document, "input"); + inputMinNode.setAttribute("ref", MINVALUEFIELDNAME); + Element inputMinLableNode = ArtifactXMLUtilities + .createXFormElement(document, "label"); + inputMinLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), MINVALUEFIELDNAME, + MINVALUEFIELDNAME)); + inputMinNode.appendChild(inputMinLableNode); + + Element inputMinValueNode = ArtifactXMLUtilities.createXFormElement( + document, "value"); + inputMinValueNode.setTextContent(min.toString()); + inputMinNode.appendChild(inputMinValueNode); + + Element inputMaxNode = ArtifactXMLUtilities.createXFormElement( + document, "input"); + inputMaxNode.setAttribute("ref", MAXVALUEFIELDNAME); + Element inputMaxLableNode = ArtifactXMLUtilities.createXFormElement( + document, "label"); + inputMaxLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), MAXVALUEFIELDNAME, + MAXVALUEFIELDNAME)); + inputMaxNode.appendChild(inputMaxLableNode); + + Element inputMaxValueNode = ArtifactXMLUtilities.createXFormElement( + document, "value"); + inputMaxValueNode.setTextContent(max.toString()); + inputMaxNode.appendChild(inputMaxValueNode); + + groupNode.appendChild(inputMinNode); + groupNode.appendChild(inputMaxNode); + + node.appendChild(groupNode); + } + + + + protected void appendSingleValueDescribeData( + Document document, + Node node, + CallMeta callMeta, + Object o + ) { + SingleValueDescribeData svdb = (SingleValueDescribeData) o; + + Element groupNode = ArtifactXMLUtilities.createXFormElement( + document, "group"); + groupNode.setAttribute("ref", svdb.getName()); + Element groupNodeLableNode = ArtifactXMLUtilities.createXFormElement( + document, "label"); + groupNodeLableNode.setTextContent(RessourceFactory + .getInstance().getRessource( + callMeta.getLanguages(), + svdb.getName(), + svdb.getName())); + groupNode.appendChild(groupNodeLableNode); + + Element inputNode = ArtifactXMLUtilities.createXFormElement( + document, "input"); + inputNode.setAttribute("ref", svdb.getName()); + + Element inputLableNode = ArtifactXMLUtilities.createXFormElement( + document, "label"); + inputLableNode.setTextContent(""); + inputNode.appendChild(inputLableNode); + + Element inputValueNode = ArtifactXMLUtilities.createXFormElement( + document, "value"); + inputValueNode.setTextContent(svdb.getValue()); + inputNode.appendChild(inputValueNode); + + groupNode.appendChild(inputNode); + + node.appendChild(groupNode); } /** diff -r 363236fc462d -r b8080695ea62 gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java --- a/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java Mon Jan 04 15:27:33 2010 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/utils/ArtifactXMLUtilities.java Mon Jan 04 15:41:29 2010 +0000 @@ -114,7 +114,7 @@ return document; } - public Element createXFormElement(Document document, String name) { + public static Element createXFormElement(Document document, String name) { Element node = document.createElementNS(XFORM_URL, name); node.setPrefix(XFORM_PREFIX); return node;