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.UUID;
|
14
|
|
15
|
import org.apache.commons.collections4.CollectionUtils;
|
16
|
import org.apache.commons.lang3.StringUtils;
|
17
|
import org.eclipse.jface.wizard.Wizard;
|
18
|
|
19
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
20
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
21
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
22
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
23
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
24
|
|
25
|
/**
|
26
|
* @author alex
|
27
|
* @date 21.07.2014
|
28
|
*/
|
29
|
public class AvailableDistributionWizard extends Wizard {
|
30
|
|
31
|
private final AvailableDistributionPage aPage;
|
32
|
|
33
|
public AvailableDistributionWizard() {
|
34
|
setWindowTitle(Messages.AvailableDistributionWizard_WINDOW_TITLE);
|
35
|
// TODO if preferenceStore has elements checked load elements in wizard
|
36
|
aPage = new AvailableDistributionPage(Messages.AvailableDistributionWizard_PAGE_TITLE);
|
37
|
}
|
38
|
|
39
|
@Override
|
40
|
public boolean performFinish() {
|
41
|
// TODO: get Selection and save in EditorPreferences
|
42
|
if (!checkNoneChecked()) {
|
43
|
Object[] checkedElements = aPage.getViewer().getCheckedElements();
|
44
|
Object[] grayedElements = aPage.getViewer().getGrayedElements();
|
45
|
ArrayList<Object> checkedList = new ArrayList<>(Arrays.asList(checkedElements));
|
46
|
ArrayList<Object> grayedList = new ArrayList<>(Arrays.asList(grayedElements));
|
47
|
checkedList = (ArrayList) CollectionUtils.subtract(checkedList, grayedList);
|
48
|
ArrayList<UUID> listUIIDChecked = new ArrayList<>();
|
49
|
ArrayList<UUID> listUIIDGrayed = new ArrayList<>();
|
50
|
for (Object o : checkedList) {
|
51
|
if (o instanceof TermDto) {
|
52
|
listUIIDChecked.add(((TermDto) o).getUuid());
|
53
|
|
54
|
}else if(o instanceof TermVocabularyDto){
|
55
|
TermVocabularyDto termVocDto = (TermVocabularyDto) o;
|
56
|
listUIIDGrayed.add(termVocDto.getUuid());
|
57
|
}
|
58
|
}
|
59
|
for (Object o : grayedList) {
|
60
|
if (o instanceof TermDto) {
|
61
|
listUIIDChecked.add(((TermDto) o).getUuid());
|
62
|
|
63
|
}else if(o instanceof TermVocabularyDto){
|
64
|
TermVocabularyDto termVocDto = (TermVocabularyDto) o;
|
65
|
listUIIDGrayed.add(termVocDto.getUuid());
|
66
|
}
|
67
|
}
|
68
|
|
69
|
String saveCheckedElements = StringUtils.join(listUIIDChecked, ";"); //$NON-NLS-1$
|
70
|
|
71
|
PreferencesUtil.setStringValue(PreferencePredicate.AvailableDistributionAreaTerms.getKey(), saveCheckedElements);
|
72
|
return true;
|
73
|
} else {
|
74
|
return false;
|
75
|
}
|
76
|
}
|
77
|
|
78
|
@Override
|
79
|
public void addPages() {
|
80
|
addPage(aPage);
|
81
|
}
|
82
|
|
83
|
private boolean checkNoneChecked() {
|
84
|
if (aPage.getViewer().getCheckedElements().length == 0) {
|
85
|
aPage.setMessage(Messages.AvailableDistributionWizard_CHECK_MESSAGE, aPage.WARNING);
|
86
|
return true;
|
87
|
} else {
|
88
|
aPage.setMessage(null);
|
89
|
return false;
|
90
|
}
|
91
|
}
|
92
|
}
|