Mercurial > dive4elements > river
comparison gwt-client/src/main/java/org/dive4elements/river/client/client/ui/uinfo/VegetationzonesTableEditPanel.java @ 9261:22a3999fd536
klasse vergessen
author | gernotbelger |
---|---|
date | Tue, 17 Jul 2018 17:51:43 +0200 |
parents | 431f1c269be5 |
children | 4a6cc7c6716a |
comparison
equal
deleted
inserted
replaced
9260:b570b6fcc052 | 9261:22a3999fd536 |
---|---|
8 | 8 |
9 package org.dive4elements.river.client.client.ui.uinfo; | 9 package org.dive4elements.river.client.client.ui.uinfo; |
10 | 10 |
11 import org.dive4elements.river.client.client.ui.PanelHelper; | 11 import org.dive4elements.river.client.client.ui.PanelHelper; |
12 import org.dive4elements.river.client.shared.model.DataList; | 12 import org.dive4elements.river.client.shared.model.DataList; |
13 import org.dive4elements.river.client.shared.model.VegetationZone; | |
13 | 14 |
15 import com.google.gwt.event.dom.client.ClickEvent; | |
16 import com.google.gwt.event.dom.client.ClickHandler; | |
17 import com.google.gwt.user.client.ui.Button; | |
14 import com.smartgwt.client.util.SC; | 18 import com.smartgwt.client.util.SC; |
15 import com.smartgwt.client.widgets.Button; | |
16 import com.smartgwt.client.widgets.events.ClickEvent; | |
17 import com.smartgwt.client.widgets.events.ClickHandler; | |
18 import com.smartgwt.client.widgets.form.DynamicForm; | 19 import com.smartgwt.client.widgets.form.DynamicForm; |
20 import com.smartgwt.client.widgets.form.fields.ColorItem; | |
19 import com.smartgwt.client.widgets.form.fields.TextItem; | 21 import com.smartgwt.client.widgets.form.fields.TextItem; |
20 import com.smartgwt.client.widgets.grid.ListGrid; | 22 import com.smartgwt.client.widgets.grid.ListGrid; |
21 import com.smartgwt.client.widgets.grid.ListGridRecord; | 23 import com.smartgwt.client.widgets.grid.ListGridRecord; |
22 import com.smartgwt.client.widgets.layout.Layout; | 24 import com.smartgwt.client.widgets.layout.Layout; |
23 import com.smartgwt.client.widgets.layout.VLayout; | 25 import com.smartgwt.client.widgets.layout.VLayout; |
32 private TextItem end; | 34 private TextItem end; |
33 | 35 |
34 @Override | 36 @Override |
35 public void createWidget(final Layout root, final DataList data) { | 37 public void createWidget(final Layout root, final DataList data) { |
36 | 38 |
37 final ListGrid elements = super.createTable(root, data, "450", true); | 39 final ListGrid elements = super.createTable(root, data, "420", true); |
38 | 40 |
39 this.vegzone = PanelHelper.createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), "*");// 450); | 41 this.vegzone = PanelHelper.createItem("uinfo_vegetation_zone_label", this.MSG.uinfo_vegetation_zone_label(), "*"); |
40 this.vegzone.setColSpan(4); | 42 this.vegzone.setColSpan(4); |
41 this.start = PanelHelper.createIntegerItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(), "*"); | 43 this.start = PanelHelper.createIntegerItem("uinfo_vegetation_zones_from", this.MSG.uinfo_vegetation_zones_from(), "*"); |
42 this.end = PanelHelper.createIntegerItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), "*"); | 44 this.end = PanelHelper.createIntegerItem("uinfo_vegetation_zones_to", this.MSG.uinfo_vegetation_zones_to(), "*"); |
43 final VLayout fields = new VLayout(); | 45 final VLayout fields = new VLayout(); |
46 | |
47 final ColorItem colorPicker = new ColorItem(); | |
48 colorPicker.setTitle(this.MSG.uinfo_vegetation_zone_color()); | |
49 | |
50 colorPicker.setShowTitle(true); | |
51 colorPicker.setShowValueIconOnly(false); | |
52 colorPicker.setShowPickerIcon(true); | |
53 colorPicker.setColSpan(2); | |
54 colorPicker.setWidth(110); | |
44 | 55 |
45 final Button add = new Button(this.MSG.add_date()); // TODO: make key more generic or change to more specific | 56 final Button add = new Button(this.MSG.add_date()); // TODO: make key more generic or change to more specific |
46 | 57 |
47 final DynamicForm form1 = new DynamicForm(); | 58 final DynamicForm form1 = new DynamicForm(); |
48 | 59 |
49 form1.setNumCols(4); // für Layout untereinander muss 2 eingestellt werden | 60 form1.setNumCols(4); // für Layout untereinander muss 2 eingestellt werden |
50 | 61 if (VegetationZone.HAS_COLORS_EDITABLE) |
51 form1.setFields(this.vegzone, this.start, this.end); | 62 form1.setFields(this.vegzone, this.start, this.end, colorPicker); |
63 else | |
64 form1.setFields(this.vegzone, this.start, this.end); | |
52 | 65 |
53 add.addClickHandler(new ClickHandler() { | 66 add.addClickHandler(new ClickHandler() { |
54 @Override | 67 @Override |
55 public void onClick(final ClickEvent ce) { | 68 public void onClick(final ClickEvent ce) { |
56 final String v1 = VegetationzonesTableEditPanel.this.start.getValueAsString(); | 69 final String v1 = VegetationzonesTableEditPanel.this.start.getValueAsString(); |
57 final String v2 = VegetationzonesTableEditPanel.this.end.getValueAsString(); | 70 final String v2 = VegetationzonesTableEditPanel.this.end.getValueAsString(); |
58 final String v3 = VegetationzonesTableEditPanel.this.vegzone.getValueAsString(); | 71 final String v3 = VegetationzonesTableEditPanel.this.vegzone.getValueAsString(); |
59 final String message = validate(v1, v2, v3); | 72 final String v4 = VegetationZone.HAS_COLORS_EDITABLE ? colorPicker.getValueAsString() : "#ffffff"; |
73 final String message = validate(v1, v2, v3, v4); | |
60 if (message != null) { | 74 if (message != null) { |
61 SC.warn(message); | 75 SC.warn(message); |
62 return; | 76 return; |
63 } | 77 } |
64 | 78 |
65 final ListGridRecord r = new ListGridRecord(); | 79 final ListGridRecord r = new ListGridRecord(); |
66 r.setAttribute("vegzone", v3); | 80 r.setAttribute("vegzone", v3); |
67 r.setAttribute("from", v1); | 81 r.setAttribute("from", v1); |
68 r.setAttribute("to", v2); | 82 r.setAttribute("to", v2); |
83 r.setAttribute("color", v4); | |
69 elements.addData(r); | 84 elements.addData(r); |
85 validateRangeOverlap(); | |
70 final String sortField = elements.getSortField(); | 86 final String sortField = elements.getSortField(); |
71 if (sortField != null) { | 87 if (sortField != null) { |
72 elements.toggleSort(sortField); | 88 elements.toggleSort(sortField); |
73 elements.toggleSort(sortField); // HACK. has to be. otherwise normalizer won't be called :-( | 89 elements.toggleSort(sortField); // HACK. has to be. otherwise normalizer won't be called :-( |
74 } | 90 } |
78 fields.addMember(form1); | 94 fields.addMember(form1); |
79 | 95 |
80 root.addMember(fields); | 96 root.addMember(fields); |
81 root.addMember(PanelHelper.getSpacer(10)); | 97 root.addMember(PanelHelper.getSpacer(10)); |
82 root.addMember(add); | 98 root.addMember(add); |
83 root.addMember(PanelHelper.getSpacer(20)); | 99 |
84 } | 100 } |
85 | 101 |
86 protected String validate(final String v1, final String v2, final String v3) { | |
87 | |
88 if (v1 == null || v2 == null || v3 == null || v1.trim().isEmpty() || v2.trim().isEmpty() || v3.trim().isEmpty()) | |
89 return this.MSG.uinfo_vegetation_zones_validation_empty(); | |
90 | |
91 try { | |
92 final Integer from = Integer.valueOf(v1); | |
93 final Integer to = Integer.valueOf(v2); | |
94 | |
95 if (from < 0 || from > 365) | |
96 return this.MSG.uinfo_vegetation_zones_validation_range(); | |
97 | |
98 if (to < 0 || to > 365) | |
99 return this.MSG.uinfo_vegetation_zones_validation_range(); | |
100 | |
101 if (from > to) | |
102 return this.MSG.uinfo_vegetation_zones_validation_from_greater_to(); | |
103 | |
104 return null; | |
105 } | |
106 catch (final NumberFormatException e) { | |
107 return this.MSG.uinfo_vegetation_zones_invalid_integer(); | |
108 } | |
109 } | |
110 } | 102 } |