# HG changeset patch # User Ingo Weinzierl # Date 1324371689 0 # Node ID 6762f54b23b12eae827a68696b6dadbaabd01015 # Parent 2bb160b2768e70a4abe8829bc98a7b6470d48d95 Bugfix: format all Ws and Qs in WQSelect State. flys-artifacts/trunk@3482 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r 2bb160b2768e -r 6762f54b23b1 flys-artifacts/ChangeLog --- a/flys-artifacts/ChangeLog Tue Dec 20 09:00:51 2011 +0000 +++ b/flys-artifacts/ChangeLog Tue Dec 20 09:01:29 2011 +0000 @@ -1,3 +1,10 @@ +2011-12-20 Ingo Weinzierl + + * src/main/java/de/intevation/flys/artifacts/states/WQSelect.java: + Create all formatted string labels for Ws and Qs in this class, because + this class is the only instance that knows that there are double values + to format. + 2011-12-20 Felix Wolfsteller Introduced new Facet that will deliver whatever getData returns via diff -r 2bb160b2768e -r 6762f54b23b1 flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java --- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Tue Dec 20 09:00:51 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java Tue Dec 20 09:01:29 2011 +0000 @@ -89,9 +89,6 @@ String mode = flys.getDataAsString(WQ_MODE); String free = flys.getDataAsString(WQ_FREE); - if (mode == null || mode.equals("W") || Boolean.valueOf(free)) { - return super.createStaticData(flys, creator, cc, name, value, type); - } WINFOArtifact winfo = (WINFOArtifact) flys; @@ -101,7 +98,17 @@ Element itemElement = creator.create("item"); creator.addAttr(itemElement, "value", value, true); - creator.addAttr(itemElement, "label", getLabel(winfo, cc, value), true); + + String label = ""; + + if (mode == null || mode.equals("W") || Boolean.valueOf(free)) { + label = getLabel(winfo, cc, value); + } + else { + label = getSpecialLabel(winfo, cc, value); + } + + creator.addAttr(itemElement, "label", label, true); dataElement.appendChild(itemElement); @@ -124,15 +131,45 @@ try { double v = Double.valueOf(value.trim()); + String formatted = nf.format(v); + + label = label != null ? label + " " + formatted : formatted; + } + catch (NumberFormatException nfe) { + // do nothing here + } + } + + return label; + } + + + protected static String getSpecialLabel( + WINFOArtifact winfo, + CallContext cc, + String raw + ) { + String[] values = raw.split(" "); + String label = null; + + NumberFormat nf = NumberFormat.getInstance( + Resources.getLocale(cc.getMeta())); + + for (String value: values) { + try { + double v = Double.valueOf(value.trim()); + String tmp = nf.format(v); String mv = FLYSUtils.getNamedMainValue(winfo.getGauge(),v); if (mv != null && mv.length() > 0) { String add = mv + ": " + tmp; - label = label != null ? label + ", " + add : add; + logger.debug("Add main value: '" + mv + "'"); + label = label != null ? label + " " + add : add; } else { - label = label != null ? label + ", " + tmp : tmp; + logger.debug("Add non main value: '" + tmp + "'"); + label = label != null ? label + " " + tmp : tmp; } } catch (NumberFormatException nfe) {