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 AbstractAreaSelectionWizard extends WizardPage {
|
38
|
|
39
|
private ColumnViewer viewer;
|
40
|
private List<TermVocabulary<DefinedTermBase>> vocabularies = new ArrayList<>();
|
41
|
boolean localPref;
|
42
|
List<TermBase> listCheckedTerms;
|
43
|
List<TermBase> listGrayedTerms;
|
44
|
|
45
|
/**
|
46
|
* @param pageName
|
47
|
*/
|
48
|
protected AbstractAreaSelectionWizard(String pageName) {
|
49
|
super(pageName);
|
50
|
// TODO check if configuration exists
|
51
|
CdmStore.getCurrentSessionManager().bindNullSession();
|
52
|
}
|
53
|
|
54
|
/**
|
55
|
* {@inheritDoc}
|
56
|
*/
|
57
|
@Override
|
58
|
public abstract void createControl(Composite parent) ;
|
59
|
|
60
|
public ColumnViewer getViewer() {
|
61
|
return viewer;
|
62
|
}
|
63
|
|
64
|
public void setViewer(ColumnViewer viewer) {
|
65
|
this.viewer = viewer;
|
66
|
}
|
67
|
|
68
|
public List<TermVocabulary<DefinedTermBase>> getVocabularies() {
|
69
|
return vocabularies;
|
70
|
}
|
71
|
|
72
|
public void addVocabularies(TermVocabulary<DefinedTermBase> vocabulary) {
|
73
|
this.vocabularies.add(vocabulary);
|
74
|
}
|
75
|
|
76
|
|
77
|
/**
|
78
|
* @param vocs
|
79
|
*/
|
80
|
protected void setVocabularies(List<TermVocabulary<DefinedTermBase>> vocs) {
|
81
|
for (TermVocabulary voc:vocs){
|
82
|
vocabularies.add(voc);
|
83
|
}
|
84
|
}
|
85
|
|
86
|
public List<TermBase> getListCheckedTerms() {
|
87
|
return listCheckedTerms;
|
88
|
}
|
89
|
|
90
|
public List<TermBase> getListGrayedTerms() {
|
91
|
return listGrayedTerms;
|
92
|
}
|
93
|
|
94
|
protected void rememberCheckedValues(String checkedValues, String grayedValues) {
|
95
|
initialiseVocabularies();
|
96
|
getViewer().setInput(getVocabularies());
|
97
|
|
98
|
if (grayedValues != null && grayedValues != "") {
|
99
|
String[] arrayGrayed = grayedValues.split(";");
|
100
|
List<String> listGrayed = Arrays.asList(arrayGrayed);
|
101
|
if (listGrayedTerms == null){
|
102
|
listGrayedTerms = new ArrayList();
|
103
|
}
|
104
|
getTermsFromStringValues(listGrayed, this.listGrayedTerms);
|
105
|
NamedAreaWrapper wrapper;
|
106
|
// for(TermBase element : listGrayedTerms){
|
107
|
// if(element != null){
|
108
|
// if (element instanceof DefinedTermBase){
|
109
|
// wrapper = new NamedAreaWrapper((DefinedTermBase)element, true, null);
|
110
|
// if (getViewer() instanceof CheckboxTreeViewer) {
|
111
|
// ((CheckboxTreeViewer)getViewer()).setGrayChecked(wrapper, true);
|
112
|
// }
|
113
|
// }else{
|
114
|
// if (getViewer() instanceof CheckboxTreeViewer) {
|
115
|
// ((CheckboxTreeViewer)getViewer()).setGrayChecked(element, true);
|
116
|
// }
|
117
|
// }
|
118
|
// }
|
119
|
//
|
120
|
// }
|
121
|
}
|
122
|
if (checkedValues != null && checkedValues != "") {
|
123
|
String[] listChecked = checkedValues.split(";");
|
124
|
String[] listCheckedComma = checkedValues.split(",");
|
125
|
List<String> checked = new ArrayList<>();
|
126
|
if (listChecked != null ){
|
127
|
checked = Arrays.asList(listChecked);
|
128
|
}
|
129
|
if (listCheckedComma != null && checkedValues.contains(",")){
|
130
|
checked = Arrays.asList(listCheckedComma);
|
131
|
}
|
132
|
if (listCheckedTerms == null){
|
133
|
listCheckedTerms = new ArrayList();
|
134
|
}
|
135
|
getTermsFromStringValues(checked, listCheckedTerms);
|
136
|
|
137
|
// Object[] elements = ((CheckboxTreeViewer)getViewer()).getExpandedElements();
|
138
|
// for (Object element: elements){
|
139
|
// if (element instanceof NamedAreaWrapper){
|
140
|
// if (listCheckedTerms.contains(((NamedAreaWrapper)element).getNamedArea())){
|
141
|
// ((CheckboxTreeViewer)getViewer()).setChecked(element, true);
|
142
|
// }
|
143
|
// if (listGrayedTerms.contains(((NamedAreaWrapper)element).getNamedArea())){
|
144
|
// ((CheckboxTreeViewer)getViewer()).setGrayChecked(element, true);
|
145
|
// }
|
146
|
// }
|
147
|
// }
|
148
|
NamedAreaWrapper wrapper;
|
149
|
// for(Object element : listCheckedTerms){
|
150
|
// if(element != null){
|
151
|
// if (element instanceof DefinedTermBase){
|
152
|
// wrapper = new NamedAreaWrapper((DefinedTermBase)element, true, null);
|
153
|
// if (getViewer() instanceof CheckboxTreeViewer) {
|
154
|
// ((CheckboxTreeViewer)getViewer()).setChecked(wrapper, true);
|
155
|
// }
|
156
|
// }else{
|
157
|
// if (getViewer() instanceof CheckboxTreeViewer) {
|
158
|
// ((CheckboxTreeViewer)getViewer()).setChecked(element, true);
|
159
|
// }
|
160
|
// }
|
161
|
// }
|
162
|
// }
|
163
|
}
|
164
|
}
|
165
|
|
166
|
/**
|
167
|
* @param split
|
168
|
* @param termlist
|
169
|
*/
|
170
|
private void getTermsFromStringValues(List<String> listValue, List<TermBase> termlist) {
|
171
|
|
172
|
for (String s : listValue) {
|
173
|
if (!StringUtils.isBlank(s)){
|
174
|
UUID uuid = UUID.fromString(s);
|
175
|
ITermService termService = CdmStore.getService(ITermService.class);
|
176
|
DefinedTermBase definedTermBase = termService.load(uuid);
|
177
|
if(definedTermBase != null){
|
178
|
termlist.add(definedTermBase);
|
179
|
}else{
|
180
|
IVocabularyService vocabularyService = CdmStore.getService(IVocabularyService.class);
|
181
|
TermVocabulary termVocabulary = vocabularyService.load(uuid);
|
182
|
termlist.add(termVocabulary);
|
183
|
}
|
184
|
}
|
185
|
}
|
186
|
}
|
187
|
|
188
|
|
189
|
protected void initialiseVocabularies() {
|
190
|
if (getVocabularies() != null) {
|
191
|
getVocabularies().clear();
|
192
|
}
|
193
|
List<TermVocabulary<DefinedTermBase>> vocs = new ArrayList<>();
|
194
|
if (localPref){
|
195
|
String vocString = PreferencesUtil.getPreferenceStore().getString(PreferencesUtil.DISTRIBUTION_VOCABULARIES);
|
196
|
String[] arrayVocs = vocString.split(";");
|
197
|
|
198
|
Set<UUID> uuidVocs = new HashSet();
|
199
|
for (String voc: arrayVocs){
|
200
|
if (!StringUtils.isBlank(voc)){
|
201
|
uuidVocs.add(UUID.fromString(voc));
|
202
|
}
|
203
|
}
|
204
|
List<TermVocabulary> tempVocs = CdmStore.getService(IVocabularyService.class).find(uuidVocs);
|
205
|
for (TermVocabulary voc: tempVocs){
|
206
|
vocs.add(voc);
|
207
|
}
|
208
|
|
209
|
}else{
|
210
|
vocs = CdmStore.getService(IVocabularyService.class).findByTermType(
|
211
|
TermType.NamedArea, null);
|
212
|
}
|
213
|
setVocabularies(vocs);
|
214
|
}
|
215
|
|
216
|
|
217
|
}
|