Mercurial > dive4elements > river
changeset 1663:4fbd43061315
Show proper labels for selected differences.
flys-artifacts/trunk@2866 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Fri, 30 Sep 2011 05:31:34 +0000 |
parents | a800994aed1e |
children | 71d5abde92f2 |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelPairSelectState.java |
diffstat | 2 files changed, 118 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Thu Sep 29 18:19:45 2011 +0000 +++ b/flys-artifacts/ChangeLog Fri Sep 30 05:31:34 2011 +0000 @@ -1,3 +1,8 @@ +2011-09-30 Felix Wolfsteller <felix.wolfsteller@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/states/WaterlevelPairSelectState.java: + (createStaticData, getLabels): Create proper labels for differences. + 2011-09-29 Sascha L. Teichmann <sascha.teichmann@intevation.de> flys/issue244 (WINFO: Export von AT-Dateien im ersten Teil unterschiedlich)
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelPairSelectState.java Thu Sep 29 18:19:45 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelPairSelectState.java Fri Sep 30 05:31:34 2011 +0000 @@ -4,13 +4,25 @@ import org.apache.log4j.Logger; +import org.w3c.dom.Element; + import de.intevation.artifacts.CallContext; +import de.intevation.artifactdatabase.data.DefaultStateData; +import de.intevation.artifactdatabase.data.StateData; import de.intevation.artifactdatabase.state.Facet; +import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; + import de.intevation.flys.artifacts.FLYSArtifact; +import de.intevation.flys.artifacts.model.CalculationResult; +import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.artifacts.model.WQKms; +import de.intevation.flys.artifacts.resources.Resources; -import de.intevation.flys.artifacts.model.FacetTypes; +import de.intevation.flys.utils.FLYSUtils; +import de.intevation.flys.utils.StringUtil; + public class WaterlevelPairSelectState @@ -20,6 +32,12 @@ /** The logger that is used in this state. */ private static Logger logger = Logger.getLogger(WaterlevelPairSelectState.class); + + // TODO fix (state.winfo.waterlevel) + // own id is state.winfo.waterlevel_pair_select + public static final String WINFO_WDIFFERENCES_STATE_ID + = "state.winfo.w_differences"; + public WaterlevelPairSelectState() { } @@ -42,5 +60,99 @@ //Get data and do stuff, do not calculate return ""; } + + + /** + * Creats the data element used for the static part of DESCRIBE document. + */ + @Override + protected Element createStaticData( + ElementCreator creator, + CallContext cc, + String name, + String value, + String type + ) { + Element dataElement = creator.create("data"); + creator.addAttr(dataElement, "name", name, true); + creator.addAttr(dataElement, "type", type, true); + + Element itemElement = creator.create("item"); + creator.addAttr(itemElement, "value", value, true); + + String[] labels = getLabels(cc, value); + Object[] obj = new Object[] { labels[0] }; + + // TODO own i18n + String attrValue = Resources.getMsg( + cc.getMeta(), "wsp.selected.string", "wsp.selected.string", obj); + //I18N_STATIC_KEY, I18N_STATIC_KEY, obj); + + creator.addAttr(itemElement, "label", attrValue, true); + dataElement.appendChild(itemElement); + + return dataElement; + } + + + // TODO merge implementations with WaterlevelSelectState + /** + * Get name to display for selected watelerlevels (for example "Q=123") + * from the CalculationResult. + */ + public static String[] getLabels(CallContext cc, String value) { + String[] recommendations = value.split("#"); + String displayString = ""; + + // Walk over all selected recommendations and create label + // like "W (Q=1) - W (Q=2)". + for (int i = 0; i < recommendations.length; i+=2) { + String[] minuendParts = StringUtil + .unbracket(recommendations[i+0]) + .split(";"); + String[] subtrahendParts = StringUtil + .unbracket(recommendations[i+1]) + .split(";"); + + + FLYSArtifact artifact1 = FLYSUtils.getArtifact(minuendParts[0], cc); + + CalculationResult rawData1 = (CalculationResult) artifact1.compute( + cc, + null, + "state.winfo.waterlevel", + ComputeType.ADVANCE, + false); + WQKms[] wqkms1 = (WQKms[]) rawData1.getData(); + + int idx1 = -1; + try { + idx1 = Integer.parseInt(minuendParts[2]); + } + catch (NumberFormatException nfe) { /* do nothing */ } + + FLYSArtifact artifact2 = FLYSUtils.getArtifact(subtrahendParts[0], cc); + + CalculationResult rawData2 = (CalculationResult) artifact2.compute( + cc, + null, + "state.winfo.waterlevel", + ComputeType.ADVANCE, + false); + WQKms[] wqkms2 = (WQKms[]) rawData2.getData(); + + int idx2 = -1; + try { + idx2 = Integer.parseInt(subtrahendParts[2]); + } + catch (NumberFormatException nfe) { /* do nothing */ } + + displayString += "(" + StringUtil.wWrap(wqkms1[idx1].getName()) + + " - " + StringUtil.wWrap(wqkms2[idx2].getName()) + ")"; + } + + return new String[] { displayString }; + } + } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 :