comparison flys-client/src/main/java/de/intevation/flys/client/client/ui/StyleEditorWindow.java @ 3355:dab808e5f516

Improve validation of double-type style arguments. flys-client/trunk@5038 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 18 Jul 2012 12:38:04 +0000
parents 2f533220af1c
children b31b0d249d21
comparison
equal deleted inserted replaced
3354:22f39c2d7a72 3355:dab808e5f516
21 import com.smartgwt.client.widgets.form.fields.events.BlurEvent; 21 import com.smartgwt.client.widgets.form.fields.events.BlurEvent;
22 import com.smartgwt.client.widgets.form.fields.events.BlurHandler; 22 import com.smartgwt.client.widgets.form.fields.events.BlurHandler;
23 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler; 23 import com.smartgwt.client.widgets.form.fields.events.ChangedHandler;
24 import com.smartgwt.client.widgets.layout.HLayout; 24 import com.smartgwt.client.widgets.layout.HLayout;
25 import com.smartgwt.client.widgets.layout.VLayout; 25 import com.smartgwt.client.widgets.layout.VLayout;
26 import com.smartgwt.client.widgets.form.validator.IsFloatValidator;
26 27
27 import de.intevation.flys.client.client.Config; 28 import de.intevation.flys.client.client.Config;
28 import de.intevation.flys.client.client.FLYSConstants; 29 import de.intevation.flys.client.client.FLYSConstants;
29 import de.intevation.flys.client.client.services.CollectionItemAttributeService; 30 import de.intevation.flys.client.client.services.CollectionItemAttributeService;
30 import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync; 31 import de.intevation.flys.client.client.services.CollectionItemAttributeServiceAsync;
68 protected FacetRecord facet; 69 protected FacetRecord facet;
69 70
70 /** Main layout. */ 71 /** Main layout. */
71 protected VLayout layout; 72 protected VLayout layout;
72 73
74 /** The form that contains all the input widgets. */
75 DynamicForm df;
76
73 protected VLayout properties; 77 protected VLayout properties;
78
74 protected Canvas container; 79 protected Canvas container;
75 80
76 protected Map<String, Style> styleGroups; 81 protected Map<String, Style> styleGroups;
77 82
78 protected Style current; 83 protected Style current;
84 GWT.create(CollectionItemAttributeService.class); 89 GWT.create(CollectionItemAttributeService.class);
85 90
86 /** The service used to request a list of themes. */ 91 /** The service used to request a list of themes. */
87 protected ThemeListingServiceAsync themeListingService = 92 protected ThemeListingServiceAsync themeListingService =
88 GWT.create(ThemeListingService.class); 93 GWT.create(ThemeListingService.class);
94
89 95
90 /** 96 /**
91 * Setup editor dialog. 97 * Setup editor dialog.
92 * @param collection The collection the current theme belongs to. 98 * @param collection The collection the current theme belongs to.
93 * @param attributes The collection attributes. 99 * @param attributes The collection attributes.
204 Button cancel = new Button(MSG.label_cancel()); 210 Button cancel = new Button(MSG.label_cancel());
205 cancel.addClickHandler(this); 211 cancel.addClickHandler(this);
206 accept.addClickHandler(new ClickHandler() { 212 accept.addClickHandler(new ClickHandler() {
207 @Override 213 @Override
208 public void onClick(ClickEvent e) { 214 public void onClick(ClickEvent e) {
209 saveStyle(); 215 // TODO Fix this, for whatever reason it doesnt work
216 // (always valid).
217 if (!df.hasErrors() && df.validate()) {
218 saveStyle();
219 }
210 } 220 }
211 }); 221 });
212 222
213 buttons.addMember(accept); 223 buttons.addMember(accept);
214 buttons.addMember(cancel); 224 buttons.addMember(cancel);
344 String dname, 354 String dname,
345 String name, 355 String name,
346 String type, 356 String type,
347 String value) 357 String value)
348 { 358 {
349 DynamicForm df = new DynamicForm(); 359 df = new DynamicForm();
350 df.setColWidths("40%", "60%"); 360 df.setColWidths("40%", "60%");
351 361
352 FormItem f; 362 FormItem f;
353 if(type.equals("int")) { 363 if(type.equals("int")) {
354 f = new SelectItem(name, MSG.getString(name)); 364 f = new SelectItem(name, MSG.getString(name));
421 ColorPickerItem c = new ColorPickerItem(name, MSG.getString(name)); 431 ColorPickerItem c = new ColorPickerItem(name, MSG.getString(name));
422 c.setValue(rgbToHtml(value)); 432 c.setValue(rgbToHtml(value));
423 f = c; 433 f = c;
424 } 434 }
425 else if (type.equals("double")) { 435 else if (type.equals("double")) {
426 f = new FormItem(MSG.getString(name)); 436 f = new FormItem(name);
437 IsFloatValidator fpv = new IsFloatValidator();
438
439 f.setValidators(fpv);
440 f.setValidateOnChange(true);
441 f.setTitle(MSG.getString(name));
427 f.addBlurHandler(new BlurHandler() { 442 f.addBlurHandler(new BlurHandler() {
428 public void onBlur(BlurEvent e) { 443 public void onBlur(BlurEvent e) {
429 DoubleValidator validator = new DoubleValidator(); 444 DoubleValidator validator = new DoubleValidator();
430 Map errors = e.getForm().getErrors(); 445 Map errors = e.getForm().getErrors();
431 if(validator.validate(e.getItem(), errors)) { 446 if(validator.validate(e.getItem(), errors)) {

http://dive4elements.wald.intevation.org