Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelPairSelectState.java @ 3468:f37e7e8907cb
merged flys-artifacts/2.8.1
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:14:39 +0200 |
parents | 5642a83420f2 |
children |
comparison
equal
deleted
inserted
replaced
3387:5ffad8bde8ad | 3468:f37e7e8907cb |
---|---|
1 package de.intevation.flys.artifacts.states; | |
2 | |
3 import java.util.List; | |
4 | |
5 import org.apache.log4j.Logger; | |
6 | |
7 import org.w3c.dom.Element; | |
8 | |
9 import de.intevation.artifacts.Artifact; | |
10 import de.intevation.artifacts.CallContext; | |
11 | |
12 import de.intevation.artifactdatabase.ProtocolUtils; | |
13 import de.intevation.artifactdatabase.state.Facet; | |
14 | |
15 import de.intevation.artifacts.common.utils.XMLUtils.ElementCreator; | |
16 | |
17 import de.intevation.flys.artifacts.FLYSArtifact; | |
18 import de.intevation.flys.artifacts.model.FacetTypes; | |
19 import de.intevation.flys.artifacts.resources.Resources; | |
20 | |
21 import de.intevation.flys.utils.StringUtil; | |
22 | |
23 /** | |
24 * State in which the user selects 1 to n pairs of Waterlevels and alikes. | |
25 */ | |
26 public class WaterlevelPairSelectState | |
27 extends DefaultState | |
28 implements FacetTypes | |
29 { | |
30 /** The logger that is used in this state. */ | |
31 private static Logger logger = Logger.getLogger( | |
32 WaterlevelPairSelectState.class); | |
33 | |
34 | |
35 /** Trivial constructor. */ | |
36 public WaterlevelPairSelectState() { | |
37 } | |
38 | |
39 | |
40 /** Specify to display a datacage_twin_panel. */ | |
41 @Override | |
42 protected String getUIProvider() { | |
43 return "datacage_twin_panel"; | |
44 } | |
45 | |
46 | |
47 /** | |
48 * Overridden to do nothing. | |
49 */ | |
50 @Override | |
51 public Object computeAdvance( | |
52 FLYSArtifact artifact, | |
53 String hash, | |
54 CallContext context, | |
55 List<Facet> facets, | |
56 Object old | |
57 ) { | |
58 //Get data and do stuff, do not calculate | |
59 return ""; | |
60 } | |
61 | |
62 | |
63 /** | |
64 * Create elements for document (prepopulated with data, if any). | |
65 * @param artifact FLYSArtifact to get data from. | |
66 * @param name DataName, expceted to be "diffids". | |
67 */ | |
68 @Override | |
69 protected Element[] createItems( | |
70 ElementCreator cr, | |
71 Artifact artifact, | |
72 String name, | |
73 CallContext context) | |
74 { | |
75 logger.debug("createItems: " + name); | |
76 if (name.equals("diffids")) { | |
77 Element item = ProtocolUtils.createArtNode(cr, "item", null, null); | |
78 Element label = ProtocolUtils.createArtNode(cr, "label", null, null); | |
79 Element value = ProtocolUtils.createArtNode(cr, "value", null, null); | |
80 FLYSArtifact flys = (FLYSArtifact) artifact; | |
81 String s = flys.getDataAsString("diffids"); | |
82 value.setTextContent(s); | |
83 item.appendChild(label); | |
84 item.appendChild(value); | |
85 return new Element[] { item }; | |
86 } | |
87 return new Element[] {}; | |
88 } | |
89 | |
90 | |
91 /** | |
92 * Creats the data element used for the static part of DESCRIBE document. | |
93 */ | |
94 @Override | |
95 protected Element createStaticData( | |
96 FLYSArtifact flys, | |
97 ElementCreator creator, | |
98 CallContext cc, | |
99 String name, | |
100 String value, | |
101 String type | |
102 ) { | |
103 Element dataElement = creator.create("data"); | |
104 creator.addAttr(dataElement, "name", name, true); | |
105 creator.addAttr(dataElement, "type", type, true); | |
106 | |
107 Element itemElement = creator.create("item"); | |
108 creator.addAttr(itemElement, "value", value, true); | |
109 | |
110 String[] labels = getLabels(cc, value); | |
111 Object[] obj = new Object[] { labels[0] }; | |
112 | |
113 // TODO own i18n | |
114 String attrValue = Resources.getMsg( | |
115 cc.getMeta(), "wsp.selected.string", "wsp.selected.string", obj); | |
116 //I18N_STATIC_KEY, I18N_STATIC_KEY, obj); | |
117 | |
118 creator.addAttr(itemElement, "label", attrValue, true); | |
119 dataElement.appendChild(itemElement); | |
120 | |
121 return dataElement; | |
122 } | |
123 | |
124 | |
125 /** | |
126 * Get name to display for selected watelerlevels (for example "Q=123") | |
127 * from the CalculationResult. | |
128 */ | |
129 public static String[] getLabels(CallContext cc, String value) { | |
130 String[] recommendations = value.split("#"); | |
131 String displayString = ""; | |
132 | |
133 // Walk over all selected recommendations and create label | |
134 // like "W (Q=1) - W (Q=2)". | |
135 for (int i = 0; i < recommendations.length; i+=2) { | |
136 String[] minuendParts = StringUtil | |
137 .unbracket(recommendations[i+0]) | |
138 .split(";"); | |
139 if(minuendParts.length >= 4) { | |
140 displayString += "(" + minuendParts[3]; | |
141 } | |
142 else { | |
143 displayString += "([error]"; | |
144 } | |
145 | |
146 displayString += " - "; | |
147 | |
148 String[] subtrahendParts = StringUtil | |
149 .unbracket(recommendations[i+1]) | |
150 .split(";"); | |
151 if(subtrahendParts.length >= 4) { | |
152 displayString += subtrahendParts[3] + ") "; | |
153 } | |
154 else { | |
155 displayString += "[error])"; | |
156 } | |
157 } | |
158 | |
159 return new String[] { displayString }; | |
160 } | |
161 } | |
162 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |