1
|
/**
|
2
|
* Copyright (C) 2015 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.component.taxon;
|
10
|
|
11
|
import java.sql.SQLException;
|
12
|
import java.util.Collection;
|
13
|
import java.util.UUID;
|
14
|
|
15
|
import com.vaadin.data.util.filter.Compare;
|
16
|
import com.vaadin.data.util.filter.Compare.Equal;
|
17
|
|
18
|
import eu.etaxonomy.cdm.api.service.ITaxonService;
|
19
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
20
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
21
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
22
|
import eu.etaxonomy.cdm.vaadin.component.taxon.IStatusComposite.StatusComponentListener;
|
23
|
import eu.etaxonomy.cdm.vaadin.container.CdmSQLContainer;
|
24
|
import eu.etaxonomy.cdm.vaadin.container.LeafNodeTaxonContainer;
|
25
|
import eu.etaxonomy.cdm.vaadin.util.CdmQueryFactory;
|
26
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
27
|
|
28
|
/**
|
29
|
* @author cmathew
|
30
|
* @since 10 Mar 2015
|
31
|
*
|
32
|
*/
|
33
|
public class StatusPresenter implements StatusComponentListener {
|
34
|
|
35
|
|
36
|
public final static String C_TCACHE_ID = "titleCache";
|
37
|
|
38
|
private LeafNodeTaxonContainer leafNodeTaxonContainer;
|
39
|
|
40
|
private CdmSQLContainer classificationContainer;
|
41
|
|
42
|
private final ITaxonService taxonService;
|
43
|
|
44
|
private int totalNoOfTaxa = 0;
|
45
|
|
46
|
public StatusPresenter() {
|
47
|
taxonService = CdmSpringContextHelper.getTaxonService();
|
48
|
}
|
49
|
|
50
|
|
51
|
@Override
|
52
|
public void removeFilters() {
|
53
|
removeUnplacedFilter();
|
54
|
removeUnpublishedFilter();
|
55
|
removeNameFilter();
|
56
|
}
|
57
|
|
58
|
@Override
|
59
|
public LeafNodeTaxonContainer loadTaxa(int classificationId) throws SQLException {
|
60
|
leafNodeTaxonContainer = new LeafNodeTaxonContainer(classificationId);
|
61
|
totalNoOfTaxa = leafNodeTaxonContainer.getTotalNoOfTaxa();
|
62
|
return leafNodeTaxonContainer;
|
63
|
}
|
64
|
|
65
|
@Override
|
66
|
public Object getClassificationId(String classification) {
|
67
|
if(classification == null) {
|
68
|
return null;
|
69
|
}
|
70
|
Equal cnameFilter = new Compare.Equal("titleCache", classification);
|
71
|
classificationContainer.addContainerFilter(cnameFilter);
|
72
|
Collection<?> itemIds = classificationContainer.getItemIds();
|
73
|
Object itemId = null;
|
74
|
if(!itemIds.isEmpty()) {
|
75
|
itemId = itemIds.iterator().next();
|
76
|
}
|
77
|
classificationContainer.removeContainerFilter(cnameFilter);
|
78
|
return itemId;
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
public void refresh() {
|
83
|
leafNodeTaxonContainer.refresh();
|
84
|
}
|
85
|
@Override
|
86
|
public void setUnplacedFilter() {
|
87
|
leafNodeTaxonContainer.setUnplacedFilter();
|
88
|
}
|
89
|
|
90
|
@Override
|
91
|
public void removeUnplacedFilter() {
|
92
|
leafNodeTaxonContainer.removeUnplacedFilter();
|
93
|
}
|
94
|
|
95
|
@Override
|
96
|
public void setUnpublishedFilter() {
|
97
|
leafNodeTaxonContainer.setUnpublishedFilter();
|
98
|
}
|
99
|
|
100
|
@Override
|
101
|
public void removeUnpublishedFilter() {
|
102
|
leafNodeTaxonContainer.removeUnpublishedFilter();
|
103
|
}
|
104
|
|
105
|
@Override
|
106
|
public void setNameFilter(String filterString) {
|
107
|
leafNodeTaxonContainer.setNameFilter(filterString);
|
108
|
}
|
109
|
|
110
|
@Override
|
111
|
public void removeNameFilter() {
|
112
|
leafNodeTaxonContainer.removeNameFilter();
|
113
|
}
|
114
|
|
115
|
@Override
|
116
|
public void setIdFilter(Object itemId) {
|
117
|
leafNodeTaxonContainer.setIdFilter(itemId);
|
118
|
}
|
119
|
|
120
|
@Override
|
121
|
public void removeIdFilter() {
|
122
|
leafNodeTaxonContainer.removeDynamicFilters();
|
123
|
}
|
124
|
|
125
|
@Override
|
126
|
public void removeDynamicFilters() {
|
127
|
leafNodeTaxonContainer.removeDynamicFilters();
|
128
|
}
|
129
|
|
130
|
@Override
|
131
|
public int getCurrentNoOfTaxa() {
|
132
|
return leafNodeTaxonContainer.size();
|
133
|
}
|
134
|
|
135
|
@Override
|
136
|
public int getTotalNoOfTaxa() {
|
137
|
return totalNoOfTaxa;
|
138
|
}
|
139
|
|
140
|
@Override
|
141
|
public boolean isSynonym(Object itemId) {
|
142
|
return leafNodeTaxonContainer.isSynonym(itemId);
|
143
|
}
|
144
|
|
145
|
@Override
|
146
|
public void refreshSynonymCache() {
|
147
|
leafNodeTaxonContainer.refreshSynonymCache();
|
148
|
}
|
149
|
|
150
|
@Override
|
151
|
public CdmSQLContainer loadClassifications() throws SQLException {
|
152
|
classificationContainer = CdmSQLContainer.newInstance("Classification");
|
153
|
return classificationContainer;
|
154
|
}
|
155
|
|
156
|
|
157
|
@Override
|
158
|
public void updatePublished(boolean pb, Object itemId) {
|
159
|
UUID uuid = UUID.fromString((String)leafNodeTaxonContainer.getItem(itemId).getItemProperty(CdmQueryFactory.UUID_ID).getValue());
|
160
|
TaxonBase taxonBase = taxonService.load(uuid);
|
161
|
Taxon taxon = CdmBase.deproxy(taxonBase, Taxon.class);
|
162
|
boolean currentPb = taxon.isPublish();
|
163
|
if(currentPb != pb) {
|
164
|
taxon.setPublish(pb);
|
165
|
taxonService.merge(taxon);
|
166
|
}
|
167
|
}
|
168
|
|
169
|
@Override
|
170
|
public LeafNodeTaxonContainer getCurrentLeafNodeTaxonContainer() {
|
171
|
return leafNodeTaxonContainer;
|
172
|
}
|
173
|
|
174
|
@Override
|
175
|
public CdmSQLContainer getClassificationContainer() {
|
176
|
return classificationContainer;
|
177
|
}
|
178
|
|
179
|
}
|