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.distributionStatus.settings;
|
10
|
|
11
|
import java.util.Arrays;
|
12
|
import java.util.Collections;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import com.vaadin.data.Container;
|
17
|
import com.vaadin.data.util.IndexedContainer;
|
18
|
import com.vaadin.server.VaadinSession;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.common.TermType;
|
21
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
22
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
23
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
24
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
25
|
import eu.etaxonomy.cdm.model.taxon.Classification;
|
26
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
27
|
import eu.etaxonomy.cdm.vaadin.util.CdmSpringContextHelper;
|
28
|
import eu.etaxonomy.cdm.vaadin.util.DistributionEditorUtil;
|
29
|
|
30
|
/**
|
31
|
* @author a.mueller
|
32
|
* @date 22.10.2017
|
33
|
*
|
34
|
*/
|
35
|
public class AreaAndTaxonSettingsPresenter extends SettingsPresenterBase {
|
36
|
|
37
|
private Container areaContainer;
|
38
|
private UUID areaVocabUUID;
|
39
|
|
40
|
/**
|
41
|
* @param distributionContainer
|
42
|
* @param vocUUID
|
43
|
*/
|
44
|
public AreaAndTaxonSettingsPresenter() {
|
45
|
super();
|
46
|
Object selectedVocabularyUuidString = VaadinSession.getCurrent()
|
47
|
.getAttribute(DistributionEditorUtil.SATTR_SELECTED_AREA_VOCABULARY_UUID);
|
48
|
if(selectedVocabularyUuidString!=null){
|
49
|
areaVocabUUID = UUID.fromString(selectedVocabularyUuidString.toString());
|
50
|
}
|
51
|
areaContainer = new IndexedContainer(getNamedAreaList());
|
52
|
}
|
53
|
|
54
|
|
55
|
|
56
|
public Container getAreaContainer() {
|
57
|
return areaContainer;
|
58
|
}
|
59
|
|
60
|
private List<TermVocabulary<? extends NamedArea>> getNamedAreaList() {
|
61
|
CdmPreference areaVocPref = CdmSpringContextHelper.getPreferenceService()
|
62
|
.findVaadin(PreferencePredicate.AvailableDistributionAreaVocabularies);
|
63
|
if (areaVocPref != null){
|
64
|
List<UUID> uuidList = areaVocPref.getValueUuidList();
|
65
|
return (List)CdmSpringContextHelper.getVocabularyService().load(uuidList, VOCABULARY_INIT_STRATEGY);
|
66
|
}else{
|
67
|
return (List)CdmSpringContextHelper.getVocabularyService().findByTermType(TermType.NamedArea, VOCABULARY_INIT_STRATEGY);
|
68
|
}
|
69
|
}
|
70
|
|
71
|
|
72
|
public TermVocabulary<NamedArea> getChosenAreaVoc(){
|
73
|
return CdmSpringContextHelper.getVocabularyService().load(areaVocabUUID, VOCABULARY_INIT_STRATEGY);
|
74
|
}
|
75
|
|
76
|
|
77
|
public List<TaxonNode> getChosenTaxonNodes(){
|
78
|
List<UUID> nodeUuids = (List<UUID>) VaadinSession.getCurrent()
|
79
|
.getAttribute(DistributionEditorUtil.SATTR_TAXON_NODES_UUID);
|
80
|
if(nodeUuids!=null){
|
81
|
return CdmSpringContextHelper.getTaxonNodeService().load(nodeUuids, null);
|
82
|
}
|
83
|
return Collections.emptyList();
|
84
|
}
|
85
|
|
86
|
public Classification getChosenClassification(){
|
87
|
UUID uuid = (UUID) VaadinSession.getCurrent().getAttribute(DistributionEditorUtil.SATTR_CLASSIFICATION);
|
88
|
if(uuid!=null){
|
89
|
return CdmSpringContextHelper.getClassificationService().load(uuid);
|
90
|
}
|
91
|
return null;
|
92
|
}
|
93
|
|
94
|
|
95
|
protected static final List<String> VOCABULARY_INIT_STRATEGY = Arrays.asList(new String []{
|
96
|
"$",
|
97
|
"terms",
|
98
|
"terms.*",
|
99
|
});
|
100
|
|
101
|
}
|