Project

General

Profile

Download (3.58 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.Arrays;
12
import java.util.List;
13

    
14
import org.vaadin.viritin.fields.CaptionGenerator;
15
import org.vaadin.viritin.fields.LazyComboBox.FilterableCountProvider;
16
import org.vaadin.viritin.fields.LazyComboBox.FilterablePagingProvider;
17

    
18
import eu.etaxonomy.cdm.api.service.DeleteResult;
19
import eu.etaxonomy.cdm.api.service.config.NameDeletionConfigurator;
20
import eu.etaxonomy.cdm.api.service.pager.Pager;
21
import eu.etaxonomy.cdm.model.name.TaxonName;
22
import eu.etaxonomy.cdm.model.reference.Reference;
23
import eu.etaxonomy.cdm.persistence.query.MatchMode;
24
import eu.etaxonomy.cdm.persistence.query.OrderHint;
25
import eu.etaxonomy.vaadin.mvp.AbstractCdmEditorPresenter;
26

    
27
/**
28
 * @author a.kohlbecker
29
 * @since May 22, 2017
30
 *
31
 */
32
public class TaxonNameEditorPresenter extends AbstractCdmEditorPresenter<TaxonName, TaxonNamePopupEditorView> {
33

    
34
    private static final long serialVersionUID = -3538980627079389221L;
35

    
36
    /**
37
     * {@inheritDoc}
38
     */
39
    @Override
40
    public void handleViewEntered() {
41
        super.handleViewEntered();
42

    
43
        getView().getNomReferenceCombobox().getSelect().setCaptionGenerator(new CaptionGenerator<Reference>(){
44

    
45
            @Override
46
            public String getCaption(Reference option) {
47
                return option.getTitleCache();
48
            }
49

    
50
        });
51
        getView().getNomReferenceCombobox().loadFrom(new FilterablePagingProvider<Reference>(){
52

    
53
            @Override
54
            public List<Reference> findEntities(int firstRow, String filter) {
55
                Pager<Reference> page = getRepo().getReferenceService().findByTitle(
56
                        null,
57
                        filter,
58
                        MatchMode.ANYWHERE,
59
                        null,
60
                        20,
61
                        firstRow,
62
                        OrderHint.ORDER_BY_TITLE_CACHE.asList(),
63
                        Arrays.asList("$")
64
                      );
65
                return page.getRecords();
66
            }},
67
            new FilterableCountProvider(){
68
                @Override
69
                public int size(String filter) {
70
                    Pager<Reference> page = getRepo().getReferenceService().findByTitle(
71
                            null,
72
                            filter,
73
                            MatchMode.ANYWHERE,
74
                            null,
75
                            1,
76
                            0,
77
                            null,
78
                            null
79
                          );
80
                    return page.getCount().intValue();
81
                }}
82
            , 20);
83
    }
84

    
85
    @Override
86
    protected TaxonName prepareAsFieldGroupDataSource(TaxonName bean){
87
        TaxonName initializedBean = getRepo().getNameService().load(bean.getUuid(), Arrays.asList(
88
                "$",
89
                "basionymAuthorship",
90
                "combinationAuthorship",
91
                "exCombinationAuthorship",
92
                "exBasionymAuthorship",
93
                "nomenclaturalReference.authorship.teamMembers"));
94
        return initializedBean;
95
    }
96

    
97

    
98
    /**
99
     * {@inheritDoc}
100
     */
101
    @Override
102
    protected DeleteResult executeServiceDeleteOperation(TaxonName bean) {
103
        NameDeletionConfigurator config = new NameDeletionConfigurator();
104
        return getRepo().getNameService().delete(bean.getUuid(), config);
105
    }
106

    
107

    
108
}
(1-1/3)