Project

General

Profile

Download (14 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

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

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

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

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

    
43
    private final static int GRID_COLS = 4;
44

    
45
    private final static int GRID_ROWS = 12;
46

    
47
    private static final boolean HAS_BASIONYM_DEFAULT = false;
48

    
49
    private TextField genusOrUninomialField;
50

    
51
    private TextField infraGenericEpithetField;
52

    
53
    private TextField specificEpithetField;
54

    
55
    private TextField infraSpecificEpithetField;
56

    
57
    private SwitchableTextField fullTitleCacheFiled;
58

    
59
    private SwitchableTextField protectedNameCacheField;
60

    
61
    private ToOneRelatedEntityCombobox<Reference> nomReferenceCombobox;
62

    
63
    private TextField nomenclaturalReferenceDetail;
64

    
65
    private TeamOrPersonField exBasionymAuthorshipField;
66

    
67
    private TeamOrPersonField basionymAuthorshipField;
68

    
69
    private ToManyRelatedEntitiesComboboxSelect<TaxonName> basionymCombobox;
70

    
71
    private CheckBox basionymToggle;
72

    
73
    private ListSelect rankSelect;
74

    
75
    private TeamOrPersonField combinationAuthorshipField;
76

    
77
    private TeamOrPersonField exCombinationAuthorshipField;
78

    
79

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

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

    
96

    
97

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

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

    
113
    }
114

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

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

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

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

    
144
         - fullTitleCache + protectedFullTitleCache -> SwitchableTextField : ADVANCED_MODE
145
         - nameCache + protectedNameCache -> SwitchableTextField : ADVANCED_MODE
146

    
147
         - homotypicalGroup -> hidden
148
         - typeDesignations -> hidden
149
         - descriptions -> hidden
150
         - taxonBases -> hidden
151
         - registrations -> hidden
152

    
153
         - relationsFromThisName-> TODO implement later
154
         - relationsToThisName -> TODO implement later
155

    
156
         - genusOrUninomial -> textField
157
         - infraGenericEpithet  -> textField
158
         - specificEpithet  -> textField
159
         - infraSpecificEpithet  -> textField
160

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

    
167
         - status -> TODO field
168
         - monomHybrid -> TODO implement hybrids later
169
         - binomHybrid -> TODO implement hybrids later
170
         - trinomHybrid -> TODO implement hybrids later
171

    
172
         - hybridParentRelations -> TODO implement hybrids later
173
         - hybridChildRelations -> TODO implement hybrids later
174
         - hybridFormula -> TODO implement hybrids later
175

    
176
         ** ViralName attributes **
177
         - acronym
178

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

    
188
        int row = 0;
189

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

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

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

    
255

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

    
288

    
289

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

    
299
    }
300

    
301
    /**
302
     * @param value
303
     * @return
304
     */
305
    private void enableBasionymFields(boolean enable) {
306
        basionymAuthorshipField.setVisible(enable);
307
        exBasionymAuthorshipField.setVisible(enable);
308
        basionymCombobox.setVisible(enable);
309
    }
310

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

    
324
    @Override
325
    protected void afterItemDataSourceSet() {
326
        TaxonName taxonName = getBean();
327
        boolean showBasionymSection = taxonName.getBasionyms().size() > 0
328
                || taxonName.getBasionymAuthorship() != null
329
                || taxonName.getExBasionymAuthorship() != null;
330
        basionymToggle.setValue(showBasionymSection);
331

    
332
    }
333

    
334
    /**
335
     * {@inheritDoc}
336
     */
337
    @Override
338
    public boolean allowAnonymousAccess() {
339
        return false;
340
    }
341

    
342
    /**
343
     * {@inheritDoc}
344
     */
345
    @Override
346
    public Collection<Collection<GrantedAuthority>> allowedGrantedAuthorities() {
347
        return null;
348
    }
349

    
350
    /**
351
     * {@inheritDoc}
352
     */
353
    @Override
354
    public ToOneRelatedEntityCombobox<Reference> getNomReferenceCombobox() {
355
        return nomReferenceCombobox;
356
    }
357

    
358
    /**
359
     * {@inheritDoc}
360
     */
361
    @Override
362
    public ToManyRelatedEntitiesComboboxSelect<TaxonName> getBasionymCombobox() {
363
        return basionymCombobox;
364
    }
365

    
366
    /**
367
     * {@inheritDoc}
368
     */
369
    @Override
370
    public ListSelect getRankSelect() {
371
        return rankSelect;
372
    }
373

    
374
    /**
375
     * @return the exBasionymAuthorshipField
376
     */
377
    @Override
378
    public TeamOrPersonField getExBasionymAuthorshipField() {
379
        return exBasionymAuthorshipField;
380
    }
381

    
382
    /**
383
     * @return the basionymAuthorshipField
384
     */
385
    @Override
386
    public TeamOrPersonField getBasionymAuthorshipField() {
387
        return basionymAuthorshipField;
388
    }
389

    
390
    /**
391
     * @return the combinationAuthorshipField
392
     */
393
    @Override
394
    public TeamOrPersonField getCombinationAuthorshipField() {
395
        return combinationAuthorshipField;
396
    }
397

    
398
    /**
399
     * @return the exCombinationAuthorshipField
400
     */
401
    @Override
402
    public TeamOrPersonField getExCombinationAuthorshipField() {
403
        return exCombinationAuthorshipField;
404
    }
405

    
406

    
407

    
408

    
409
}
(7-7/9)