Mercurial > dive4elements > river
changeset 2705:71f072d8b3d8
Improved the MultiIntArrayState, so the clients are able to display human readable strings for parameters and its values.
flys-artifacts/trunk@4422 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 16 May 2012 10:52:12 +0000 |
parents | d930245c9956 |
children | d8444fcb4e44 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeState.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MultiIntArrayState.java flys-artifacts/src/main/resources/messages.properties flys-artifacts/src/main/resources/messages_de.properties flys-artifacts/src/main/resources/messages_de_DE.properties flys-artifacts/src/main/resources/messages_en.properties |
diffstat | 7 files changed, 101 insertions(+), 2 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Wed May 16 09:18:10 2012 +0000 +++ b/flys-artifacts/ChangeLog Wed May 16 10:52:12 2012 +0000 @@ -1,3 +1,20 @@ +2012-05-16 Ingo Weinzierl <ingo@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/states/MultiIntArrayState.java: + Add a 'label' attribute to each <data> element in the static DESCRIBE. + In addition to that, the <data> element created in this class can have + multiple <item> elements which consist of a 'value' and a 'label' + attribute. This 'label' attribute is taken from getLabelFor() which is + abstract and needs to be implemented by subclasses. + + * src/main/java/de/intevation/flys/artifacts/states/DischargeState.java: + Implemented the abstract method getLabelFor(). + + * src/main/resources/messages.properties, + src/main/resources/messages_de_DE.properties, + src/main/resources/messages_de.properties: New i18n strings for MINFO + parameter names. + 2012-05-16 Ingo Weinzierl <ingo@intevation.de> * src/main/resources/messages.properties,
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeState.java Wed May 16 09:18:10 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/DischargeState.java Wed May 16 10:52:12 2012 +0000 @@ -5,6 +5,7 @@ import org.apache.log4j.Logger; import de.intevation.artifacts.Artifact; +import de.intevation.artifacts.CallContext; import de.intevation.artifacts.common.model.KVP; @@ -76,6 +77,34 @@ } + @Override + protected String getLabelFor( + CallContext cc, + String parameterName, + int value + ) throws IllegalArgumentException + { + if (!testParameterName(parameterName)) { + throw new IllegalArgumentException( + "Invalid parameter for state: '" + parameterName + "'"); + } + + DischargeZone zone = DischargeZone.getDischargeZoneById(value); + + if (zone == null) { + throw new IllegalArgumentException( + "Invalid id for DischargeZone: '" + value + "'"); + } + + String lo = zone.getLowerDischarge(); + String hi = zone.getUpperDischarge(); + + return hi != null && lo.equals(hi) + ? lo + " - " + hi + : lo; + } + + /** * This method might be used to test, if a parameter name is handled by this * state.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MultiIntArrayState.java Wed May 16 09:18:10 2012 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/MultiIntArrayState.java Wed May 16 10:52:12 2012 +0000 @@ -10,6 +10,10 @@ import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; import de.intevation.artifacts.common.model.KVP; +import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.resources.Resources; +import de.intevation.flys.utils.FLYSUtils; + /** * State that holds minimun and maximum (for validation). @@ -51,9 +55,50 @@ } + @Override + protected Element createStaticData( + FLYSArtifact flys, + ElementCreator creator, + CallContext cc, + String name, + String value, + String type + ) { + Element data = creator.create("data"); + creator.addAttr(data, "name", name, true); + creator.addAttr(data, "type", type, true); + creator.addAttr(data, "label", + Resources.getMsg(cc.getMeta(), name, name), true); + + int[] values = FLYSUtils.intArrayFromString(value); + + for (int val: values) { + try { + Element item = creator.create("item"); + creator.addAttr(item, "value", String.valueOf(val), true); + creator.addAttr(item, "label", getLabelFor(cc, name, val), true); + + data.appendChild(item); + } + catch (IllegalArgumentException iae) { + logger.warn("Cannot append item: " + val, iae); + } + } + + return data; + } + + protected abstract KVP<Integer, String>[] getOptions( Artifact artifact, String parameterName ) throws IllegalArgumentException; + + + protected abstract String getLabelFor( + CallContext cc, + String parameterName, + int value) + throws IllegalArgumentException; }
--- a/flys-artifacts/src/main/resources/messages.properties Wed May 16 09:18:10 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages.properties Wed May 16 10:52:12 2012 +0000 @@ -71,6 +71,8 @@ river = River calculation_mode = Calculation Mode ld_locations = Location(s) +main.channel = Main channel +total.channel = Total channel chart.longitudinal.section.title = W-Longitudinal Section chart.longitudinal.section.subtitle = Range: {0}-km {1,number,#.###} - {2,number,#.###}
--- a/flys-artifacts/src/main/resources/messages_de.properties Wed May 16 09:18:10 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_de.properties Wed May 16 10:52:12 2012 +0000 @@ -24,7 +24,7 @@ state.minfo.river = Gew\u00e4sser state.minfo.calculation_mode = Berechnungsart state.minfo.distance_only = Wahl der Berechnungsstrecke -state.minfo.dischargestate = Abflusszustand und Gerinne w\u00e4hlen +state.minfo.dischargestate = Abflusszustand und Gerinne historical.mode.w = Wasserstandsanalyse historical.mode.q = Abflussanalyse @@ -71,6 +71,8 @@ river = Fluss calculation_mode = Berechnungsart ld_locations = Ort(e) +main.channel = Hauptgerinne +total.channel = Gesamtgerinne chart.cross_section.title = Querprofildiagram f\u00fcr Gew\u00e4sser {0} chart.cross_section.subtitle = {0}-km: {1,number,#.###}
--- a/flys-artifacts/src/main/resources/messages_de_DE.properties Wed May 16 09:18:10 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_de_DE.properties Wed May 16 10:52:12 2012 +0000 @@ -24,7 +24,7 @@ state.minfo.river = Gew\u00e4sser state.minfo.calculation_mode = Berechnungsart state.minfo.distance_only = Wahl der Berechnungsstrecke -state.minfo.dischargestate = Abflusszustand und Gerinne w\u00e4hlen +state.minfo.dischargestate = Abflusszustand und Gerinne historical.mode.w = Wasserstandsanalyse historical.mode.q = Abflussanalyse @@ -69,6 +69,8 @@ river = Fluss calculation_mode = Berechnungsart ld_locations = Ort(e) +main.channel = Hauptgerinne +total.channel = Gesamtgerinne chart.cross_section.title = Querprofildiagram f\u00fcr Gew\u00e4sser {0} chart.cross_section.subtitle = {0}-km: {1,number,#.###}
--- a/flys-artifacts/src/main/resources/messages_en.properties Wed May 16 09:18:10 2012 +0000 +++ b/flys-artifacts/src/main/resources/messages_en.properties Wed May 16 10:52:12 2012 +0000 @@ -71,6 +71,8 @@ river = River calculation_mode = Calculation Mode ld_locations = Location(s) +main.channel = Main channel +total.channel = Total channel chart.cross_section.title = Cross Section for river {0} chart.cross_section.subtitle = {0}-km: {1,number,#.###}