Project

General

Profile

Download (8.34 KB) Statistics
| Branch: | Tag: | Revision:
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.view.name;
10

    
11
import java.util.Collection;
12

    
13
import org.springframework.security.core.GrantedAuthority;
14
import org.vaadin.viritin.fields.ElementCollectionField;
15

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

    
25
import eu.etaxonomy.cdm.vaadin.component.PartialDateField;
26
import eu.etaxonomy.cdm.vaadin.component.common.GeoLocationField;
27
import eu.etaxonomy.cdm.vaadin.component.common.MinMaxTextField;
28
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
29
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationDTO;
30
import eu.etaxonomy.cdm.vaadin.model.registration.SpecimenTypeDesignationWorkingSetDTO;
31
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
32
import eu.etaxonomy.vaadin.mvp.AbstractPopupEditor;
33

    
34
/**
35
 * @author a.kohlbecker
36
 * @since May 15, 2017
37
 *
38
 */
39
public class SpecimenTypeDesignationWorkingsetPopupEditor extends AbstractPopupEditor<SpecimenTypeDesignationWorkingSetDTO, SpecimenTypeDesignationWorkingsetEditorPresenter>
40
    implements SpecimenTypeDesignationWorkingsetPopupEditorView, AccessRestrictedView {
41

    
42
    /**
43
     * @param layout
44
     * @param dtoType
45
     */
46
    public SpecimenTypeDesignationWorkingsetPopupEditor() {
47
        super(new GridLayout(), SpecimenTypeDesignationWorkingSetDTO.class);
48
        GridLayout grid = (GridLayout) getFieldLayout();
49
        grid.setMargin(true);
50
        grid.setSpacing(true);
51
    }
52

    
53
    private static final long serialVersionUID = 5418275817834009509L;
54

    
55
    private ListSelect countrySelectField;
56

    
57
    private ElementCollectionField<SpecimenTypeDesignationDTO> typeDesignationsCollectionField;
58

    
59
    /**
60
     * @return the countrySelectField
61
     */
62
    @Override
63
    public ListSelect getCountrySelectField() {
64
        return countrySelectField;
65
    }
66

    
67
    /**
68
     * {@inheritDoc}
69
     */
70
    @Override
71
    protected void initContent() {
72

    
73
        GridLayout grid = (GridLayout)getFieldLayout();
74
        grid.setSpacing(true);
75
        grid.setMargin(true);
76
        grid.setColumns(3);
77
        grid.setRows(9);
78

    
79
        //TODO typifyingAuthors
80

    
81
        // FieldUnit + GatheringEvent
82

    
83
        int row = 0;
84
        countrySelectField = new ListSelect("Country");
85
        addField(countrySelectField, "country", 1, row , 2, row);
86
        countrySelectField.setWidth("100%");
87
        countrySelectField.setItemCaptionMode(ItemCaptionMode.PROPERTY);
88
        countrySelectField.setItemCaptionPropertyId("label");
89
        countrySelectField.setRows(1);
90

    
91
        row++;
92
        TextArea localityField = new TextArea("Locality");
93
        addField(localityField, "locality", 0, row , 2, row);
94
        localityField.setWidth("100%");
95
        // NOTE: setRows and SetCold breaks he width setting,
96
        //        see https://github.com/vaadin/framework/issues/3617
97

    
98
        row++;
99
        GeoLocationField exactLocation = new GeoLocationField("Geo location");
100
        addField(exactLocation, "exactLocation", 0, row, 2, row);
101
        exactLocation.setWidth("100%");
102

    
103
        row++;
104
        MinMaxTextField absElevationMinMax = new MinMaxTextField("Altitude", "m");
105
        absElevationMinMax.setWidth("100%");
106
        absElevationMinMax.addSubComponentsStyleName(getDefaultComponentStyles());
107
        grid.addComponent(absElevationMinMax, 0, row, 2, row);
108

    
109
        bindField(absElevationMinMax.getMinField(), "absoluteElevation");
110
        bindField(absElevationMinMax.getMaxField(), "absoluteElevationMax");
111
        bindField(absElevationMinMax.getTextField(), "absoluteElevationText");
112

    
113
        row++;
114
        MinMaxTextField distanceToWaterSurfaceMinMax = new MinMaxTextField("Distance to water surface", "m");
115
        distanceToWaterSurfaceMinMax.setWidth("100%");
116
        distanceToWaterSurfaceMinMax.addSubComponentsStyleName(getDefaultComponentStyles());
117
        grid.addComponent(distanceToWaterSurfaceMinMax, 0, row, 2, row);
118

    
119
        bindField(distanceToWaterSurfaceMinMax.getMinField(), "distanceToWaterSurface");
120
        bindField(distanceToWaterSurfaceMinMax.getMaxField(), "distanceToWaterSurfaceMax");
121
        bindField(distanceToWaterSurfaceMinMax.getTextField(), "distanceToWaterSurfaceText");
122
        distanceToWaterSurfaceMinMax.getMaxField().addValidator(new DoubleRangeValidator("Negative values are not allowed here.", 0.0, Double.MAX_VALUE));
123
        distanceToWaterSurfaceMinMax.getMinField().addValidator(new DoubleRangeValidator("Negative values are not allowed here.", 0.0, Double.MAX_VALUE));
124

    
125
        row++;
126
        MinMaxTextField distanceToGroundMinMax = new MinMaxTextField("Distance to substrate", "m");
127
        distanceToGroundMinMax.setWidth("100%");
128
        distanceToGroundMinMax.addSubComponentsStyleName(getDefaultComponentStyles());
129
        grid.addComponent(distanceToGroundMinMax, 0, row, 2, row);
130

    
131
        bindField(distanceToGroundMinMax.getMinField(), "distanceToGround");
132
        bindField(distanceToGroundMinMax.getMaxField(), "distanceToGroundMax");
133
        bindField(distanceToGroundMinMax.getTextField(), "distanceToGroundText");
134

    
135
        row++;
136
        TeamOrPersonField collectorField = new TeamOrPersonField("Collector");
137
        addField(collectorField, "collector", 0, row, 2, row);
138

    
139
        row++;
140
        PartialDateField collectionDateField = new PartialDateField("Collection date");
141
        addField(collectionDateField, "gatheringDate", 0, row);
142
        TextField fieldNumberField = addTextField("Field number", "fieldNumber", 2, row);
143

    
144
        row++;
145

    
146
        // FIXME: can we use the Grid instaed?
147
        typeDesignationsCollectionField = new ElementCollectionField<>(
148
                SpecimenTypeDesignationDTO.class,
149
                SpecimenTypeDesignationDTORow.class
150
                );
151
        typeDesignationsCollectionField.withCaption("Types");
152
        typeDesignationsCollectionField.getLayout().setSpacing(false);
153
        typeDesignationsCollectionField.getLayout().setColumns(3);
154

    
155
        typeDesignationsCollectionField.setPropertyHeader("accessionNumber", "Access. num.");
156
        typeDesignationsCollectionField.setPropertyHeader("mediaSpecimenReference", "Image reference");
157
        typeDesignationsCollectionField.setPropertyHeader("mediaSpecimenReferenceDetail", "Reference detail");
158

    
159
        // typeDesignationsCollectionField.getLayout().setMargin(false);
160
        // typeDesignationsCollectionField.addStyleName("composite-field-wrapper");
161
        // addField(typeDesignationsCollectionField, "specimenTypeDesignationDTOs", 0, row, 2, row);
162

    
163
        Panel scrollPanel = new Panel(typeDesignationsCollectionField.getLayout());
164
        scrollPanel.setCaption("Types");
165
        scrollPanel.setWidth(800, Unit.PIXELS);
166

    
167
        bindField(typeDesignationsCollectionField, "specimenTypeDesignationDTOs");
168
        addComponent(scrollPanel, 0, row, 2, row);
169

    
170
     }
171

    
172

    
173
    /**
174
     * {@inheritDoc}
175
     */
176
    @Override
177
    public String getWindowCaption() {
178
        return "Specimen typedesignations editor";
179
    }
180

    
181
    /**
182
     * {@inheritDoc}
183
     */
184
    @Override
185
    public void focusFirst() {
186
        // none
187
    }
188

    
189
    /**
190
     * {@inheritDoc}
191
     */
192
    @Override
193
    protected String getDefaultComponentStyles() {
194
        return "tiny";
195
    }
196

    
197
    /**
198
     * {@inheritDoc}
199
     */
200
    @Override
201
    public boolean allowAnonymousAccess() {
202
        return false;
203
    }
204

    
205
    /**
206
     * {@inheritDoc}
207
     */
208
    @Override
209
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
210
        return null;
211
    }
212

    
213
    /**
214
     * {@inheritDoc}
215
     */
216
    @Override
217
    public boolean isResizable() {
218
        return true;
219
    }
220

    
221

    
222
    // ------- SpecimenTypeDesignationWorkingsetPopupEditorView methods ---- //
223
    @Override
224
    public ElementCollectionField<SpecimenTypeDesignationDTO> getTypeDesignationsCollectionField() {
225
        return typeDesignationsCollectionField;
226
    }
227

    
228
    @Override
229
    public void applyDefaultComponentStyle(Component ... components){
230
        for(int i = 0; i <components.length; i++){
231
            components[i].setStyleName(getDefaultComponentStyles());
232
        }
233
    }
234

    
235

    
236

    
237

    
238
}
(3-3/7)