Mercurial > dive4elements > river
annotate artifacts/src/main/java/org/dive4elements/river/artifacts/states/AddTableDataHelper.java @ 9479:2b83d3a96703
i18n TODO "benutzerdefiniert" = "custom" fixed
author | gernotbelger |
---|---|
date | Mon, 10 Sep 2018 15:31:55 +0200 |
parents | 2b13de1b0897 |
children |
rev | line source |
---|---|
9074 | 1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
2 * Software engineering by | |
3 * Björnsen Beratende Ingenieure GmbH | |
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt | |
5 * | |
6 * This file is Free Software under the GNU AGPL (>=v3) | |
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the | |
8 * documentation coming with Dive4Elements River for details. | |
9 */ | |
10 package org.dive4elements.river.artifacts.states; | |
11 | |
12 import java.util.ArrayList; | |
13 import java.util.HashMap; | |
14 import java.util.List; | |
15 import java.util.Map; | |
16 import java.util.Map.Entry; | |
17 | |
18 import org.dive4elements.artifacts.CallMeta; | |
19 import org.dive4elements.artifacts.common.utils.XMLUtils.ElementCreator; | |
20 import org.dive4elements.river.artifacts.resources.Resources; | |
21 import org.w3c.dom.Element; | |
22 | |
23 /** | |
24 * @author Domenico Nardi Tironi | |
25 * | |
26 */ | |
27 public class AddTableDataHelper { | |
28 | |
29 private final ElementCreator creator; | |
30 private final Element select; | |
31 private final CallMeta callmeta; | |
32 // Create Metadata: | |
33 final Map<String, Map<String, String>> meta = new HashMap<>(); | |
34 final List<String> columnValidList = new ArrayList<>(); | |
35 | |
36 public AddTableDataHelper(final ElementCreator creator, final Element select, final String pinKeyColumn, final CallMeta callMeta) { | |
37 this.creator = creator; | |
38 this.select = select; | |
39 this.callmeta = callMeta; | |
40 creator.addAttr(select, "type", "multiattribute", true); | |
41 | |
42 final Map<String, String> metaTableInfo = new HashMap<>(); | |
43 metaTableInfo.put("keycol", pinKeyColumn); | |
44 this.meta.put("meta_tableinfo", metaTableInfo); | |
45 | |
46 } | |
47 | |
48 public void submitMapToXml() { | |
49 | |
50 final Element meta = this.creator.create("meta"); | |
51 | |
52 for (final Entry<String, Map<String, String>> entry : this.meta.entrySet()) { | |
53 final String name = entry.getKey(); // z.B. Spaltenname | |
54 final Map<String, String> keyValueMap = entry.getValue(); | |
55 final Element element = this.creator.create(name); | |
56 | |
57 for (final Entry<String, String> kventry : keyValueMap.entrySet()) { | |
58 this.creator.addAttr(element, kventry.getKey(), kventry.getValue()); | |
59 } | |
60 meta.appendChild(element); | |
61 } | |
62 | |
63 this.select.appendChild(meta); | |
64 | |
65 } | |
66 | |
9077
2b13de1b0897
moved single_year/multi_year common code to AbstractPanel
gernotbelger
parents:
9074
diff
changeset
|
67 public void addRow(final Map<String, String> colValMap) { |
9074 | 68 |
69 final Element item = this.creator.create("item"); | |
70 | |
71 for (final Entry<String, String> entry : colValMap.entrySet()) { | |
72 if (this.meta.containsKey(entry.getKey())) { | |
73 this.creator.addAttr(item, entry.getKey(), entry.getValue() != null ? entry.getValue().toString() : ""); | |
74 } else { | |
9077
2b13de1b0897
moved single_year/multi_year common code to AbstractPanel
gernotbelger
parents:
9074
diff
changeset
|
75 try { |
2b13de1b0897
moved single_year/multi_year common code to AbstractPanel
gernotbelger
parents:
9074
diff
changeset
|
76 throw new Exception("Error: No such column " + entry.getKey()); |
2b13de1b0897
moved single_year/multi_year common code to AbstractPanel
gernotbelger
parents:
9074
diff
changeset
|
77 } |
2b13de1b0897
moved single_year/multi_year common code to AbstractPanel
gernotbelger
parents:
9074
diff
changeset
|
78 catch (final Exception e) { |
2b13de1b0897
moved single_year/multi_year common code to AbstractPanel
gernotbelger
parents:
9074
diff
changeset
|
79 e.printStackTrace(); |
2b13de1b0897
moved single_year/multi_year common code to AbstractPanel
gernotbelger
parents:
9074
diff
changeset
|
80 } |
9074 | 81 } |
82 } | |
83 this.select.appendChild(item); | |
84 } | |
85 | |
86 public void addColumn(final int order, final String rootHashmapKey, final String colWidth, final String translationKeyFromMessages, final String type, | |
87 final String alignment, final String pinType) { | |
88 | |
89 final Map<String, String> map = new HashMap<>(); | |
90 map.put("colwidth", colWidth); | |
91 final String translation = Resources.getMsg(this.callmeta, translationKeyFromMessages); | |
92 map.put("translation", translation); | |
93 map.put("type", type); | |
94 map.put("alignment", alignment); | |
95 map.put("order", Integer.toString(order)); | |
96 map.put("pin", pinType); | |
97 this.meta.put(rootHashmapKey, map); | |
98 | |
99 } | |
100 | |
101 } |