1
|
/**
|
2
|
* Copyright (C) 2014 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.HashMap;
|
14
|
import java.util.HashSet;
|
15
|
import java.util.List;
|
16
|
import java.util.Map;
|
17
|
import java.util.Set;
|
18
|
import java.util.UUID;
|
19
|
|
20
|
import org.apache.commons.lang.StringUtils;
|
21
|
import org.eclipse.swt.widgets.Composite;
|
22
|
|
23
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
24
|
import eu.etaxonomy.cdm.model.common.TermType;
|
25
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
26
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
27
|
import eu.etaxonomy.cdm.persistence.dto.AbstractTermDto;
|
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.store.CdmStore;
|
32
|
|
33
|
/**
|
34
|
* @author a.oppermann
|
35
|
* @date 21.07.2014
|
36
|
*
|
37
|
*/
|
38
|
public class AvailableDistributionPage extends AbstractTermSelectionWizardPage {
|
39
|
|
40
|
protected AvailableDistributionPage(String pageName) {
|
41
|
super(pageName, TermType.NamedArea);
|
42
|
this.localPref = true;
|
43
|
|
44
|
|
45
|
}
|
46
|
|
47
|
@Override
|
48
|
public void createControl(Composite parent) {
|
49
|
setTitle(Messages.AvailableDistributionPage_PAGE_TITLE);
|
50
|
setDescription(Messages.AvailableDistributionPage_PAGE_DESCRIPTION);
|
51
|
|
52
|
super.createControl(parent);
|
53
|
}
|
54
|
|
55
|
@Override
|
56
|
protected String getCheckedValuesFromPreferences() {
|
57
|
String checkedValues = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey());
|
58
|
|
59
|
return checkedValues;
|
60
|
}
|
61
|
|
62
|
@Override
|
63
|
protected void rememberCheckedValues(String checkedValues) {
|
64
|
initialiseVocabularies();
|
65
|
|
66
|
treeComposite.getViewer().setInput(getVocabularies());
|
67
|
|
68
|
if (checkedValues != null && checkedValues != "") { //$NON-NLS-1$
|
69
|
String[] listChecked = checkedValues.split(";"); //$NON-NLS-1$
|
70
|
String[] listCheckedComma = checkedValues.split(","); //$NON-NLS-1$
|
71
|
List<String> checked = new ArrayList<>();
|
72
|
if (listChecked != null ){
|
73
|
checked = Arrays.asList(listChecked);
|
74
|
}
|
75
|
if (listCheckedComma != null && checkedValues.contains(",")){ //$NON-NLS-1$
|
76
|
checked = Arrays.asList(listCheckedComma);
|
77
|
}
|
78
|
List<AbstractTermDto> termsFromStringValues = getTermsFromStringValues(checked);
|
79
|
treeComposite.setCheckedElements(termsFromStringValues.toArray());
|
80
|
}
|
81
|
|
82
|
}
|
83
|
|
84
|
@Override
|
85
|
public void dispose() {
|
86
|
// CdmStore.getCurrentSessionManager().dispose(this);
|
87
|
super.dispose();
|
88
|
}
|
89
|
|
90
|
// @Override
|
91
|
// public ICdmEntitySession getCdmEntitySession() {
|
92
|
// return CdmStore.getCurrentSessionManager().getNullSession();
|
93
|
// }
|
94
|
//
|
95
|
// @Override
|
96
|
// public <T extends CdmBase> Collection<T> getRootEntities() {
|
97
|
// return null;
|
98
|
// }
|
99
|
//
|
100
|
// @Override
|
101
|
public Map<Object, List<String>> getPropertyPathsMap() {
|
102
|
Map<Object, List<String>> propertyPathsMap = new HashMap<Object, List<String>>();
|
103
|
List<String> termsPropertyPaths = Arrays.asList(new String[] {
|
104
|
"includes" //$NON-NLS-1$
|
105
|
});
|
106
|
propertyPathsMap.put("includes", termsPropertyPaths); //$NON-NLS-1$
|
107
|
propertyPathsMap.put("terms", termsPropertyPaths); //$NON-NLS-1$
|
108
|
return propertyPathsMap;
|
109
|
}
|
110
|
|
111
|
@Override
|
112
|
protected List<TermVocabularyDto> getVocabulariesFromPreference(){
|
113
|
List<TermVocabularyDto> vocs = new ArrayList<>();
|
114
|
|
115
|
if (PreferencesUtil.getPreferenceFromDB(PreferencePredicate.AvailableDistributionAreaVocabularies) == null && PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey()) == null){
|
116
|
vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
|
117
|
}else{
|
118
|
String vocString = PreferencesUtil.getStringValue(PreferencePredicate.AvailableDistributionAreaVocabularies.getKey());
|
119
|
if (vocString.equals("")){
|
120
|
vocs = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(type);
|
121
|
return vocs;
|
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
|
@Override
|
140
|
protected void initialiseVocabularies() {
|
141
|
if (getVocabularies() != null) {
|
142
|
getVocabularies().clear();
|
143
|
}
|
144
|
List<TermVocabularyDto> vocs = new ArrayList<>();
|
145
|
vocs = getVocabulariesFromPreference();
|
146
|
|
147
|
setVocabularies(vocs);
|
148
|
}
|
149
|
|
150
|
}
|