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