8 |
8 |
*/
|
9 |
9 |
package eu.etaxonomy.cdm.vaadin.component.common;
|
10 |
10 |
|
|
11 |
import java.text.ParseException;
|
|
12 |
|
|
13 |
import org.vaadin.addon.leaflet.LMap;
|
|
14 |
import org.vaadin.addon.leaflet.LMarker;
|
|
15 |
import org.vaadin.addon.leaflet.LOpenStreetMapLayer;
|
|
16 |
|
11 |
17 |
import com.vaadin.data.fieldgroup.BeanFieldGroup;
|
12 |
18 |
import com.vaadin.data.fieldgroup.FieldGroup;
|
13 |
19 |
import com.vaadin.data.util.BeanItem;
|
|
20 |
import com.vaadin.server.UserError;
|
14 |
21 |
import com.vaadin.ui.Component;
|
|
22 |
import com.vaadin.ui.CssLayout;
|
15 |
23 |
import com.vaadin.ui.GridLayout;
|
|
24 |
import com.vaadin.ui.Label;
|
16 |
25 |
import com.vaadin.ui.TextField;
|
17 |
26 |
|
18 |
27 |
import eu.etaxonomy.cdm.model.location.Point;
|
... | ... | |
32 |
41 |
|
33 |
42 |
private BeanFieldGroup<Point> fieldGroup = new BeanFieldGroup<>(Point.class);
|
34 |
43 |
|
35 |
|
TextField longitudeField = new TextField("Long.");
|
|
44 |
Point parsedPoint = Point.NewInstance();
|
|
45 |
|
|
46 |
private TextField longitudeField = new TextField("Long.");
|
36 |
47 |
TextField latitudeField = new TextField("Lat.");
|
|
48 |
Label longLatParsed = new Label();
|
37 |
49 |
TextField errorRadiusField = new TextField("Error radius (m)");
|
38 |
50 |
TextField referenceSystemField = new TextField("ReferenceSystem");
|
39 |
51 |
|
|
52 |
private LMap leafletMap = new LMap();
|
|
53 |
|
|
54 |
private CssLayout mapWrapper;
|
|
55 |
|
40 |
56 |
/**
|
41 |
57 |
*
|
42 |
58 |
*/
|
... | ... | |
58 |
74 |
|
59 |
75 |
GridLayout root = new GridLayout();
|
60 |
76 |
root.setRows(2);
|
61 |
|
root.setColumns(2);
|
|
77 |
root.setColumns(3);
|
62 |
78 |
root.setStyleName("wrapper");
|
63 |
|
root.addComponent(longitudeField);
|
64 |
|
root.addComponent(latitudeField);
|
65 |
|
root.addComponent(errorRadiusField);
|
66 |
|
root.addComponent(referenceSystemField);
|
|
79 |
root.addComponent(longitudeField, 0, 0);
|
|
80 |
root.addComponent(latitudeField, 1, 0);
|
|
81 |
root.addComponent(errorRadiusField, 0, 1);
|
|
82 |
root.addComponent(referenceSystemField, 1, 1);
|
|
83 |
|
|
84 |
leafletMap = new LMap();
|
|
85 |
leafletMap.setZoomLevel(7);
|
|
86 |
leafletMap.addBaseLayer(new LOpenStreetMapLayer(), null);
|
67 |
87 |
|
68 |
|
addStyledComponents(longitudeField, latitudeField, errorRadiusField, referenceSystemField);
|
|
88 |
root.setColumnExpandRatio(2, 1.0f);
|
|
89 |
root.setRowExpandRatio(1, 1.0f);
|
|
90 |
|
|
91 |
root.addComponent(leafletMap, 2, 1);
|
|
92 |
mapWrapper = new CssLayout(longLatParsed, leafletMap);
|
|
93 |
root.addComponent(mapWrapper, 2, 0, 2, 1);
|
|
94 |
mapWrapper.setSizeFull();
|
|
95 |
mapWrapper.setStyleName("map-wrapper");
|
|
96 |
|
|
97 |
longitudeField.addTextChangeListener(e -> updateParsedValue(longitudeField, e.getText()));
|
|
98 |
latitudeField.addTextChangeListener(e -> updateParsedValue(latitudeField, e.getText()));
|
|
99 |
|
|
100 |
addStyledComponents(longitudeField, latitudeField, errorRadiusField, referenceSystemField, longLatParsed);
|
69 |
101 |
addSizedComponent(root);
|
70 |
102 |
|
71 |
103 |
fieldGroup.bind(longitudeField, "longitude");
|
... | ... | |
76 |
108 |
return root;
|
77 |
109 |
}
|
78 |
110 |
|
|
111 |
/**
|
|
112 |
* @param longitudeField2
|
|
113 |
* @param value
|
|
114 |
* @return
|
|
115 |
*/
|
|
116 |
private void updateParsedValue(TextField field, String value) {
|
|
117 |
field.setComponentError(null);
|
|
118 |
if(value != null){
|
|
119 |
try {
|
|
120 |
if(field == longitudeField){
|
|
121 |
|
|
122 |
parsedPoint.setLongitudeByParsing(value);
|
|
123 |
} else {
|
|
124 |
parsedPoint.setLatitudeByParsing(value);
|
|
125 |
}
|
|
126 |
} catch (ParseException e) {
|
|
127 |
field.setComponentError(new UserError(e.getMessage()));
|
|
128 |
}
|
|
129 |
}
|
|
130 |
|
|
131 |
updateMap();
|
|
132 |
}
|
|
133 |
|
|
134 |
/**
|
|
135 |
*
|
|
136 |
*/
|
|
137 |
protected void updateMap() {
|
|
138 |
longLatParsed.setValue(parsedPoint.getLongitudeSexagesimal() + "/" + parsedPoint.getLatitudeSexagesimal());
|
|
139 |
leafletMap.removeAllComponents();
|
|
140 |
if(parsedPoint.getLongitude() != null && parsedPoint.getLatitude() != null){
|
|
141 |
leafletMap.setCenter(parsedPoint.getLongitude(), parsedPoint.getLatitude());
|
|
142 |
leafletMap.addComponents(new LMarker(parsedPoint.getLongitude(), parsedPoint.getLatitude()));
|
|
143 |
}
|
|
144 |
}
|
|
145 |
|
79 |
146 |
/**
|
80 |
147 |
* {@inheritDoc}
|
81 |
148 |
*/
|
... | ... | |
94 |
161 |
|
95 |
162 |
referenceSystemField.setEnabled(false); // disabled since not fully implemented
|
96 |
163 |
|
|
164 |
parsedPoint = newValue;
|
|
165 |
updateMap();
|
97 |
166 |
}
|
98 |
167 |
|
99 |
168 |
/**
|
ref #6724 geolocation field with log lat parsing and map