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.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
16
|
import java.util.UUID;
|
17
|
|
18
|
import org.apache.commons.lang.StringUtils;
|
19
|
import org.eclipse.jface.viewers.ColumnViewer;
|
20
|
import org.eclipse.jface.wizard.WizardPage;
|
21
|
import org.eclipse.swt.widgets.Composite;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.service.ITermService;
|
24
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
25
|
import eu.etaxonomy.cdm.model.common.DefinedTermBase;
|
26
|
import eu.etaxonomy.cdm.model.common.TermBase;
|
27
|
import eu.etaxonomy.cdm.model.common.TermType;
|
28
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
29
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
30
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
31
|
|
32
|
/**
|
33
|
* @author k.luther
|
34
|
* @since 04.06.2018
|
35
|
*
|
36
|
*/
|
37
|
public abstract class AbstractTermSelectionWizardPage extends WizardPage {
|
38
|
|
39
|
private ColumnViewer viewer;
|
40
|
private List<TermVocabulary<DefinedTermBase>> vocabularies = new ArrayList<>();
|
41
|
boolean localPref;
|
42
|
List<TermBase> listCheckedTerms = new ArrayList<>();
|
43
|
List<TermBase> listGrayedTerms = new ArrayList<>();
|
44
|
|
45
|
TermType type;
|
46
|
|
47
|
/**
|
48
|
* @param pageName
|
49
|
*/
|
50
|
protected AbstractTermSelectionWizardPage(String pageName, TermType type) {
|
51
|
super(pageName);
|
52
|
// TODO check if configuration exists
|
53
|
CdmStore.getCurrentSessionManager().bindNullSession();
|
54
|
this.type = type;
|
55
|
}
|
56
|
|
57
|
/**
|
58
|
* {@inheritDoc}
|
59
|
*/
|
60
|
@Override
|
61
|
public abstract void createControl(Composite parent) ;
|
62
|
|
63
|
public ColumnViewer getViewer() {
|
64
|
return viewer;
|
65
|
}
|
66
|
|
67
|
public void setViewer(ColumnViewer viewer) {
|
68
|
this.viewer = viewer;
|
69
|
}
|
70
|
|
71
|
public List<TermVocabulary<DefinedTermBase>> getVocabularies() {
|
72
|
return vocabularies;
|
73
|
}
|
74
|
|
75
|
public void addVocabularies(TermVocabulary<DefinedTermBase> vocabulary) {
|
76
|
this.vocabularies.add(vocabulary);
|
77
|
}
|
78
|
|
79
|
|
80
|
/**
|
81
|
* @param vocs
|
82
|
*/
|
83
|
protected void setVocabularies(List<TermVocabulary<DefinedTermBase>> vocs) {
|
84
|
for (TermVocabulary voc:vocs){
|
85
|
vocabularies.add(voc);
|
86
|
}
|
87
|
}
|
88
|
|
89
|
public List<TermBase> getListCheckedTerms() {
|
90
|
return listCheckedTerms;
|
91
|
}
|
92
|
|
93
|
public List<TermBase> getListGrayedTerms() {
|
94
|
return listGrayedTerms;
|
95
|
}
|
96
|
|
97
|
protected void rememberCheckedValues(String checkedValues, String grayedValues) {
|
98
|
initialiseVocabularies();
|
99
|
getViewer().setInput(getVocabularies());
|
100
|
|
101
|
if (grayedValues != null && grayedValues != "") {
|
102
|
String[] arrayGrayed = grayedValues.split(";");
|
103
|
List<String> listGrayed = Arrays.asList(arrayGrayed);
|
104
|
if (listGrayedTerms == null){
|
105
|
listGrayedTerms = new ArrayList();
|
106
|
}
|
107
|
getTermsFromStringValues(listGrayed, this.listGrayedTerms);
|
108
|
|
109
|
}
|
110
|
if (checkedValues != null && checkedValues != "") {
|
111
|
String[] listChecked = checkedValues.split(";");
|
112
|
String[] listCheckedComma = checkedValues.split(",");
|
113
|
List<String> checked = new ArrayList<>();
|
114
|
if (listChecked != null ){
|
115
|
checked = Arrays.asList(listChecked);
|
116
|
}
|
117
|
if (listCheckedComma != null && checkedValues.contains(",")){
|
118
|
checked = Arrays.asList(listCheckedComma);
|
119
|
}
|
120
|
if (listCheckedTerms == null){
|
121
|
listCheckedTerms = new ArrayList();
|
122
|
}
|
123
|
getTermsFromStringValues(checked, listCheckedTerms);
|
124
|
|
125
|
}
|
126
|
}
|
127
|
|
128
|
/**
|
129
|
* @param split
|
130
|
* @param termlist
|
131
|
*/
|
132
|
private void getTermsFromStringValues(List<String> listValue, List<TermBase> termlist) {
|
133
|
|
134
|
for (String s : listValue) {
|
135
|
if (!StringUtils.isBlank(s)){
|
136
|
UUID uuid = UUID.fromString(s);
|
137
|
ITermService termService = CdmStore.getService(ITermService.class);
|
138
|
DefinedTermBase definedTermBase = termService.load(uuid);
|
139
|
if(definedTermBase != null){
|
140
|
termlist.add(definedTermBase);
|
141
|
}else{
|
142
|
IVocabularyService vocabularyService = CdmStore.getService(IVocabularyService.class);
|
143
|
TermVocabulary termVocabulary = vocabularyService.load(uuid);
|
144
|
termlist.add(termVocabulary);
|
145
|
}
|
146
|
}
|
147
|
}
|
148
|
}
|
149
|
|
150
|
|
151
|
protected void initialiseVocabularies() {
|
152
|
if (getVocabularies() != null) {
|
153
|
getVocabularies().clear();
|
154
|
}
|
155
|
List<TermVocabulary<DefinedTermBase>> vocs = new ArrayList<>();
|
156
|
if (localPref){
|
157
|
String vocString = PreferencesUtil.getPreferenceStore().getString(PreferencesUtil.DISTRIBUTION_VOCABULARIES);
|
158
|
String[] arrayVocs = vocString.split(";");
|
159
|
|
160
|
Set<UUID> uuidVocs = new HashSet();
|
161
|
for (String voc: arrayVocs){
|
162
|
if (!StringUtils.isBlank(voc)){
|
163
|
uuidVocs.add(UUID.fromString(voc));
|
164
|
}
|
165
|
}
|
166
|
List<TermVocabulary> tempVocs = CdmStore.getService(IVocabularyService.class).find(uuidVocs);
|
167
|
for (TermVocabulary voc: tempVocs){
|
168
|
vocs.add(voc);
|
169
|
}
|
170
|
|
171
|
}else{
|
172
|
vocs = CdmStore.getService(IVocabularyService.class).findByTermType(
|
173
|
type, null);
|
174
|
}
|
175
|
setVocabularies(vocs);
|
176
|
}
|
177
|
|
178
|
|
179
|
}
|