1
|
/**
|
2
|
* Copyright (C) 2018 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.Collection;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Map;
|
16
|
import java.util.Set;
|
17
|
import java.util.UUID;
|
18
|
|
19
|
import org.apache.commons.lang.StringUtils;
|
20
|
import org.eclipse.swt.widgets.Composite;
|
21
|
|
22
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
23
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
24
|
import eu.etaxonomy.cdm.model.common.TermType;
|
25
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
26
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
27
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
28
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
29
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
30
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
31
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySession;
|
32
|
import eu.etaxonomy.taxeditor.session.ICdmEntitySessionEnabled;
|
33
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
34
|
|
35
|
/**
|
36
|
* @author k.luther
|
37
|
* @since 04.06.2018
|
38
|
*
|
39
|
*/
|
40
|
public class AvailableAreaVocabulariesPage extends AbstractTermSelectionWizardPage implements ICdmEntitySessionEnabled{
|
41
|
|
42
|
CdmPreference pref;
|
43
|
String featureTitle;
|
44
|
/**
|
45
|
* @param pageName
|
46
|
*/
|
47
|
public AvailableAreaVocabulariesPage(String pageName, boolean localPref, CdmPreference pref, String featureTitle) {
|
48
|
super(pageName, TermType.NamedArea);
|
49
|
this.localPref = localPref;
|
50
|
this.pref = pref;
|
51
|
this.featureTitle = featureTitle;
|
52
|
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* {@inheritDoc}
|
57
|
*/
|
58
|
@Override
|
59
|
public void createControl(Composite parent) {
|
60
|
|
61
|
setTitle(String.format(Messages.AvailableAreaVocabulariesPage_PAGE_TITLE, featureTitle));
|
62
|
setDescription(String.format(Messages.AvailableAreaVocabulariesPage_PAGE_DESCRIPTION, featureTitle));
|
63
|
|
64
|
super.createControl(parent);
|
65
|
}
|
66
|
|
67
|
/**
|
68
|
* {@inheritDoc}
|
69
|
*/
|
70
|
@Override
|
71
|
protected String getCheckedValuesFromPreferences() {
|
72
|
String vocString = null;
|
73
|
if (localPref){
|
74
|
vocString = PreferencesUtil.getPreferredVocabulariesForDistributionEditor(localPref);
|
75
|
}else if (pref != null){
|
76
|
vocString = pref.getValue();
|
77
|
}
|
78
|
return vocString;
|
79
|
}
|
80
|
|
81
|
/**
|
82
|
* {@inheritDoc}
|
83
|
*/
|
84
|
@Override
|
85
|
protected String getGrayedValuesFromPreferences() {
|
86
|
// TODO Auto-generated method stub
|
87
|
return null;
|
88
|
}
|
89
|
|
90
|
/**
|
91
|
* {@inheritDoc}
|
92
|
*/
|
93
|
@Override
|
94
|
public ICdmEntitySession getCdmEntitySession() {
|
95
|
return null;
|
96
|
}
|
97
|
|
98
|
/**
|
99
|
* {@inheritDoc}
|
100
|
*/
|
101
|
@Override
|
102
|
public <T extends CdmBase> Collection<T> getRootEntities() {
|
103
|
return null;
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* {@inheritDoc}
|
108
|
*/
|
109
|
@Override
|
110
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
111
|
return null;
|
112
|
}
|
113
|
|
114
|
@Override
|
115
|
protected List<TermVocabularyDto> getVocabulariesFromPreference(){
|
116
|
List<TermVocabularyDto> vocs = new ArrayList<>();
|
117
|
|
118
|
if (PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies) == null ){
|
119
|
vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
|
120
|
}else{
|
121
|
String vocString = PreferencesUtil.getStringValue(PreferencesUtil.DISTRIBUTION_VOCABULARIES);
|
122
|
|
123
|
String[] arrayVocs = vocString.split(";"); //$NON-NLS-1$
|
124
|
|
125
|
Set<UUID> uuidVocs = new HashSet();
|
126
|
for (String voc: arrayVocs){
|
127
|
if (!StringUtils.isBlank(voc)){
|
128
|
uuidVocs.add(UUID.fromString(voc));
|
129
|
}
|
130
|
}
|
131
|
List<TermVocabulary> tempVocs = CdmStore.getService(IVocabularyService.class).find(uuidVocs);
|
132
|
for (TermVocabulary voc: tempVocs){
|
133
|
vocs.add(new TermVocabularyDto(voc.getUuid(), voc.getRepresentations()));
|
134
|
}
|
135
|
|
136
|
}
|
137
|
return vocs;
|
138
|
}
|
139
|
|
140
|
}
|