Project

General

Profile

Revision f68f9e94

IDf68f9e94a1f39cbbb9bc1f3d88bd320fdb39e654
Parent cfabbeb0
Child 4a3c0817

Added by Andreas Kohlbecker over 3 years ago

ref #6724 Custom Field for geo location Points

View differences:

src/main/java/eu/etaxonomy/cdm/vaadin/component/common/GeoLocationField.java
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
}
src/main/java/eu/etaxonomy/cdm/vaadin/view/name/SpecimenTypeDesignationWorkingsetPopupEditor.java
14 14

  
15 15
import com.vaadin.data.validator.DoubleRangeValidator;
16 16
import com.vaadin.ui.AbstractSelect.ItemCaptionMode;
17
import com.vaadin.ui.Component;
18 17
import com.vaadin.ui.GridLayout;
19 18
import com.vaadin.ui.ListSelect;
20 19
import com.vaadin.ui.TextArea;
21 20
import com.vaadin.ui.TextField;
22 21

  
23 22
import eu.etaxonomy.cdm.vaadin.component.PartialDateField;
23
import eu.etaxonomy.cdm.vaadin.component.common.GeoLocationField;
24 24
import eu.etaxonomy.cdm.vaadin.component.common.MinMaxTextField;
25 25
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
26 26
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
......
78 78
        int row = 0;
79 79
        countrySelectField = new ListSelect("Country");
80 80
        addField(countrySelectField, "country", 1, row , 2, row);
81
        setToFullWidth(countrySelectField);
81
        countrySelectField.setWidth("100%");
82 82
        countrySelectField.setItemCaptionMode(ItemCaptionMode.PROPERTY);
83 83
        countrySelectField.setItemCaptionPropertyId("label");
84 84
        countrySelectField.setRows(1);
85 85

  
86
        // -------
87

  
88 86
        row++;
89 87
        TextArea localityField = new TextArea("Locality");
90 88
        addField(localityField, "locality", 0, row , 2, row);
91
        setToFullWidth(localityField);
92
        localityField.setRows(3);
89
        localityField.setWidth("100%");
90
        // NOTE: setRows and SetCold breaks he width setting,
91
        //        see https://github.com/vaadin/framework/issues/3617
93 92

  
94
        // TODO ExactLocation as PointField
93
        row++;
94
        GeoLocationField exactLocation = new GeoLocationField("Geo location");
95
        addField(exactLocation, "exactLocation", 0, row, 2, row);
96
        exactLocation.setWidth("100%");
95 97

  
96 98
        row++;
97 99
        MinMaxTextField absElevationMinMax = new MinMaxTextField("Altitude", "m");
......
133 135
        PartialDateField collectionDateField = new PartialDateField("Collection date");
134 136
        addField(collectionDateField, "gatheringDate", 0, row);
135 137
        TextField fieldNumberField = addTextField("Field number", "fieldNumber", 2, row);
136
        //
137
    }
138

  
139
    protected void setToFullWidth(Component component){
140
        //component.setWidth(100, Unit.PERCENTAGE);
141
    }
142

  
138
     }
143 139

  
144 140

  
145 141
    /**
src/main/webapp/VAADIN/themes/edit-valo/custom-fields.scss
151 151
        @include composite-field-wrapper;
152 152
    }
153 153
    
154
    // ------------ v-geolocation-field ------------- //
155
    .v-geolocation-field {
156
        .wrapper{
157
          @include composite-field-wrapper;
158
        }
159
    }
160
    
154 161
} 

Also available in: Unified diff

Add picture from clipboard (Maximum size: 40 MB)