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