comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/AbstractUIProvider.java @ 9066:b5d7a9d79837

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

http://dive4elements.wald.intevation.org