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