Project

General

Profile

Download (8.35 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
40
    extends AbstractPopupEditor<SpecimenTypeDesignationWorkingSetDTO, SpecimenTypeDesignationWorkingsetEditorPresenter>
41
    implements SpecimenTypeDesignationWorkingsetPopupEditorView, AccessRestrictedView {
42

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

    
54

    
55

    
56
    private static final long serialVersionUID = 5418275817834009509L;
57

    
58
    private ListSelect countrySelectField;
59

    
60
    private ElementCollectionField<SpecimenTypeDesignationDTO> typeDesignationsCollectionField;
61

    
62
    /**
63
     * @return the countrySelectField
64
     */
65
    @Override
66
    public ListSelect getCountrySelectField() {
67
        return countrySelectField;
68
    }
69

    
70
    /**
71
     * {@inheritDoc}
72
     */
73
    @Override
74
    protected void initContent() {
75

    
76
        GridLayout grid = (GridLayout)getFieldLayout();
77
        grid.setSpacing(true);
78
        grid.setMargin(true);
79
        grid.setColumns(3);
80
        grid.setRows(9);
81

    
82
        //TODO typifyingAuthors
83

    
84
        // FieldUnit + GatheringEvent
85

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

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

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

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

    
112
        bindField(absElevationMinMax.getMinField(), "absoluteElevation");
113
        bindField(absElevationMinMax.getMaxField(), "absoluteElevationMax");
114
        bindField(absElevationMinMax.getTextField(), "absoluteElevationText");
115

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

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

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

    
134
        bindField(distanceToGroundMinMax.getMinField(), "distanceToGround");
135
        bindField(distanceToGroundMinMax.getMaxField(), "distanceToGroundMax");
136
        bindField(distanceToGroundMinMax.getTextField(), "distanceToGroundText");
137

    
138
        row++;
139
        TeamOrPersonField collectorField = new TeamOrPersonField("Collector");
140
        addField(collectorField, "collector", 0, row, 2, row);
141

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

    
147
        row++;
148

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

    
158
        typeDesignationsCollectionField.setPropertyHeader("accessionNumber", "Access. num.");
159
        typeDesignationsCollectionField.setPropertyHeader("mediaSpecimenReference", "Image reference");
160
        typeDesignationsCollectionField.setPropertyHeader("mediaSpecimenReferenceDetail", "Reference detail");
161

    
162
        // typeDesignationsCollectionField.getLayout().setMargin(false);
163
        // typeDesignationsCollectionField.addStyleName("composite-field-wrapper");
164
        // addField(typeDesignationsCollectionField, "specimenTypeDesignationDTOs", 0, row, 2, row);
165

    
166
        Panel scrollPanel = new Panel(typeDesignationsCollectionField.getLayout());
167
        scrollPanel.setCaption("Types");
168
        scrollPanel.setWidth(800, Unit.PIXELS);
169

    
170
        bindField(typeDesignationsCollectionField, "specimenTypeDesignationDTOs");
171
        addComponent(scrollPanel, 0, row, 2, row);
172

    
173
     }
174

    
175

    
176
    /**
177
     * {@inheritDoc}
178
     */
179
    @Override
180
    public String getWindowCaption() {
181
        return "Specimen typedesignations editor";
182
    }
183

    
184
    /**
185
     * {@inheritDoc}
186
     */
187
    @Override
188
    public void focusFirst() {
189
        // none
190
    }
191

    
192
    /**
193
     * {@inheritDoc}
194
     */
195
    @Override
196
    protected String getDefaultComponentStyles() {
197
        return "tiny";
198
    }
199

    
200
    /**
201
     * {@inheritDoc}
202
     */
203
    @Override
204
    public boolean allowAnonymousAccess() {
205
        return false;
206
    }
207

    
208
    /**
209
     * {@inheritDoc}
210
     */
211
    @Override
212
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
213
        return null;
214
    }
215

    
216
    /**
217
     * {@inheritDoc}
218
     */
219
    @Override
220
    public boolean isResizable() {
221
        return true;
222
    }
223

    
224

    
225
    // ------- SpecimenTypeDesignationWorkingsetPopupEditorView methods ---- //
226
    @Override
227
    public ElementCollectionField<SpecimenTypeDesignationDTO> getTypeDesignationsCollectionField() {
228
        return typeDesignationsCollectionField;
229
    }
230

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

    
238

    
239

    
240

    
241
}
(4-4/8)