comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WQSelect.java @ 2164:d548e2e13524

Added code for the simple case of "Bezugslinienverfahren" ("W auf freier Strecke"). flys-artifacts/trunk@3752 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Mon, 23 Jan 2012 16:55:42 +0000
parents 48fd8b06bce5
children 22bac691d414
comparison
equal deleted inserted replaced
2163:105097966111 2164:d548e2e13524
100 creator.addAttr(dataElement, "type", type, true); 100 creator.addAttr(dataElement, "type", type, true);
101 101
102 Element itemElement = creator.create("item"); 102 Element itemElement = creator.create("item");
103 creator.addAttr(itemElement, "value", value, true); 103 creator.addAttr(itemElement, "value", value, true);
104 104
105 String label = ""; 105 String label;
106 106
107 if (mode == null || mode.equals("W") || Boolean.valueOf(free)) { 107 if (mode == null || mode.equals("W") || Boolean.valueOf(free)) {
108 label = getLabel(winfo, cc, value); 108 label = getLabel(winfo, cc, value);
109 } 109 }
110 else { 110 else {
123 WINFOArtifact winfo, 123 WINFOArtifact winfo,
124 CallContext cc, 124 CallContext cc,
125 String raw 125 String raw
126 ) { 126 ) {
127 String[] values = raw.split(" "); 127 String[] values = raw.split(" ");
128 String label = null; 128
129 if (values.length < 1) {
130 return null;
131 }
132
133 StringBuilder label = new StringBuilder();
129 134
130 NumberFormat nf = NumberFormat.getInstance( 135 NumberFormat nf = NumberFormat.getInstance(
131 Resources.getLocale(cc.getMeta())); 136 Resources.getLocale(cc.getMeta()));
132 137
133 for (String value: values) { 138 for (String value: values) {
134 try { 139 try {
135 double v = Double.valueOf(value.trim()); 140 double v = Double.parseDouble(value.trim());
136 141
137 String formatted = nf.format(v); 142 String formatted = nf.format(v);
138 143
139 label = label != null ? label + ";" + formatted : formatted; 144 if (label.length() > 0) {
145 label.append(';');
146 }
147 label.append(formatted);
140 } 148 }
141 catch (NumberFormatException nfe) { 149 catch (NumberFormatException nfe) {
142 // do nothing here 150 // do nothing here
143 } 151 }
144 } 152 }
145 153
146 return label; 154 return label.toString();
147 } 155 }
148 156
149 157
150 protected static String getSpecialLabel( 158 protected static String getSpecialLabel(
151 WINFOArtifact winfo, 159 WINFOArtifact winfo,
152 CallContext cc, 160 CallContext cc,
153 String raw 161 String raw
154 ) { 162 ) {
155 String[] values = raw.split(" "); 163 String[] values = raw.split(" ");
156 String label = null; 164
165 if (values.length < 1) {
166 return null;
167 }
157 168
158 NumberFormat nf = NumberFormat.getInstance( 169 NumberFormat nf = NumberFormat.getInstance(
159 Resources.getLocale(cc.getMeta())); 170 Resources.getLocale(cc.getMeta()));
160 171
172 Gauge gauge = winfo.getGauge();
173
174 boolean debug = logger.isDebugEnabled();
175
176 StringBuilder label = new StringBuilder();
177
161 for (String value: values) { 178 for (String value: values) {
162 try { 179 try {
163 double v = Double.valueOf(value.trim()); 180 double v = Double.parseDouble(value.trim());
164 181
165 String tmp = nf.format(v); 182 String tmp = nf.format(v);
166 String mv = FLYSUtils.getNamedMainValue(winfo.getGauge(),v); 183 String mv = FLYSUtils.getNamedMainValue(gauge, v);
167 184
168 if (mv != null && mv.length() > 0) { 185 if (mv != null && mv.length() > 0) {
169 String add = mv + ": " + tmp; 186 tmp = mv + ": " + tmp;
170 logger.debug("Add main value: '" + mv + "'"); 187 if (debug) {
171 label = label != null ? label + ";" + add : add; 188 logger.debug("Add main value: '" + mv + "'");
189 }
172 } 190 }
173 else { 191 if (label.length() > 0) {
174 logger.debug("Add non main value: '" + tmp + "'"); 192 label.append(';');
175 label = label != null ? label + ";" + tmp : tmp;
176 } 193 }
194 label.append(tmp);
177 } 195 }
178 catch (NumberFormatException nfe) { 196 catch (NumberFormatException nfe) {
179 // do nothing here 197 // do nothing here
180 } 198 }
181 } 199 }
182 200
183 return label; 201 return label.toString();
184 } 202 }
185 203
186 204
187 @Override 205 @Override
188 protected Element createData( 206 protected Element createData(

http://dive4elements.wald.intevation.org