1
|
/**
|
2
|
* Copyright (C) 2017 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.vaadin.component.common;
|
10
|
|
11
|
import com.vaadin.data.fieldgroup.BeanFieldGroup;
|
12
|
import com.vaadin.data.fieldgroup.FieldGroup;
|
13
|
import com.vaadin.data.util.BeanItem;
|
14
|
import com.vaadin.ui.Component;
|
15
|
import com.vaadin.ui.GridLayout;
|
16
|
import com.vaadin.ui.TextField;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.location.Point;
|
19
|
import eu.etaxonomy.vaadin.component.CompositeCustomField;
|
20
|
|
21
|
/**
|
22
|
* @author a.kohlbecker
|
23
|
* @since Jun 22, 2017
|
24
|
*
|
25
|
*/
|
26
|
public class GeoLocationField extends CompositeCustomField<Point> {
|
27
|
|
28
|
|
29
|
private static final long serialVersionUID = 1122123034547920390L;
|
30
|
|
31
|
private static final String PRIMARY_STYLE = "v-geolocation-field";
|
32
|
|
33
|
private BeanFieldGroup<Point> fieldGroup = new BeanFieldGroup<>(Point.class);
|
34
|
|
35
|
TextField longitudeField = new TextField("Long.");
|
36
|
TextField latitudeField = new TextField("Lat.");
|
37
|
TextField errorRadiusField = new TextField("Error radius (m)");
|
38
|
TextField referenceSystemField = new TextField("ReferenceSystem");
|
39
|
|
40
|
/**
|
41
|
*
|
42
|
*/
|
43
|
public GeoLocationField() {
|
44
|
super();
|
45
|
}
|
46
|
|
47
|
public GeoLocationField(String caption) {
|
48
|
super();
|
49
|
setCaption(caption);
|
50
|
}
|
51
|
|
52
|
/**
|
53
|
* {@inheritDoc}
|
54
|
*/
|
55
|
@Override
|
56
|
protected Component initContent() {
|
57
|
super.setPrimaryStyleName(PRIMARY_STYLE);
|
58
|
|
59
|
GridLayout root = new GridLayout();
|
60
|
root.setRows(2);
|
61
|
root.setColumns(2);
|
62
|
root.setStyleName("wrapper");
|
63
|
root.addComponent(longitudeField);
|
64
|
root.addComponent(latitudeField);
|
65
|
root.addComponent(errorRadiusField);
|
66
|
root.addComponent(referenceSystemField);
|
67
|
|
68
|
addStyledComponents(longitudeField, latitudeField, errorRadiusField, referenceSystemField);
|
69
|
addSizedComponent(root);
|
70
|
|
71
|
fieldGroup.bind(longitudeField, "longitude");
|
72
|
fieldGroup.bind(latitudeField, "latitude");
|
73
|
fieldGroup.bind(errorRadiusField, "errorRadius");
|
74
|
fieldGroup.bind(referenceSystemField, "referenceSystem");
|
75
|
|
76
|
referenceSystemField.setEnabled(false); // disabled since not fully implemented
|
77
|
|
78
|
return root;
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* {@inheritDoc}
|
83
|
*/
|
84
|
@Override
|
85
|
public Class<? extends Point> getType() {
|
86
|
return Point.class;
|
87
|
}
|
88
|
|
89
|
@Override
|
90
|
protected void setInternalValue(Point newValue) {
|
91
|
if(newValue == null){
|
92
|
newValue = Point.NewInstance();
|
93
|
}
|
94
|
super.setInternalValue(newValue);
|
95
|
fieldGroup.setItemDataSource(new BeanItem<Point>(newValue));
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* {@inheritDoc}
|
100
|
*/
|
101
|
@Override
|
102
|
protected void addDefaultStyles() {
|
103
|
// no default styles so far
|
104
|
|
105
|
}
|
106
|
|
107
|
/**
|
108
|
* {@inheritDoc}
|
109
|
*/
|
110
|
@Override
|
111
|
public FieldGroup getFieldGroup() {
|
112
|
return fieldGroup;
|
113
|
}
|
114
|
|
115
|
|
116
|
|
117
|
}
|