Project

General

Profile

Download (14.9 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
import java.util.EnumSet;
13

    
14
import org.springframework.security.core.GrantedAuthority;
15

    
16
import com.vaadin.ui.Alignment;
17
import com.vaadin.ui.CheckBox;
18
import com.vaadin.ui.GridLayout;
19
import com.vaadin.ui.ListSelect;
20
import com.vaadin.ui.TextField;
21

    
22
import eu.etaxonomy.cdm.model.name.Rank;
23
import eu.etaxonomy.cdm.model.name.TaxonName;
24
import eu.etaxonomy.cdm.model.reference.Reference;
25
import eu.etaxonomy.cdm.vaadin.component.common.TeamOrPersonField;
26
import eu.etaxonomy.cdm.vaadin.event.AbstractEditorAction;
27
import eu.etaxonomy.cdm.vaadin.event.ReferenceEditorAction;
28
import eu.etaxonomy.cdm.vaadin.security.AccessRestrictedView;
29
import eu.etaxonomy.cdm.vaadin.util.converter.SetToListConverter;
30
import eu.etaxonomy.vaadin.component.SwitchableTextField;
31
import eu.etaxonomy.vaadin.component.ToManyRelatedEntitiesComboboxSelect;
32
import eu.etaxonomy.vaadin.component.ToOneRelatedEntityCombobox;
33
import eu.etaxonomy.vaadin.mvp.AbstractCdmPopupEditor;
34

    
35
/**
36
 * @author a.kohlbecker
37
 * @since May 22, 2017
38
 *
39
 */
40
public class TaxonNamePopupEditor extends AbstractCdmPopupEditor<TaxonName, TaxonNameEditorPresenter> implements TaxonNamePopupEditorView, AccessRestrictedView {
41

    
42
    private static final long serialVersionUID = -7037436241474466359L;
43

    
44
    private final static int GRID_COLS = 4;
45

    
46
    private final static int GRID_ROWS = 12;
47

    
48
    private static final boolean HAS_BASIONYM_DEFAULT = false;
49

    
50
    private TextField genusOrUninomialField;
51

    
52
    private TextField infraGenericEpithetField;
53

    
54
    private TextField specificEpithetField;
55

    
56
    private TextField infraSpecificEpithetField;
57

    
58
    private SwitchableTextField fullTitleCacheFiled;
59

    
60
    private SwitchableTextField protectedNameCacheField;
61

    
62
    private ToOneRelatedEntityCombobox<Reference> nomReferenceCombobox;
63

    
64
    private TextField nomenclaturalReferenceDetail;
65

    
66
    private TeamOrPersonField exBasionymAuthorshipField;
67

    
68
    private TeamOrPersonField basionymAuthorshipField;
69

    
70
    private ToManyRelatedEntitiesComboboxSelect<TaxonName> basionymCombobox;
71

    
72
    private CheckBox basionymToggle;
73

    
74
    private ListSelect rankSelect;
75

    
76
    private TeamOrPersonField combinationAuthorshipField;
77

    
78
    private TeamOrPersonField exCombinationAuthorshipField;
79

    
80
    private EnumSet<TaxonNamePopupEditorMode> modesActive = EnumSet.noneOf(TaxonNamePopupEditorMode.class);
81

    
82
    /**
83
     * @param layout
84
     * @param dtoType
85
     */
86
    public TaxonNamePopupEditor() {
87
        super(new GridLayout(GRID_COLS, GRID_ROWS), TaxonName.class);
88
    }
89

    
90
    /**
91
     * {@inheritDoc}
92
     */
93
    @Override
94
    public String getWindowCaption() {
95
        return "Name editor";
96
    }
97

    
98

    
99

    
100
    /**
101
     * {@inheritDoc}
102
     */
103
    @Override
104
    public int getWindowPixelWidth() {
105
        return 700;
106
    }
107

    
108
    /**
109
     * {@inheritDoc}
110
     */
111
    @Override
112
    public void focusFirst() {
113
        // titleField.focus();
114

    
115
    }
116

    
117
    /**
118
     * {@inheritDoc}
119
     */
120
    @Override
121
    protected String getDefaultComponentStyles() {
122
        return "tiny";
123
    }
124

    
125
    /**
126
     * {@inheritDoc}
127
     */
128
    @Override
129
    protected void initContent() {
130

    
131
        GridLayout grid = (GridLayout)getFieldLayout();
132
        grid.setSizeFull();
133
        grid.setSpacing(true);
134
        grid.setColumnExpandRatio(0, 0.3f);
135
        grid.setColumnExpandRatio(1, 0.3f);
136
        grid.setColumnExpandRatio(2, 0.3f);
137
        grid.setColumnExpandRatio(3, 0.0f);
138

    
139
        /*
140
         - nameType: preset, needs to be set in the presenter for new names
141
         - appendedPhrase: -> TODO field
142
         - nomenclaturalMicroReference:  -> TODO field
143
         - nomenclaturalReference ->  field but disabled for REGISTRY
144
         - rank -> SelectField which determines the visiblity of the other fields
145

    
146
         - fullTitleCache + protectedFullTitleCache -> SwitchableTextField : ADVANCED_MODE
147
         - nameCache + protectedNameCache -> SwitchableTextField : ADVANCED_MODE
148

    
149
         - homotypicalGroup -> hidden
150
         - typeDesignations -> hidden
151
         - descriptions -> hidden
152
         - taxonBases -> hidden
153
         - registrations -> hidden
154

    
155
         - relationsFromThisName-> TODO implement later
156
         - relationsToThisName -> TODO implement later
157

    
158
         - genusOrUninomial -> textField
159
         - infraGenericEpithet  -> textField
160
         - specificEpithet  -> textField
161
         - infraSpecificEpithet  -> textField
162

    
163
         - authorshipCache + protectedAuthorshipCache -> SwitchableTextField : only ADVANCED_MODE and disabled for REGISTRY
164
         - basionymAuthorship -> field but disabled for REGISTRY, basionym is set as nameRelationShip
165
         - combinationAuthorship -> field but disabled for REGISTRY author team of the reference
166
         - exCombinationAuthorship -> textField
167
         - exBasionymAuthorship -> textField
168

    
169
         - status -> TODO field
170
         - monomHybrid -> TODO implement hybrids later
171
         - binomHybrid -> TODO implement hybrids later
172
         - trinomHybrid -> TODO implement hybrids later
173

    
174
         - hybridParentRelations -> TODO implement hybrids later
175
         - hybridChildRelations -> TODO implement hybrids later
176
         - hybridFormula -> TODO implement hybrids later
177

    
178
         ** ViralName attributes **
179
         - acronym
180

    
181
         ** BacterialName attributes **
182
         - subGenusAuthorship
183
         - nameApprobation
184
         - breed
185
         - publicationYear
186
         - originalPublicationYear
187
         - cultivarName
188
        */
189

    
190
        int row = 0;
191

    
192
        rankSelect = new ListSelect("Rank");
193
        rankSelect.setNullSelectionAllowed(false);
194
        rankSelect.setRows(1);
195
        rankSelect.setWidth(100, Unit.PERCENTAGE);
196
        rankSelect.addValueChangeListener(e -> updateFieldVisibility((Rank)e.getProperty().getValue()));
197
        addField(rankSelect, "rank", 0, row, 1, row);
198
        grid.setComponentAlignment(rankSelect, Alignment.TOP_RIGHT);
199

    
200
        basionymToggle = new CheckBox("With basionym");
201
        basionymToggle.setValue(HAS_BASIONYM_DEFAULT);
202
        basionymToggle.addValueChangeListener(e -> {
203
                boolean enable = e.getProperty().getValue() != null && (Boolean)e.getProperty().getValue();
204
                enableBasionymFields(enable);
205
            });
206
        basionymToggle.setStyleName(getDefaultComponentStyles());
207
        grid.addComponent(basionymToggle, 2, row, 3, row);
208
        grid.setComponentAlignment(basionymToggle, Alignment.BOTTOM_LEFT);
209
        row++;
210
        // fullTitleCache
211
        fullTitleCacheFiled = addSwitchableTextField("Full title cache", "fullTitleCache", "protectedFullTitleCache", 0, row, GRID_COLS-1, row);
212
        fullTitleCacheFiled.setWidth(100, Unit.PERCENTAGE);
213
        row++;
214
        protectedNameCacheField = addSwitchableTextField("Name cache", "nameCache", "protectedNameCache", 0, row, GRID_COLS-1, row);
215
        protectedNameCacheField.setWidth(100, Unit.PERCENTAGE);
216
        row++;
217
        genusOrUninomialField = addTextField("Genus or uninomial", "genusOrUninomial", 0, row, 1, row);
218
        genusOrUninomialField.setWidth(200, Unit.PIXELS);
219
        infraGenericEpithetField = addTextField("Infrageneric epithet", "infraGenericEpithet", 2, row, 3, row);
220
        infraGenericEpithetField.setWidth(200, Unit.PIXELS);
221
        row++;
222
        specificEpithetField = addTextField("Specific epithet", "specificEpithet", 0, row, 1, row);
223
        specificEpithetField.setWidth(200, Unit.PIXELS);
224
        infraSpecificEpithetField = addTextField("Infraspecific epithet", "infraSpecificEpithet", 2, row, 3, row);
225
        infraSpecificEpithetField.setWidth(200, Unit.PIXELS);
226
        row++;
227
        combinationAuthorshipField = new TeamOrPersonField("combination author(s)");
228
        combinationAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
229
        addField(combinationAuthorshipField, "combinationAuthorship", 0, row, GRID_COLS-1, row);
230
        row++;
231
        exCombinationAuthorshipField = new TeamOrPersonField("Ex-combination author(s)");
232
        exCombinationAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
233
        addField(exCombinationAuthorshipField, "exCombinationAuthorship", 0, row, GRID_COLS-1, row);
234

    
235
        // nomenclaturalReference
236
        row++;
237
        nomReferenceCombobox = new ToOneRelatedEntityCombobox<Reference>("Nomenclatural reference", Reference.class);
238
        nomReferenceCombobox.addClickListenerAddEntity(e -> getEventBus().publishEvent(
239
                new ReferenceEditorAction(AbstractEditorAction.Action.ADD, null, nomReferenceCombobox, this)
240
                ));
241
        nomReferenceCombobox.addClickListenerEditEntity(e -> {
242
            if(nomReferenceCombobox.getValue() != null){
243
                getEventBus().publishEvent(
244
                    new ReferenceEditorAction(
245
                            AbstractEditorAction.Action.EDIT,
246
                            nomReferenceCombobox.getValue().getId(),
247
                            nomReferenceCombobox,
248
                            this)
249
                );
250
            }
251
            });
252
        nomReferenceCombobox.setWidth(300, Unit.PIXELS);
253
        addField(nomReferenceCombobox, "nomenclaturalReference", 0, row, 2, row);
254
        nomenclaturalReferenceDetail = addTextField("Reference detail", "nomenclaturalMicroReference", 3, row, 3, row);
255
        nomenclaturalReferenceDetail.setWidth(100, Unit.PIXELS);
256

    
257

    
258
        // Basionym
259
        row++;
260
        basionymCombobox = new ToManyRelatedEntitiesComboboxSelect<TaxonName>(TaxonName.class, "Basionym");
261
        /**
262
        basionymCombobox.newAdd(e -> getEventBus().publishEvent(
263
                new TaxonNameEditorAction(AbstractEditorAction.Action.ADD, null, basionymCombobox, this)
264
                ));
265
        basionymCombobox.addClickListenerEditEntity(e -> {
266
            if(basionymCombobox.getValue() != null){
267
                getEventBus().publishEvent(
268
                    new TaxonNameEditorAction(
269
                            AbstractEditorAction.Action.EDIT,
270
                            basionymCombobox.getValue().getId(),
271
                            basionymCombobox,
272
                            this)
273
                );
274
            }
275
            });
276
         **/
277
        basionymCombobox.setConverter(new SetToListConverter<TaxonName>());
278
        addField(basionymCombobox, "basionyms", 0, row, 3, row);
279
        basionymCombobox.setWidth(100, Unit.PERCENTAGE);
280
        grid.setComponentAlignment(basionymCombobox, Alignment.TOP_RIGHT);
281
        row++;
282
        basionymAuthorshipField = new TeamOrPersonField("Basionym author(s)");
283
        basionymAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
284
        addField(basionymAuthorshipField, "basionymAuthorship", 0, row, GRID_COLS-1, row);
285
        row++;
286
        exBasionymAuthorshipField = new TeamOrPersonField("Ex-basionym author(s)");
287
        exBasionymAuthorshipField.setWidth(100,  Unit.PERCENTAGE);
288
        addField(exBasionymAuthorshipField, "exBasionymAuthorship", 0, row, GRID_COLS-1, row);
289

    
290

    
291

    
292
        setAdvancedModeEnabled(true);
293
        enableBasionymFields(HAS_BASIONYM_DEFAULT);
294
        registerAdvancedModeComponents(fullTitleCacheFiled, protectedNameCacheField);
295
        registerAdvancedModeComponents(basionymAuthorshipField.getCachFields());
296
        registerAdvancedModeComponents(exBasionymAuthorshipField.getCachFields());
297
        registerAdvancedModeComponents(combinationAuthorshipField.getCachFields());
298
        registerAdvancedModeComponents(exCombinationAuthorshipField.getCachFields());
299
        setAdvancedMode(false);
300

    
301
    }
302

    
303
    /**
304
     * @param value
305
     * @return
306
     */
307
    private void enableBasionymFields(boolean enable) {
308
        basionymAuthorshipField.setVisible(enable);
309
        exBasionymAuthorshipField.setVisible(enable);
310
        basionymCombobox.setVisible(enable);
311
        if(modesActive.contains(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData)){
312
            TaxonName taxonName = getBean();
313
            basionymAuthorshipField.setVisible(taxonName.getBasionymAuthorship() != null);
314
        }
315
    }
316

    
317
    /**
318
     * @param rank
319
     * @return
320
     */
321
    private void updateFieldVisibility(Rank rank) {
322
        boolean isSpeciesOrBelow = !rank.isHigher(Rank.SPECIES());
323
        // TODO use getField() instead and remove field references
324
        infraSpecificEpithetField.setVisible(rank.isInfraSpecific());
325
        specificEpithetField.setVisible(isSpeciesOrBelow);
326
        infraGenericEpithetField.setVisible(rank.isInfraGenericButNotSpeciesGroup());
327
        genusOrUninomialField.setCaption(isSpeciesOrBelow ? "Genus" : "Uninomial");
328
    }
329

    
330
    @Override
331
    protected void afterItemDataSourceSet() {
332
        TaxonName taxonName = getBean();
333
        boolean showBasionymSection = taxonName.getBasionyms().size() > 0
334
                || taxonName.getBasionymAuthorship() != null
335
                || taxonName.getExBasionymAuthorship() != null;
336
        basionymToggle.setValue(showBasionymSection);
337

    
338
        if(isModeEnabled(TaxonNamePopupEditorMode.suppressReplacementAuthorshipData)){
339
            combinationAuthorshipField.setVisible(taxonName.getCombinationAuthorship() != null);
340
        }
341

    
342
    }
343

    
344
    /**
345
     * {@inheritDoc}
346
     */
347
    @Override
348
    public boolean allowAnonymousAccess() {
349
        return false;
350
    }
351

    
352
    /**
353
     * {@inheritDoc}
354
     */
355
    @Override
356
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
357
        return null;
358
    }
359

    
360
    /**
361
     * {@inheritDoc}
362
     */
363
    @Override
364
    public ToOneRelatedEntityCombobox<Reference> getNomReferenceCombobox() {
365
        return nomReferenceCombobox;
366
    }
367

    
368
    /**
369
     * {@inheritDoc}
370
     */
371
    @Override
372
    public ToManyRelatedEntitiesComboboxSelect<TaxonName> getBasionymCombobox() {
373
        return basionymCombobox;
374
    }
375

    
376
    /**
377
     * {@inheritDoc}
378
     */
379
    @Override
380
    public ListSelect getRankSelect() {
381
        return rankSelect;
382
    }
383

    
384
    /**
385
     * @return the exBasionymAuthorshipField
386
     */
387
    @Override
388
    public TeamOrPersonField getExBasionymAuthorshipField() {
389
        return exBasionymAuthorshipField;
390
    }
391

    
392
    /**
393
     * @return the basionymAuthorshipField
394
     */
395
    @Override
396
    public TeamOrPersonField getBasionymAuthorshipField() {
397
        return basionymAuthorshipField;
398
    }
399

    
400
    /**
401
     * @return the combinationAuthorshipField
402
     */
403
    @Override
404
    public TeamOrPersonField getCombinationAuthorshipField() {
405
        return combinationAuthorshipField;
406
    }
407

    
408
    /**
409
     * @return the exCombinationAuthorshipField
410
     */
411
    @Override
412
    public TeamOrPersonField getExCombinationAuthorshipField() {
413
        return exCombinationAuthorshipField;
414
    }
415

    
416
    @Override
417
    public void enableMode(TaxonNamePopupEditorMode mode){
418
        modesActive.add(mode);
419
    }
420

    
421
    @Override
422
    public boolean isModeEnabled(TaxonNamePopupEditorMode mode){
423
        return modesActive.contains(mode);
424
    }
425

    
426
    @Override
427
    public void disableMode(TaxonNamePopupEditorMode mode){
428
        modesActive.remove(mode);
429
    }
430

    
431

    
432
}
(7-7/10)