1 |
1 |
package eu.etaxonomy.cdm.vaadin.container;
|
2 |
2 |
|
3 |
3 |
import java.util.Collection;
|
|
4 |
import java.util.HashSet;
|
4 |
5 |
import java.util.Set;
|
5 |
6 |
|
6 |
7 |
import com.vaadin.data.util.BeanItemContainer;
|
... | ... | |
16 |
17 |
|
17 |
18 |
private static final long serialVersionUID = -7891310979870159325L;
|
18 |
19 |
|
19 |
|
public PresenceAbsenceTermContainer()
|
|
20 |
private static PresenceAbsenceTermContainer instance;
|
|
21 |
private static Collection<PresenceAbsenceTerm> defaultDistributionStatus;
|
|
22 |
|
|
23 |
private PresenceAbsenceTermContainer()
|
20 |
24 |
throws IllegalArgumentException {
|
21 |
25 |
super(PresenceAbsenceTerm.class);
|
22 |
|
Collection<PresenceAbsenceTerm> distributionStatus = (Set<PresenceAbsenceTerm>) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS);
|
23 |
|
if(distributionStatus==null || distributionStatus.isEmpty()){
|
24 |
|
distributionStatus = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
|
25 |
|
}
|
|
26 |
initDataModel();
|
|
27 |
}
|
|
28 |
|
|
29 |
private void initDataModel() {
|
|
30 |
Collection<PresenceAbsenceTerm> distributionStatus = new HashSet<>();
|
|
31 |
distributionStatus = CdmSpringContextHelper.getTermService().listByTermType(TermType.PresenceAbsenceTerm, null, null, null, null);
|
|
32 |
defaultDistributionStatus = distributionStatus;
|
26 |
33 |
TermCacher termCacher = TermCacher.getInstance();
|
|
34 |
addAll(distributionStatus);
|
27 |
35 |
for (PresenceAbsenceTerm presenceAbsenceTerm : distributionStatus) {
|
28 |
36 |
termCacher.addPresenceAbsenceTerm(presenceAbsenceTerm);
|
29 |
|
addBean(presenceAbsenceTerm);
|
30 |
37 |
}
|
|
38 |
}
|
|
39 |
|
|
40 |
public static PresenceAbsenceTermContainer getInstance(){
|
|
41 |
if(instance==null){
|
|
42 |
instance = new PresenceAbsenceTermContainer();
|
|
43 |
}
|
|
44 |
Collection<PresenceAbsenceTerm> distributionStatus = new HashSet<>();
|
|
45 |
Object attribute = VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_DISTRIBUTION_STATUS);
|
|
46 |
if(attribute!=null){
|
|
47 |
distributionStatus = (Set<PresenceAbsenceTerm>) attribute;
|
|
48 |
}
|
|
49 |
if(!distributionStatus.isEmpty() && !distributionStatus.equals(defaultDistributionStatus)){
|
|
50 |
instance.removeAllItems();
|
|
51 |
instance.addAll(distributionStatus);
|
|
52 |
defaultDistributionStatus = distributionStatus;
|
|
53 |
}
|
|
54 |
return instance;
|
31 |
55 |
}
|
32 |
56 |
|
33 |
57 |
}
|
ref #5458 performance tweak for distribution status selection