comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/chart/ManualWSPEditor.java @ 4568:bbd82bd8e541

flys-client: Cosmetics and warnings.
author Christian Lins <christian.lins@intevation.de>
date Mon, 19 Nov 2012 00:07:53 +0100
parents 22f39c2d7a72
children
comparison
equal deleted inserted replaced
4567:5e6e89f19a37 4568:bbd82bd8e541
1 package de.intevation.flys.client.client.ui.chart; 1 package de.intevation.flys.client.client.ui.chart;
2 2
3 import com.google.gwt.core.client.GWT; 3 import com.google.gwt.core.client.GWT;
4
5 import com.google.gwt.i18n.client.NumberFormat; 4 import com.google.gwt.i18n.client.NumberFormat;
6
7 import com.google.gwt.json.client.JSONArray; 5 import com.google.gwt.json.client.JSONArray;
8 import com.google.gwt.json.client.JSONNumber; 6 import com.google.gwt.json.client.JSONNumber;
9 import com.google.gwt.json.client.JSONParser; 7 import com.google.gwt.json.client.JSONParser;
10 import com.google.gwt.json.client.JSONString; 8 import com.google.gwt.json.client.JSONString;
11
12 import com.google.gwt.user.client.rpc.AsyncCallback; 9 import com.google.gwt.user.client.rpc.AsyncCallback;
13 10
14 import com.smartgwt.client.types.Alignment; 11 import com.smartgwt.client.types.Alignment;
15
16 import com.smartgwt.client.util.SC; 12 import com.smartgwt.client.util.SC;
17
18 import com.smartgwt.client.widgets.Button; 13 import com.smartgwt.client.widgets.Button;
19 import com.smartgwt.client.widgets.Label; 14 import com.smartgwt.client.widgets.Label;
20 import com.smartgwt.client.widgets.Window; 15 import com.smartgwt.client.widgets.Window;
21
22 import com.smartgwt.client.widgets.events.ClickEvent; 16 import com.smartgwt.client.widgets.events.ClickEvent;
23 import com.smartgwt.client.widgets.events.ClickHandler; 17 import com.smartgwt.client.widgets.events.ClickHandler;
24
25 import com.smartgwt.client.widgets.form.DynamicForm; 18 import com.smartgwt.client.widgets.form.DynamicForm;
26
27 import com.smartgwt.client.widgets.form.fields.TextItem; 19 import com.smartgwt.client.widgets.form.fields.TextItem;
28
29 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; 20 import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
30 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; 21 import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
31
32 import com.smartgwt.client.widgets.layout.HLayout; 22 import com.smartgwt.client.widgets.layout.HLayout;
33 import com.smartgwt.client.widgets.layout.VLayout; 23 import com.smartgwt.client.widgets.layout.VLayout;
34 24
35 import de.intevation.flys.client.client.Config; 25 import de.intevation.flys.client.client.Config;
36 import de.intevation.flys.client.client.FLYSConstants; 26 import de.intevation.flys.client.client.FLYSConstants;
37
38 import de.intevation.flys.client.client.event.RedrawRequestEvent; 27 import de.intevation.flys.client.client.event.RedrawRequestEvent;
39 import de.intevation.flys.client.client.event.RedrawRequestHandler; 28 import de.intevation.flys.client.client.event.RedrawRequestHandler;
40
41 import de.intevation.flys.client.client.services.FeedService;
42 import de.intevation.flys.client.client.services.FeedServiceAsync; 29 import de.intevation.flys.client.client.services.FeedServiceAsync;
43 import de.intevation.flys.client.client.services.LoadArtifactService;
44 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync; 30 import de.intevation.flys.client.client.services.LoadArtifactServiceAsync;
45
46 import de.intevation.flys.client.client.utils.DoubleValidator; 31 import de.intevation.flys.client.client.utils.DoubleValidator;
47
48 import de.intevation.flys.client.shared.model.Artifact; 32 import de.intevation.flys.client.shared.model.Artifact;
49 import de.intevation.flys.client.shared.model.Collection; 33 import de.intevation.flys.client.shared.model.Collection;
50 import de.intevation.flys.client.shared.model.CollectionItem; 34 import de.intevation.flys.client.shared.model.CollectionItem;
51 import de.intevation.flys.client.shared.model.Data; 35 import de.intevation.flys.client.shared.model.Data;
52 import de.intevation.flys.client.shared.model.DefaultArtifact; 36 import de.intevation.flys.client.shared.model.DefaultArtifact;
71 protected FLYSConstants MSG = GWT.create(FLYSConstants.class); 55 protected FLYSConstants MSG = GWT.create(FLYSConstants.class);
72 56
73 /** Name of the main data item to be fed. */ 57 /** Name of the main data item to be fed. */
74 public static final String LINE_DATA = "manualpoints.lines"; 58 public static final String LINE_DATA = "manualpoints.lines";
75 59
76 /** When we chaged something, we need a RedrawRequest(Handler). */ 60 /** When we change something, we need a RedrawRequest(Handler). */
77 protected RedrawRequestHandler redrawRequestHandler; 61 protected RedrawRequestHandler redrawRequestHandler;
78 62
79 /** The collection */ 63 /** The collection */
80 protected Collection collection; 64 protected Collection collection;
81 65
125 public String findManualPointsUUID() { 109 public String findManualPointsUUID() {
126 int size = collection.getItemLength(); 110 int size = collection.getItemLength();
127 111
128 for (int i = 0; i < size; i++) { 112 for (int i = 0; i < size; i++) {
129 CollectionItem item = collection.getItem(i); 113 CollectionItem item = collection.getItem(i);
130 String dataValue = (String) item.getData().get(dataItemName); 114 String dataValue = item.getData().get(dataItemName);
131 if (dataValue != null) { 115 if (dataValue != null) {
132 // Found it. 116 // Found it.
133 uuid = item.identifier(); 117 uuid = item.identifier();
134 return uuid; 118 return uuid;
135 } 119 }
156 } 140 }
157 141
158 142
159 /** Create and setup/add the ui. */ 143 /** Create and setup/add the ui. */
160 public void createUI() { 144 public void createUI() {
161 Config config = Config.getInstance();
162
163 Button accept = new Button(MSG.label_ok()); 145 Button accept = new Button(MSG.label_ok());
164 Button cancel = new Button(MSG.label_cancel()); 146 Button cancel = new Button(MSG.label_cancel());
165 cancel.addClickHandler(this); 147 cancel.addClickHandler(this);
166 148
167 accept.addClickHandler(new ClickHandler() { 149 accept.addClickHandler(new ClickHandler() {
150 @Override
168 public void onClick(ClickEvent e) { 151 public void onClick(ClickEvent e) {
169 okClicked(); 152 okClicked();
170 } 153 }
171 }); 154 });
172 155
198 DynamicForm form = new DynamicForm(); 181 DynamicForm form = new DynamicForm();
199 valueInputPanel = new TextItem(); 182 valueInputPanel = new TextItem();
200 valueInputPanel.setTitle(yAxis); 183 valueInputPanel.setTitle(yAxis);
201 valueInputPanel.setShowTitle(true); 184 valueInputPanel.setShowTitle(true);
202 valueInputPanel.addBlurHandler(new BlurHandler() { 185 valueInputPanel.addBlurHandler(new BlurHandler() {
186 @Override
203 public void onBlur(BlurEvent e) { 187 public void onBlur(BlurEvent e) {
204 DoubleValidator validator = new DoubleValidator(); 188 DoubleValidator validator = new DoubleValidator();
205 Map errors = e.getForm().getErrors(); 189 Map errors = e.getForm().getErrors();
206 validator.validate(e.getItem(), errors); 190 validator.validate(e.getItem(), errors);
207 e.getForm().setErrors(errors, true); 191 e.getForm().setErrors(errors, true);
246 protected JSONArray jsonArrayFromForm() { 230 protected JSONArray jsonArrayFromForm() {
247 if (oldLines == null) { 231 if (oldLines == null) {
248 oldLines = new JSONArray(); 232 oldLines = new JSONArray();
249 } 233 }
250 234
251 int idx = 0;
252 double val; 235 double val;
253 if (valueInputPanel.getValue() == null) 236 if (valueInputPanel.getValue() == null)
254 return oldLines; 237 return oldLines;
255 try { 238 try {
256 NumberFormat nf = NumberFormat.getDecimalFormat(); 239 NumberFormat nf = NumberFormat.getDecimalFormat();
257 double d = nf.parse(valueInputPanel.getValue().toString()); 240 double d = nf.parse(valueInputPanel.getValue().toString());
258 val = d; 241 val = d;
259 } 242 }
260 catch(NumberFormatException nfe) { 243 catch(NumberFormatException nfe) {
261 SC.warn("fehler... nfe... TODO"); 244 GWT.log("fehler... nfe... TODO");
262 return oldLines; 245 return oldLines;
263 } 246 }
264 247
265 JSONArray data = new JSONArray(); 248 JSONArray data = new JSONArray();
266 data.set(0, new JSONNumber(val)); 249 data.set(0, new JSONNumber(val));
297 feedService.feed( 280 feedService.feed(
298 Config.getInstance().getLocale(), 281 Config.getInstance().getLocale(),
299 new DefaultArtifact(uuid, "TODO:hash"), 282 new DefaultArtifact(uuid, "TODO:hash"),
300 feedData, 283 feedData,
301 new AsyncCallback<Artifact>() { 284 new AsyncCallback<Artifact>() {
285 @Override
302 public void onFailure(Throwable caught) { 286 public void onFailure(Throwable caught) {
303 GWT.log("Could not feed artifact with lines."); 287 GWT.log("Could not feed artifact with lines.");
304 SC.warn(MSG.getString(caught.getMessage())); 288 SC.warn(MSG.getString(caught.getMessage()));
305 enable(); 289 enable();
306 } 290 }
291 @Override
307 public void onSuccess(Artifact fartifact) { 292 public void onSuccess(Artifact fartifact) {
308 GWT.log("Successfully set lines "); 293 GWT.log("Successfully set lines ");
309 redrawRequestHandler.onRedrawRequest( 294 redrawRequestHandler.onRedrawRequest(
310 new RedrawRequestEvent()); 295 new RedrawRequestEvent());
311 destroy(); 296 destroy();
335 this.collection, 320 this.collection,
336 new Recommendation("manualpoints", ""), 321 new Recommendation("manualpoints", ""),
337 "manualpoints", 322 "manualpoints",
338 locale, 323 locale,
339 new AsyncCallback<Artifact>() { 324 new AsyncCallback<Artifact>() {
325 @Override
340 public void onFailure(Throwable caught) { 326 public void onFailure(Throwable caught) {
341 GWT.log("Creating manualpoint artifact failed!"); 327 GWT.log("Creating manualpoint artifact failed!");
342 } 328 }
329 @Override
343 public void onSuccess(Artifact artifact) { 330 public void onSuccess(Artifact artifact) {
344 GWT.log("Successfully created artifact."); 331 GWT.log("Successfully created artifact.");
345 removeItem(standByLabel); 332 removeItem(standByLabel);
346 uuid = artifact.getUuid(); 333 uuid = artifact.getUuid();
347 createUI(); 334 createUI();
352 339
353 /** 340 /**
354 * This method is called when the user aborts point editing. 341 * This method is called when the user aborts point editing.
355 * @param event The event. 342 * @param event The event.
356 */ 343 */
344 @Override
357 public void onClick(ClickEvent event) { 345 public void onClick(ClickEvent event) {
358 this.destroy(); 346 this.destroy();
359 } 347 }
360 348
361 349

http://dive4elements.wald.intevation.org