1
|
/**
|
2
|
* Copyright (C) 2019 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.ui.dialog;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.List;
|
14
|
import java.util.UUID;
|
15
|
|
16
|
import org.apache.commons.collections4.CollectionUtils;
|
17
|
import org.eclipse.jface.wizard.Wizard;
|
18
|
|
19
|
import eu.etaxonomy.cdm.api.service.description.DistributionAggregationConfiguration;
|
20
|
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
|
21
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
22
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
23
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
24
|
import eu.etaxonomy.taxeditor.ui.dialog.configurator.wizard.SuperAreaPage;
|
25
|
|
26
|
/**
|
27
|
* @author k.luther
|
28
|
* @since 25.11.2019
|
29
|
*/
|
30
|
public class SuperAreaSelectionWizard extends Wizard {
|
31
|
|
32
|
private final SuperAreaPage aPage;
|
33
|
DistributionAggregationConfiguration configurator;
|
34
|
|
35
|
public SuperAreaSelectionWizard(DistributionAggregationConfiguration configurator, NamedAreaLevel level) {
|
36
|
setWindowTitle(Messages.AvailableDistributionWizard_WINDOW_TITLE);
|
37
|
// TODO if preferenceStore has elements checked load elements in wizard
|
38
|
aPage = new SuperAreaPage(Messages.AvailableDistributionWizard_PAGE_TITLE, level);
|
39
|
this.configurator = configurator;
|
40
|
}
|
41
|
|
42
|
@Override
|
43
|
public boolean performFinish() {
|
44
|
// TODO: get Selection and save in EditorPreferences
|
45
|
if (!checkNoneChecked()) {
|
46
|
Object[] checkedElements = aPage.getViewer().getCheckedElements();
|
47
|
Object[] grayedElements = aPage.getViewer().getGrayedElements();
|
48
|
List<Object> checkedList = new ArrayList<>(Arrays.asList(checkedElements));
|
49
|
List<Object> grayedList = new ArrayList<>(Arrays.asList(grayedElements));
|
50
|
checkedList = (ArrayList) CollectionUtils.subtract(checkedList, grayedList);
|
51
|
ArrayList<UUID> listUIIDChecked = new ArrayList<>();
|
52
|
ArrayList<UUID> listUIIDGrayed = new ArrayList<>();
|
53
|
for (Object o : checkedList) {
|
54
|
if (o instanceof TermDto) {
|
55
|
listUIIDChecked.add(((TermDto) o).getUuid());
|
56
|
|
57
|
}else if(o instanceof TermVocabularyDto){
|
58
|
TermVocabularyDto termVocDto = (TermVocabularyDto) o;
|
59
|
listUIIDGrayed.add(termVocDto.getUuid());
|
60
|
}
|
61
|
}
|
62
|
// for (Object o : grayedList) {
|
63
|
// if (o instanceof TermDto) {
|
64
|
// listUIIDChecked.add(((TermDto) o).getUuid());
|
65
|
//
|
66
|
// }else if(o instanceof TermVocabularyDto){
|
67
|
// TermVocabularyDto termVocDto = (TermVocabularyDto) o;
|
68
|
// listUIIDGrayed.add(termVocDto.getUuid());
|
69
|
// }
|
70
|
// }
|
71
|
|
72
|
configurator.setSuperAreas(listUIIDChecked);
|
73
|
|
74
|
|
75
|
return true;
|
76
|
} else {
|
77
|
return false;
|
78
|
}
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
public void addPages() {
|
83
|
addPage(aPage);
|
84
|
}
|
85
|
|
86
|
private boolean checkNoneChecked() {
|
87
|
|
88
|
if (aPage.getViewer().getCheckedElements().length == 0) {
|
89
|
aPage.setMessage(Messages.AvailableDistributionWizard_CHECK_MESSAGE, aPage.WARNING);
|
90
|
return true;
|
91
|
} else {
|
92
|
aPage.setMessage(null);
|
93
|
return false;
|
94
|
}
|
95
|
}
|
96
|
}
|