Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java @ 2025:6762f54b23b1
Bugfix: format all Ws and Qs in WQSelect State.
flys-artifacts/trunk@3482 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 20 Dec 2011 09:01:29 +0000 |
parents | 8a2cbf947395 |
children | 355495661a1c |
comparison
equal
deleted
inserted
replaced
2024:2bb160b2768e | 2025:6762f54b23b1 |
---|---|
87 return super.createStaticData(flys, creator, cc, name, value, type); | 87 return super.createStaticData(flys, creator, cc, name, value, type); |
88 } | 88 } |
89 | 89 |
90 String mode = flys.getDataAsString(WQ_MODE); | 90 String mode = flys.getDataAsString(WQ_MODE); |
91 String free = flys.getDataAsString(WQ_FREE); | 91 String free = flys.getDataAsString(WQ_FREE); |
92 if (mode == null || mode.equals("W") || Boolean.valueOf(free)) { | |
93 return super.createStaticData(flys, creator, cc, name, value, type); | |
94 } | |
95 | 92 |
96 WINFOArtifact winfo = (WINFOArtifact) flys; | 93 WINFOArtifact winfo = (WINFOArtifact) flys; |
97 | 94 |
98 Element dataElement = creator.create("data"); | 95 Element dataElement = creator.create("data"); |
99 creator.addAttr(dataElement, "name", name, true); | 96 creator.addAttr(dataElement, "name", name, true); |
100 creator.addAttr(dataElement, "type", type, true); | 97 creator.addAttr(dataElement, "type", type, true); |
101 | 98 |
102 Element itemElement = creator.create("item"); | 99 Element itemElement = creator.create("item"); |
103 creator.addAttr(itemElement, "value", value, true); | 100 creator.addAttr(itemElement, "value", value, true); |
104 creator.addAttr(itemElement, "label", getLabel(winfo, cc, value), true); | 101 |
102 String label = ""; | |
103 | |
104 if (mode == null || mode.equals("W") || Boolean.valueOf(free)) { | |
105 label = getLabel(winfo, cc, value); | |
106 } | |
107 else { | |
108 label = getSpecialLabel(winfo, cc, value); | |
109 } | |
110 | |
111 creator.addAttr(itemElement, "label", label, true); | |
105 | 112 |
106 dataElement.appendChild(itemElement); | 113 dataElement.appendChild(itemElement); |
107 | 114 |
108 return dataElement; | 115 return dataElement; |
109 } | 116 } |
122 | 129 |
123 for (String value: values) { | 130 for (String value: values) { |
124 try { | 131 try { |
125 double v = Double.valueOf(value.trim()); | 132 double v = Double.valueOf(value.trim()); |
126 | 133 |
134 String formatted = nf.format(v); | |
135 | |
136 label = label != null ? label + " " + formatted : formatted; | |
137 } | |
138 catch (NumberFormatException nfe) { | |
139 // do nothing here | |
140 } | |
141 } | |
142 | |
143 return label; | |
144 } | |
145 | |
146 | |
147 protected static String getSpecialLabel( | |
148 WINFOArtifact winfo, | |
149 CallContext cc, | |
150 String raw | |
151 ) { | |
152 String[] values = raw.split(" "); | |
153 String label = null; | |
154 | |
155 NumberFormat nf = NumberFormat.getInstance( | |
156 Resources.getLocale(cc.getMeta())); | |
157 | |
158 for (String value: values) { | |
159 try { | |
160 double v = Double.valueOf(value.trim()); | |
161 | |
127 String tmp = nf.format(v); | 162 String tmp = nf.format(v); |
128 String mv = FLYSUtils.getNamedMainValue(winfo.getGauge(),v); | 163 String mv = FLYSUtils.getNamedMainValue(winfo.getGauge(),v); |
129 | 164 |
130 if (mv != null && mv.length() > 0) { | 165 if (mv != null && mv.length() > 0) { |
131 String add = mv + ": " + tmp; | 166 String add = mv + ": " + tmp; |
132 label = label != null ? label + ", " + add : add; | 167 logger.debug("Add main value: '" + mv + "'"); |
168 label = label != null ? label + " " + add : add; | |
133 } | 169 } |
134 else { | 170 else { |
135 label = label != null ? label + ", " + tmp : tmp; | 171 logger.debug("Add non main value: '" + tmp + "'"); |
172 label = label != null ? label + " " + tmp : tmp; | |
136 } | 173 } |
137 } | 174 } |
138 catch (NumberFormatException nfe) { | 175 catch (NumberFormatException nfe) { |
139 // do nothing here | 176 // do nothing here |
140 } | 177 } |