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.taxon;
|
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.TaxonNameBase;
|
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<TaxonNameBase, 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
|
|
86
|
/**
|
87
|
* {@inheritDoc}
|
88
|
*/
|
89
|
@Override
|
90
|
protected DeleteResult executeServiceDeleteOperation(TaxonNameBase bean) {
|
91
|
NameDeletionConfigurator config = new NameDeletionConfigurator();
|
92
|
return getRepo().getNameService().delete(bean.getUuid(), config);
|
93
|
}
|
94
|
|
95
|
|
96
|
}
|