comparison gnv-artifacts/src/main/java/de/intevation/gnv/state/StateBase.java @ 615:01054ddccb0f

Repaired multi parameter selection. gnv-artifacts/trunk@685 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Fri, 12 Feb 2010 15:36:05 +0000
parents e80e37b78302
children 65f09139e9b3
comparison
equal deleted inserted replaced
614:e80e37b78302 615:01054ddccb0f
223 } 223 }
224 224
225 boolean valid = iv.isInputValid(tmpItem.getValue(), 225 boolean valid = iv.isInputValid(tmpItem.getValue(),
226 inputValue.getType()); 226 inputValue.getType());
227 if (valid) { 227 if (valid) {
228 String desc = getDescriptionForInputData(tmpItem, uuid); 228 String[] desc = getDescriptionForInputData(tmpItem, uuid);
229 tmpItem.setDescription(desc); 229 tmpItem.setDescription(desc);
230 this.inputData.put(tmpItem.getName(), tmpItem); 230 this.inputData.put(tmpItem.getName(), tmpItem);
231 } else { 231 } else {
232 String errMsg = "Wrong input for " + tmpItem.getValue() 232 String errMsg = "Wrong input for " + tmpItem.getValue()
233 + " is not an " + inputValue.getType() 233 + " is not an " + inputValue.getType()
247 log.warn("No Inputdata given"); 247 log.warn("No Inputdata given");
248 } 248 }
249 } 249 }
250 250
251 251
252 private String getDescriptionForInputData(InputData data, String uuid) { 252 private String[] getDescriptionForInputData(InputData data, String uuid) {
253 // there is only one element in the list, so take the first 253 // there is only one element in the list, so take the first
254 Object obj = getDescibeData(uuid).get(0); 254 Object obj = getDescibeData(uuid).get(0);
255 List descs = new ArrayList();
255 256
256 if (obj instanceof NamedArrayList) { 257 if (obj instanceof NamedArrayList) {
257 NamedArrayList list = (NamedArrayList) obj; 258 NamedArrayList list = (NamedArrayList) obj;
259 String[] selected = data.splitValue();
258 int size = list.size(); 260 int size = list.size();
261 int ssize = selected.length;
259 262
260 for (int i = 0; i < size; i++) { 263 for (int i = 0; i < size; i++) {
261 KeyValueDescibeData kv = (KeyValueDescibeData) list.get(i); 264 KeyValueDescibeData kv = (KeyValueDescibeData) list.get(i);
262 265
263 if (kv.getKey().equals(data.getValue())) { 266 // values are concatinated in InputData, so one InputData object can
264 return kv.getValue(); 267 // contain many input
265 } 268 for (int j = 0; j < ssize; j++) {
266 } 269 if (kv.getKey().equals(selected[j])) {
267 } 270 descs.add(kv.getValue());
268 271 }
269 return data.getValue(); 272 }
273 }
274 }
275
276 return (String[]) descs.toArray(new String[descs.size()]);
270 } 277 }
271 278
272 279
273 /** 280 /**
274 * @see de.intevation.gnv.state.State#putInputData(java.util.Collection) 281 * @see de.intevation.gnv.state.State#putInputData(java.util.Collection)
673 Element lableNode = creator.create("label"); 680 Element lableNode = creator.create("label");
674 lableNode.setTextContent(RessourceFactory.getInstance() 681 lableNode.setTextContent(RessourceFactory.getInstance()
675 .getRessource(callMeta.getLanguages(), dataName, dataName)); 682 .getRessource(callMeta.getLanguages(), dataName, dataName));
676 Element choiceNode = creator.create("choices"); 683 Element choiceNode = creator.create("choices");
677 684
678 /* TODO InputData can have more than 1 value if multiselect, implement a
679 * loop over these values
680
681 while (resultIt.hasNext()) {
682 KeyValueDescibeData result = resultIt.next();
683 */
684
685 artCreator.addAttr( 685 artCreator.addAttr(
686 selectNode, "state", getID(), true 686 selectNode, "state", getID(), true
687 ); 687 );
688 688
689 Element itemNode = creator.create("item"); 689 String[] descriptions = data.getDescription();
690 690 int size = descriptions.length;
691 creator.addAttr(itemNode, "selected", "true"); 691
692 692 for (int i = 0; i < size; i++) {
693 Element choiceLableNode = creator.create("label"); 693 Element itemNode = creator.create("item");
694 choiceLableNode.setTextContent(data.getDescription()); 694
695 itemNode.appendChild(choiceLableNode); 695 creator.addAttr(itemNode, "selected", "true");
696 696
697 Element choiceValueNode = creator.create("value"); 697 Element choiceLableNode = creator.create("label");
698 choiceValueNode.setTextContent(dataName); 698 choiceLableNode.setTextContent(descriptions[i]);
699 itemNode.appendChild(choiceValueNode); 699 itemNode.appendChild(choiceLableNode);
700 choiceNode.appendChild(itemNode); 700
701 /* 701 Element choiceValueNode = creator.create("value");
702 } 702 choiceValueNode.setTextContent(dataName);
703 */ 703 itemNode.appendChild(choiceValueNode);
704 choiceNode.appendChild(itemNode);
705 }
706
704 selectNode.appendChild(lableNode); 707 selectNode.appendChild(lableNode);
705 selectNode.appendChild(choiceNode); 708 selectNode.appendChild(choiceNode);
706 709
707 staticNode.appendChild(selectNode); 710 staticNode.appendChild(selectNode);
708 } 711 }
920 try { 923 try {
921 String[] filterValues = generateFilterValuesFromInputData(); 924 String[] filterValues = generateFilterValuesFromInputData();
922 List<Object> data = queryDatabase(filterValues, uuid); 925 List<Object> data = queryDatabase(filterValues, uuid);
923 926
924 cache.put(new net.sf.ehcache.Element(key, data)); 927 cache.put(new net.sf.ehcache.Element(key, data));
925
926 return data; 928 return data;
927 } 929 }
928 catch (QueryException qe) { 930 catch (QueryException qe) {
929 log.error(qe, qe); 931 log.error(qe, qe);
930 } 932 }

http://dive4elements.wald.intevation.org