Revision a3a78809
Added by Andreas Kohlbecker over 5 years ago
src/main/java/eu/etaxonomy/cdm/vaadin/component/common/GeoLocationField.java | ||
---|---|---|
16 | 16 |
import org.vaadin.addon.leaflet.LTileLayer; |
17 | 17 |
import org.vaadin.addon.leaflet.LeafletClickEvent; |
18 | 18 |
|
19 |
import com.vaadin.data.Validator.InvalidValueException; |
|
19 | 20 |
import com.vaadin.data.fieldgroup.BeanFieldGroup; |
20 | 21 |
import com.vaadin.data.fieldgroup.FieldGroup; |
21 | 22 |
import com.vaadin.data.util.BeanItem; |
23 |
import com.vaadin.data.util.converter.Converter.ConversionException; |
|
22 | 24 |
import com.vaadin.ui.Component; |
23 | 25 |
import com.vaadin.ui.CssLayout; |
24 | 26 |
import com.vaadin.ui.GridLayout; |
... | ... | |
27 | 29 |
import com.vaadin.ui.TextField; |
28 | 30 |
|
29 | 31 |
import eu.etaxonomy.cdm.model.location.Point; |
32 |
import eu.etaxonomy.cdm.vaadin.component.LongLatField; |
|
30 | 33 |
import eu.etaxonomy.cdm.vaadin.component.TextFieldNFix; |
31 |
import eu.etaxonomy.cdm.vaadin.util.converter.GeoLocationConverterValidator; |
|
32 | 34 |
import eu.etaxonomy.cdm.vaadin.util.converter.GeoLocationConverterValidator.Axis; |
33 | 35 |
import eu.etaxonomy.cdm.vaadin.util.converter.IntegerConverter; |
34 | 36 |
import eu.etaxonomy.vaadin.component.CompositeCustomField; |
... | ... | |
48 | 50 |
|
49 | 51 |
private BeanFieldGroup<Point> fieldGroup = new BeanFieldGroup<>(Point.class); |
50 | 52 |
|
51 |
private TextField longitudeField = new TextFieldNFix("Longitude");
|
|
52 |
private TextField latitudeField = new TextFieldNFix("Latitude");
|
|
53 |
private TextField longitudeField = new LongLatField("Longitude", Axis.LONGITUDE);
|
|
54 |
private TextField latitudeField = new LongLatField("Latitude", Axis.LATITUDE);
|
|
53 | 55 |
private Label longLatParsed = new Label(); |
54 | 56 |
private TextField errorRadiusField = new TextFieldNFix("Error radius (m)"); |
55 | 57 |
private ListSelect referenceSystemSelect; |
... | ... | |
99 | 101 |
mapWrapper.setStyleName("map-wrapper"); |
100 | 102 |
longLatParsed.setWidthUndefined(); |
101 | 103 |
|
102 |
longitudeField.setConverter(new GeoLocationConverterValidator(Axis.LONGITUDE)); |
|
103 |
longitudeField.addValidator(new GeoLocationConverterValidator(Axis.LONGITUDE)); |
|
104 | 104 |
longitudeField.setBuffered(false); |
105 | 105 |
longitudeField.addValueChangeListener(e -> updateMap()); |
106 | 106 |
|
107 |
latitudeField.setConverter(new GeoLocationConverterValidator(Axis.LATITUDE)); |
|
108 |
latitudeField.addValidator(new GeoLocationConverterValidator(Axis.LATITUDE)); |
|
109 | 107 |
latitudeField.setBuffered(false); |
110 | 108 |
latitudeField.addValueChangeListener(e -> updateMap()); |
111 | 109 |
|
... | ... | |
120 | 118 |
root.setRows(2); |
121 | 119 |
root.setColumns(3); |
122 | 120 |
root.setStyleName("wrapper"); |
123 |
root.addComponent(latitudeField, 0, 0);
|
|
124 |
root.addComponent(longitudeField, 1, 0);
|
|
121 |
root.addComponent(longitudeField, 0, 0);
|
|
122 |
root.addComponent(latitudeField, 1, 0);
|
|
125 | 123 |
root.addComponent(errorRadiusField, 0, 1); |
126 | 124 |
root.addComponent(referenceSystemSelect, 1, 1); |
127 | 125 |
// root.addComponent(map, 2, 1); |
... | ... | |
144 | 142 |
* |
145 | 143 |
*/ |
146 | 144 |
protected void updateMap() { |
145 |
|
|
146 |
Double longitude = null; |
|
147 |
Double latitude = null; |
|
148 |
|
|
147 | 149 |
// using the string representations for UI display |
148 | 150 |
longLatParsed.setValue(longitudeField.getValue() + "/" + latitudeField.getValue()); |
149 | 151 |
map.removeComponent(mapMarker); |
150 | 152 |
if(errorRadiusMarker != null){ |
151 | 153 |
map.removeComponent(errorRadiusMarker); |
152 | 154 |
} |
153 |
Double longitude = (Double) longitudeField.getConverter().convertToModel(longitudeField.getValue(), Double.class, null); |
|
154 |
Double latitude = (Double) latitudeField.getConverter().convertToModel(latitudeField.getValue(), Double.class, null); |
|
155 |
|
|
156 |
try { |
|
157 |
longitudeField.validate(); |
|
158 |
longitude = (Double) longitudeField.getConverter().convertToModel(longitudeField.getValue(), Double.class, null); |
|
159 |
latitudeField.validate(); |
|
160 |
latitude = (Double) latitudeField.getConverter().convertToModel(latitudeField.getValue(), Double.class, null); |
|
161 |
} catch (InvalidValueException | ConversionException e){ |
|
162 |
// IGNORE validation error have been set in the UI in the validate() methods |
|
163 |
} |
|
164 |
|
|
155 | 165 |
logger.debug("panning map to " + longitude + "/" + latitude); |
156 | 166 |
if(longitude != null && latitude != null){ |
157 | 167 |
map.setZoomLevel(10); |
Also available in: Unified diff
ref #7217 better geo coordinate validation and parsing error feedback by creating LongLatField