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