Mercurial > dive4elements > river
comparison flys-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractUIProvider.java @ 5834:f507086aa94b
Repaired internal references.
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Thu, 25 Apr 2013 12:31:32 +0200 |
parents | flys-client/src/main/java/de/intevation/flys/client/client/ui/AbstractUIProvider.java@995320711d80 |
children | 821a02bbfb4e |
comparison
equal
deleted
inserted
replaced
5833:a2bdc0f524e8 | 5834:f507086aa94b |
---|---|
1 package de.intevation.flys.client.client.ui; | |
2 | |
3 import com.google.gwt.core.client.GWT; | |
4 | |
5 import com.smartgwt.client.util.SC; | |
6 import com.smartgwt.client.widgets.Button; | |
7 import com.smartgwt.client.widgets.Canvas; | |
8 import com.smartgwt.client.widgets.Img; | |
9 import com.smartgwt.client.widgets.events.ClickEvent; | |
10 import com.smartgwt.client.widgets.events.ClickHandler; | |
11 import com.smartgwt.client.widgets.layout.VLayout; | |
12 | |
13 import de.intevation.flys.client.client.FLYSConstants; | |
14 import de.intevation.flys.client.client.event.HasStepBackHandlers; | |
15 import de.intevation.flys.client.client.event.HasStepForwardHandlers; | |
16 import de.intevation.flys.client.client.event.StepBackEvent; | |
17 import de.intevation.flys.client.client.event.StepBackHandler; | |
18 import de.intevation.flys.client.client.event.StepForwardEvent; | |
19 import de.intevation.flys.client.client.event.StepForwardHandler; | |
20 import de.intevation.flys.client.shared.model.Artifact; | |
21 import de.intevation.flys.client.shared.model.ArtifactDescription; | |
22 import de.intevation.flys.client.shared.model.Collection; | |
23 import de.intevation.flys.client.shared.model.Data; | |
24 import de.intevation.flys.client.shared.model.DataItem; | |
25 import de.intevation.flys.client.shared.model.DataList; | |
26 import de.intevation.flys.client.shared.model.DefaultData; | |
27 import de.intevation.flys.client.shared.model.DefaultDataItem; | |
28 | |
29 import java.util.ArrayList; | |
30 import java.util.List; | |
31 | |
32 | |
33 /** | |
34 * An abstract UIProvider that provides some basic methods. | |
35 * | |
36 * @author <a href="mailto:ingo.weinzierl@intevation.de">Ingo Weinzierl</a> | |
37 */ | |
38 public abstract class AbstractUIProvider | |
39 implements UIProvider, HasStepForwardHandlers, ClickHandler, | |
40 HasStepBackHandlers | |
41 { | |
42 private static final long serialVersionUID = -1610874613377494184L; | |
43 | |
44 /** The message class that provides i18n strings. */ | |
45 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); | |
46 | |
47 /** The StepForwardHandlers. */ | |
48 protected List<StepForwardHandler> forwardHandlers; | |
49 | |
50 /** The StepForwardHandlers. */ | |
51 protected List<StepBackHandler> backHandlers; | |
52 | |
53 /** The container that is used to position helper widgets. */ | |
54 protected VLayout helperContainer; | |
55 | |
56 /** The artifact that contains status information. */ | |
57 protected Artifact artifact; | |
58 | |
59 /** The Collection. */ | |
60 protected Collection collection; | |
61 | |
62 /** The ParameterList. */ | |
63 protected ParameterList parameterList; | |
64 | |
65 /** | |
66 * Creates a new UIProvider instance of this class. | |
67 */ | |
68 public AbstractUIProvider() { | |
69 forwardHandlers = new ArrayList<StepForwardHandler>(); | |
70 backHandlers = new ArrayList<StepBackHandler>(); | |
71 } | |
72 | |
73 | |
74 /** | |
75 * Appends a StepBackHandler that wants to listen to StepBackEvents. | |
76 * | |
77 * @param handler A new StepBackHandler. | |
78 */ | |
79 @Override | |
80 public void addStepBackHandler(StepBackHandler handler) { | |
81 if (handler != null) { | |
82 backHandlers.add(handler); | |
83 } | |
84 } | |
85 | |
86 | |
87 /** | |
88 * Appends a StepForwardHandler that wants to listen to StepForwardEvents. | |
89 * | |
90 * @param handler A new StepForwardHandler. | |
91 */ | |
92 @Override | |
93 public void addStepForwardHandler(StepForwardHandler handler) { | |
94 if (handler != null) { | |
95 forwardHandlers.add(handler); | |
96 } | |
97 } | |
98 | |
99 | |
100 /** | |
101 * This method is called after the user has clicked one of the buttons to | |
102 * step back to a previous state. | |
103 * | |
104 * @param e The StepBackEvent. | |
105 */ | |
106 protected void fireStepBackEvent(StepBackEvent e) { | |
107 GWT.log("AbstractUIProvider - fireStepBackEvent() handlers: " + backHandlers.size()); | |
108 for (StepBackHandler handler: backHandlers) { | |
109 handler.onStepBack(e); | |
110 } | |
111 } | |
112 | |
113 | |
114 /** | |
115 * This method is called after the user has clicked on the 'next' button to | |
116 * step to the next state. | |
117 * | |
118 * @param e The StepForwardEvent. | |
119 */ | |
120 protected void fireStepForwardEvent(StepForwardEvent e) { | |
121 GWT.log("AbstractUIProvider - fireStepForwardEvent() handlers: " + forwardHandlers.size()); | |
122 for (StepForwardHandler handler: forwardHandlers) { | |
123 handler.onStepForward(e); | |
124 } | |
125 } | |
126 | |
127 | |
128 /** | |
129 * This method is used to listen to click events on the 'next' button. The | |
130 * fireStepForwardEvent() method is called here. | |
131 * | |
132 * @param e The click event. | |
133 */ | |
134 @Override | |
135 public void onClick(ClickEvent e) { | |
136 List<String> errors = validate(); | |
137 if (errors == null || errors.isEmpty()) { | |
138 Data[] data = getData(); | |
139 fireStepForwardEvent(new StepForwardEvent(data)); | |
140 } | |
141 else { | |
142 showErrors(errors); | |
143 } | |
144 } | |
145 | |
146 | |
147 protected void showErrors(List<String> errors) { | |
148 StringBuilder sb = new StringBuilder(); | |
149 | |
150 for (String error: errors) { | |
151 sb.append(error); | |
152 sb.append("<br>"); | |
153 } | |
154 | |
155 SC.warn(sb.toString()); | |
156 } | |
157 | |
158 | |
159 /** | |
160 * Creates the 'next' button to step forward to the next state. | |
161 * | |
162 * @return the 'next' button. | |
163 */ | |
164 protected Canvas getNextButton() { | |
165 Button next = new Button(MSG.buttonNext()); | |
166 next.addClickHandler(this); | |
167 | |
168 return next; | |
169 } | |
170 | |
171 | |
172 @Override | |
173 public Canvas createHelpLink(DataList dataList, Data data) { | |
174 String iUrl = GWT.getHostPageBaseURL() + MSG.getFeatureInfo(); | |
175 String helpUrl = dataList.getHelpText(); | |
176 | |
177 return new ImgLink(iUrl, helpUrl, 30, 30, true); | |
178 } | |
179 | |
180 | |
181 /** | |
182 * Creates the 'back' button to step back to a previous state. | |
183 * | |
184 * @param targetState The identifier of the target state. | |
185 * | |
186 * @return the 'back' button. | |
187 */ | |
188 protected Canvas getBackButton(final String targetState) { | |
189 String url = GWT.getHostPageBaseURL() + MSG.imageBack(); | |
190 Img back = new Img(url, 16, 16); | |
191 | |
192 back.addClickHandler(new ClickHandler() { | |
193 @Override | |
194 public void onClick(ClickEvent event) { | |
195 fireStepBackEvent(new StepBackEvent(targetState)); | |
196 } | |
197 }); | |
198 | |
199 return back; | |
200 } | |
201 | |
202 | |
203 /** | |
204 * This method injects a container that is used to position helper widgets. | |
205 * | |
206 * @param helperContainer A container that is used to position helper | |
207 * widgets. | |
208 */ | |
209 @Override | |
210 public void setContainer(VLayout helperContainer) { | |
211 this.helperContainer = helperContainer; | |
212 } | |
213 | |
214 | |
215 /** | |
216 * This method injects an artifact that contains the status information. | |
217 * | |
218 * @param art An artifact containing status information. | |
219 */ | |
220 @Override | |
221 public void setArtifact(Artifact art) { | |
222 this.artifact = art; | |
223 } | |
224 | |
225 | |
226 @Override | |
227 public void setCollection(Collection collection) { | |
228 this.collection = collection; | |
229 } | |
230 | |
231 | |
232 @Override | |
233 public void setParameterList(ParameterList list) { | |
234 this.parameterList = list; | |
235 } | |
236 | |
237 | |
238 public Collection getCollection() { | |
239 return collection; | |
240 } | |
241 | |
242 | |
243 /** | |
244 * This method greps the Data with name <i>name</i> from the list and | |
245 * returns it. | |
246 * | |
247 * @param items A list of Data. | |
248 * @param name The name of the Data that we are searching for. | |
249 * | |
250 * @return the Data with the name <i>name</i>. | |
251 */ | |
252 protected Data getData(List<Data> data, String name) { | |
253 for (Data d: data) { | |
254 if (name.equals(d.getLabel())) { | |
255 return d; | |
256 } | |
257 } | |
258 | |
259 return null; | |
260 } | |
261 | |
262 | |
263 protected String getDataValue(String state, String name) { | |
264 ArtifactDescription desc = artifact.getArtifactDescription(); | |
265 | |
266 DataList[] old = desc.getOldData(); | |
267 | |
268 for (DataList list: old) { | |
269 if (list == null) { | |
270 continue; | |
271 } | |
272 Data d = getData(list.getAll(), name); | |
273 | |
274 if (d != null) { | |
275 return d.getItems()[0].getStringValue(); | |
276 } | |
277 } | |
278 | |
279 return null; | |
280 } | |
281 | |
282 /** | |
283 * This method greps the DataItem with name <i>name</i> from the list and | |
284 * returns it. | |
285 * | |
286 * @param items A list of DataItems. | |
287 * @param name The name of the DataItem that we are searching for. | |
288 * | |
289 * @return the DataItem with the name <i>name</i>. | |
290 */ | |
291 protected DataItem getDataItem(DataItem[] items, String name) { | |
292 for (DataItem item: items) { | |
293 if (name.equals(item.getLabel())) { | |
294 return item; | |
295 } | |
296 } | |
297 | |
298 return null; | |
299 } | |
300 | |
301 | |
302 public List<String> validate() { | |
303 return new ArrayList<String>(); // FIXME: What's this? | |
304 } | |
305 | |
306 | |
307 /** Create simple DefaultData with single DataItem inside. */ | |
308 public static DefaultData createDataArray(String name, String value) { | |
309 DataItem item = new DefaultDataItem( | |
310 name, | |
311 name, | |
312 value); | |
313 | |
314 return new DefaultData(name, | |
315 null, | |
316 null, | |
317 new DataItem[] {item}); | |
318 } | |
319 | |
320 | |
321 /** | |
322 * This method needs to be implemented by concrete subclasses. It should | |
323 * create a new Canvas object with a representation of <i>data</i>. | |
324 * | |
325 * @param data The data that should be displayed. | |
326 * | |
327 * @return a Canvas object that displays <i>data</i>. | |
328 */ | |
329 @Override | |
330 public abstract Canvas create(DataList data); | |
331 | |
332 | |
333 /** | |
334 * This method needs to be implemented by concrete subclasses. It should | |
335 * return the selected data. | |
336 * | |
337 * @return the selected data. | |
338 */ | |
339 protected abstract Data[] getData(); | |
340 } | |
341 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |