1
|
/**
|
2
|
* Copyright (C) 2014 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.taxeditor.preference.wizard;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.Collection;
|
14
|
import java.util.HashMap;
|
15
|
import java.util.HashSet;
|
16
|
import java.util.List;
|
17
|
import java.util.Map;
|
18
|
import java.util.Set;
|
19
|
import java.util.UUID;
|
20
|
|
21
|
import org.apache.commons.lang.StringUtils;
|
22
|
import org.eclipse.swt.widgets.Composite;
|
23
|
|
24
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
25
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
26
|
import eu.etaxonomy.cdm.model.common.TermType;
|
27
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
28
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
29
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
30
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
31
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
32
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
33
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
34
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
35
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
36
|
|
37
|
/**
|
38
|
* @author a.oppermann
|
39
|
* @date 21.07.2014
|
40
|
*
|
41
|
*/
|
42
|
public class AvailableDistributionPage extends AbstractTermSelectionWizardPage implements ICdmEntitySessionEnabled {
|
43
|
|
44
|
protected AvailableDistributionPage(String pageName) {
|
45
|
super(pageName, TermType.NamedArea);
|
46
|
this.localPref = true;
|
47
|
|
48
|
}
|
49
|
|
50
|
@Override
|
51
|
public void createControl(Composite parent) {
|
52
|
setTitle(Messages.AvailableDistributionPage_PAGE_TITLE);
|
53
|
setDescription(Messages.AvailableDistributionPage_PAGE_DESCRIPTION);
|
54
|
|
55
|
super.createControl(parent);
|
56
|
}
|
57
|
|
58
|
@Override
|
59
|
protected String getCheckedValuesFromPreferences() {
|
60
|
return PreferencesUtil.getStringValue(IPreferenceKeys.DISTRIBUTION_AREA_OCCURENCE_STATUS);
|
61
|
}
|
62
|
|
63
|
@Override
|
64
|
public void dispose() {
|
65
|
CdmStore.getCurrentSessionManager().dispose(this);
|
66
|
super.dispose();
|
67
|
}
|
68
|
|
69
|
@Override
|
70
|
public ICdmEntitySession getCdmEntitySession() {
|
71
|
return CdmStore.getCurrentSessionManager().getNullSession();
|
72
|
}
|
73
|
|
74
|
@Override
|
75
|
public <T extends CdmBase> Collection<T> getRootEntities() {
|
76
|
return null;
|
77
|
}
|
78
|
|
79
|
@Override
|
80
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
81
|
Map<Object, List<String>> propertyPathsMap = new HashMap<Object, List<String>>();
|
82
|
List<String> termsPropertyPaths = Arrays.asList(new String[] {
|
83
|
"includes" //$NON-NLS-1$
|
84
|
});
|
85
|
propertyPathsMap.put("includes", termsPropertyPaths); //$NON-NLS-1$
|
86
|
propertyPathsMap.put("terms", termsPropertyPaths); //$NON-NLS-1$
|
87
|
return propertyPathsMap;
|
88
|
}
|
89
|
|
90
|
@Override
|
91
|
protected List<TermVocabularyDto> getVocabulariesFromPreference(){
|
92
|
List<TermVocabularyDto> vocs = new ArrayList<>();
|
93
|
|
94
|
if (PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies) == null && PreferencesUtil.getStringValue(PreferencesUtil.DISTRIBUTION_VOCABULARIES) == null){
|
95
|
vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
|
96
|
}else{
|
97
|
String vocString = PreferencesUtil.getStringValue(IPreferenceKeys.DISTRIBUTION_VOCABULARIES);
|
98
|
|
99
|
String[] arrayVocs = vocString.split(";"); //$NON-NLS-1$
|
100
|
|
101
|
Set<UUID> uuidVocs = new HashSet<>();
|
102
|
for (String voc: arrayVocs){
|
103
|
if (!StringUtils.isBlank(voc)){
|
104
|
uuidVocs.add(UUID.fromString(voc));
|
105
|
}
|
106
|
}
|
107
|
List<TermVocabulary> tempVocs = CdmStore.getService(IVocabularyService.class).find(uuidVocs);
|
108
|
for (TermVocabulary voc: tempVocs){
|
109
|
vocs.add(new TermVocabularyDto(voc.getUuid(), voc.getRepresentations()));
|
110
|
}
|
111
|
|
112
|
}
|
113
|
return vocs;
|
114
|
}
|
115
|
|
116
|
}
|