Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/states/WaterlevelPairSelectState.java @ 1737:d26911cac2e4
Create label from data String to revive names in client.
flys-artifacts/trunk@3026 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Felix Wolfsteller <felix.wolfsteller@intevation.de> |
---|---|
date | Wed, 19 Oct 2011 11:00:13 +0000 |
parents | 2b9f0ca1449b |
children | 8a2cbf947395 |
comparison
equal
deleted
inserted
replaced
1736:0155cbaba182 | 1737:d26911cac2e4 |
---|---|
21 import de.intevation.flys.artifacts.resources.Resources; | 21 import de.intevation.flys.artifacts.resources.Resources; |
22 | 22 |
23 import de.intevation.flys.utils.FLYSUtils; | 23 import de.intevation.flys.utils.FLYSUtils; |
24 import de.intevation.flys.utils.StringUtil; | 24 import de.intevation.flys.utils.StringUtil; |
25 | 25 |
26 | 26 /** |
27 * State in which the user selects 1 to n pairs of Waterlevels and alikes. | |
28 */ | |
27 public class WaterlevelPairSelectState | 29 public class WaterlevelPairSelectState |
28 extends DefaultState | 30 extends DefaultState |
29 implements FacetTypes | 31 implements FacetTypes |
30 { | 32 { |
31 /** The logger that is used in this state. */ | 33 /** The logger that is used in this state. */ |
32 private static Logger logger = Logger.getLogger( | 34 private static Logger logger = Logger.getLogger( |
33 WaterlevelPairSelectState.class); | 35 WaterlevelPairSelectState.class); |
34 | 36 |
35 | 37 |
36 // TODO fix (state.winfo.waterlevel) | 38 /** Trivial constructor. */ |
37 // own id is state.winfo.waterlevel_pair_select | |
38 public static final String WINFO_WDIFFERENCES_STATE_ID | |
39 = "state.winfo.w_differences"; | |
40 | |
41 public WaterlevelPairSelectState() { | 39 public WaterlevelPairSelectState() { |
42 } | 40 } |
43 | 41 |
44 | 42 |
45 /** Specify to display a datacage_twin_panel. */ | 43 /** Specify to display a datacage_twin_panel. */ |
47 protected String getUIProvider() { | 45 protected String getUIProvider() { |
48 return "datacage_twin_panel"; | 46 return "datacage_twin_panel"; |
49 } | 47 } |
50 | 48 |
51 | 49 |
50 /** | |
51 * Overridden to do nothing. | |
52 */ | |
52 @Override | 53 @Override |
53 public Object computeAdvance( | 54 public Object computeAdvance( |
54 FLYSArtifact artifact, | 55 FLYSArtifact artifact, |
55 String hash, | 56 String hash, |
56 CallContext context, | 57 CallContext context, |
57 List<Facet> facets, | 58 List<Facet> facets, |
58 Object old | 59 Object old |
59 ) { | 60 ) { |
60 //Get data and do stuff, do not calculate | 61 //Get data and do stuff, do not calculate |
61 return old; | 62 return ""; |
62 } | 63 } |
63 | |
64 | 64 |
65 | 65 |
66 /** | 66 /** |
67 * Create elements for document (prepopulated with data, if any). | 67 * Create elements for document (prepopulated with data, if any). |
68 * @param artifact FLYSArtifact to get data from. | |
69 * @param name DataName, expceted to be "diffids". | |
68 */ | 70 */ |
69 @Override | 71 @Override |
70 protected Element[] createItems( | 72 protected Element[] createItems( |
71 ElementCreator cr, | 73 ElementCreator cr, |
72 Artifact artifact, | 74 Artifact artifact, |
120 | 122 |
121 return dataElement; | 123 return dataElement; |
122 } | 124 } |
123 | 125 |
124 | 126 |
125 // TODO merge implementations with WaterlevelSelectState | |
126 /** | 127 /** |
127 * Get name to display for selected watelerlevels (for example "Q=123") | 128 * Get name to display for selected watelerlevels (for example "Q=123") |
128 * from the CalculationResult. | 129 * from the CalculationResult. |
129 */ | 130 */ |
130 public static String[] getLabels(CallContext cc, String value) { | 131 public static String[] getLabels(CallContext cc, String value) { |
135 // like "W (Q=1) - W (Q=2)". | 136 // like "W (Q=1) - W (Q=2)". |
136 for (int i = 0; i < recommendations.length; i+=2) { | 137 for (int i = 0; i < recommendations.length; i+=2) { |
137 String[] minuendParts = StringUtil | 138 String[] minuendParts = StringUtil |
138 .unbracket(recommendations[i+0]) | 139 .unbracket(recommendations[i+0]) |
139 .split(";"); | 140 .split(";"); |
141 if(minuendParts.length >= 4) { | |
142 displayString += "(" + minuendParts[3]; | |
143 } | |
144 else { | |
145 displayString += "([error]"; | |
146 } | |
147 | |
148 displayString += " - "; | |
149 | |
140 String[] subtrahendParts = StringUtil | 150 String[] subtrahendParts = StringUtil |
141 .unbracket(recommendations[i+1]) | 151 .unbracket(recommendations[i+1]) |
142 .split(";"); | 152 .split(";"); |
143 | 153 if(subtrahendParts.length >= 4) { |
144 FLYSArtifact artifact1 = FLYSUtils.getArtifact(minuendParts[0], cc); | 154 displayString += subtrahendParts[3] + ") "; |
145 | |
146 CalculationResult rawData1 = (CalculationResult) artifact1.compute( | |
147 cc, | |
148 null, | |
149 "state.winfo.waterlevel", | |
150 ComputeType.ADVANCE, | |
151 false); | |
152 WQKms[] wqkms1 = (WQKms[]) rawData1.getData(); | |
153 | |
154 int idx1 = -1; | |
155 try { | |
156 idx1 = Integer.parseInt(minuendParts[2]); | |
157 } | 155 } |
158 catch (NumberFormatException nfe) { /* do nothing */ } | 156 else { |
159 | 157 displayString += "[error])"; |
160 FLYSArtifact artifact2 = FLYSUtils.getArtifact(subtrahendParts[0], cc); | |
161 | |
162 CalculationResult rawData2 = (CalculationResult) artifact2.compute( | |
163 cc, | |
164 null, | |
165 "state.winfo.waterlevel", | |
166 ComputeType.ADVANCE, | |
167 false); | |
168 WQKms[] wqkms2 = (WQKms[]) rawData2.getData(); | |
169 | |
170 int idx2 = -1; | |
171 try { | |
172 idx2 = Integer.parseInt(subtrahendParts[2]); | |
173 } | 158 } |
174 catch (NumberFormatException nfe) { /* do nothing */ } | |
175 | |
176 displayString += "(" + StringUtil.wWrap(wqkms1[idx1].getName()) | |
177 + " - " + StringUtil.wWrap(wqkms2[idx2].getName()) + ")"; | |
178 } | 159 } |
179 | 160 |
180 return new String[] { displayString }; | 161 return new String[] { displayString }; |
181 } | 162 } |
182 | |
183 } | 163 } |
184 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : | 164 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf-8 : |