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.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.commons.lang3.StringUtils;
|
17
|
import org.eclipse.swt.widgets.Composite;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
20
|
import eu.etaxonomy.cdm.model.metadata.CdmPreference;
|
21
|
import eu.etaxonomy.cdm.model.term.TermType;
|
22
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
23
|
import eu.etaxonomy.taxeditor.editor.definedterm.RootElementsOnlyTreeContentProvider;
|
24
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
25
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
26
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
27
|
|
28
|
|
29
|
/**
|
30
|
* @author k.luther
|
31
|
* @since 04.06.2018
|
32
|
*
|
33
|
*/
|
34
|
public class AvailableAreaVocabulariesPage extends AbstractTermSelectionWizardPage<TermVocabularyDto>{
|
35
|
|
36
|
String featureTitle;
|
37
|
|
38
|
public AvailableAreaVocabulariesPage(String pageName, boolean localPref, CdmPreference pref, String featureTitle) {
|
39
|
super(pageName, TermType.NamedArea);
|
40
|
this.localPref = localPref;
|
41
|
this.featureTitle = featureTitle;
|
42
|
this.pref = pref;
|
43
|
|
44
|
|
45
|
}
|
46
|
|
47
|
// public AvailableAreaVocabulariesPage(String pageName, boolean localPref, CdmPreference pref, String featureTitle) {
|
48
|
// this(pageName, localPref, pref, featureTitle);
|
49
|
//
|
50
|
// }
|
51
|
|
52
|
@Override
|
53
|
public void createControl(Composite parent) {
|
54
|
|
55
|
setTitle(String.format(Messages.AvailableAreaVocabulariesPage_PAGE_TITLE, featureTitle));
|
56
|
setDescription(String.format(Messages.AvailableAreaVocabulariesPage_PAGE_DESCRIPTION, featureTitle));
|
57
|
if (!localPref){
|
58
|
createAllowOverrideButton(parent);
|
59
|
}
|
60
|
|
61
|
super.createControl(parent);
|
62
|
|
63
|
treeComposite.getViewer().setContentProvider(new RootElementsOnlyTreeContentProvider());
|
64
|
treeComposite.setAllowTopLevelSelection(true);
|
65
|
}
|
66
|
|
67
|
|
68
|
|
69
|
@Override
|
70
|
protected String getCheckedValuesFromPreferences() {
|
71
|
String vocString = null;
|
72
|
if (localPref){
|
73
|
vocString = PreferencesUtil.getPreferredVocabulariesForDistributionEditor(localPref);
|
74
|
if (StringUtils.isBlank(vocString) && pref != null){
|
75
|
vocString = pref.getValue();
|
76
|
}
|
77
|
this.override = PreferencesUtil.getOverrideForPreference(pref.getPredicate());
|
78
|
}else if (pref != null){
|
79
|
vocString = pref.getValue();
|
80
|
}
|
81
|
return vocString;
|
82
|
}
|
83
|
|
84
|
|
85
|
|
86
|
|
87
|
|
88
|
/**
|
89
|
* {@inheritDoc}
|
90
|
*/
|
91
|
@Override
|
92
|
protected List<TermVocabularyDto> getVocabulariesFromPreference() {
|
93
|
// TODO Auto-generated method stub
|
94
|
return null;
|
95
|
}
|
96
|
@Override
|
97
|
protected void rememberCheckedValues(String checkedValues) {
|
98
|
initialiseVocabularies();
|
99
|
|
100
|
treeComposite.getViewer().setInput(getVocabularies());
|
101
|
|
102
|
if (checkedValues != null && checkedValues != "") { //$NON-NLS-1$
|
103
|
String[] listChecked = checkedValues.split(";"); //$NON-NLS-1$
|
104
|
String[] listCheckedComma = checkedValues.split(","); //$NON-NLS-1$
|
105
|
List<String> checked = new ArrayList<>();
|
106
|
if (listChecked != null ){
|
107
|
checked = Arrays.asList(listChecked);
|
108
|
}
|
109
|
if (listCheckedComma != null && checkedValues.contains(",")){ //$NON-NLS-1$
|
110
|
checked = Arrays.asList(listCheckedComma);
|
111
|
}
|
112
|
List<TermVocabularyDto> termsFromStringValues = getTermsFromStringValues(checked);
|
113
|
treeComposite.setCheckedElements(termsFromStringValues.toArray());
|
114
|
|
115
|
}else{
|
116
|
|
117
|
treeComposite.getViewer().setAllChecked(true);
|
118
|
}
|
119
|
}
|
120
|
|
121
|
@Override
|
122
|
protected List<TermVocabularyDto> getTermsFromStringValues(List<String> listValue) {
|
123
|
List<TermVocabularyDto> termlist = new ArrayList<>();
|
124
|
List<UUID> uuidList = new ArrayList<>();
|
125
|
for (String s : listValue) {
|
126
|
if (!StringUtils.isBlank(s)){
|
127
|
UUID uuid = UUID.fromString(s);
|
128
|
uuidList.add(uuid);
|
129
|
}
|
130
|
}
|
131
|
IVocabularyService vocabularyService = CdmStore.getService(IVocabularyService.class);
|
132
|
|
133
|
termlist = vocabularyService.findVocabularyDtoByVocabularyUuids(uuidList);
|
134
|
|
135
|
|
136
|
|
137
|
return termlist;
|
138
|
|
139
|
}
|
140
|
|
141
|
|
142
|
|
143
|
|
144
|
}
|