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.editor.descriptiveDataSet;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Arrays;
|
13
|
import java.util.Collection;
|
14
|
import java.util.Collections;
|
15
|
import java.util.List;
|
16
|
import java.util.stream.Collectors;
|
17
|
|
18
|
import org.eclipse.jface.dialogs.Dialog;
|
19
|
import org.eclipse.jface.layout.GridLayoutFactory;
|
20
|
import org.eclipse.swt.SWT;
|
21
|
import org.eclipse.swt.layout.GridLayout;
|
22
|
import org.eclipse.swt.widgets.Composite;
|
23
|
import org.eclipse.swt.widgets.Control;
|
24
|
import org.eclipse.swt.widgets.Shell;
|
25
|
|
26
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
27
|
import eu.etaxonomy.cdm.model.common.TermType;
|
28
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
29
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
30
|
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermSorter;
|
31
|
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider;
|
32
|
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider;
|
33
|
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite;
|
34
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
35
|
|
36
|
/**
|
37
|
* @author pplitzner
|
38
|
* @since Oct 29, 2018
|
39
|
*
|
40
|
*/
|
41
|
public class AreasSelectionDialog extends Dialog{
|
42
|
|
43
|
private CheckBoxTreeComposite treeComposite;
|
44
|
|
45
|
private List<TermDto> selectedAreas;
|
46
|
|
47
|
private Collection<TermVocabularyDto> areaVocabularies;
|
48
|
|
49
|
|
50
|
protected AreasSelectionDialog(Shell parentShell, List<TermDto> selectedAreas) {
|
51
|
super(parentShell);
|
52
|
this.selectedAreas = selectedAreas;
|
53
|
this.areaVocabularies = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(TermType.NamedArea);
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
protected Control createDialogArea(Composite parent) {
|
58
|
parent.setLayout(new GridLayout());
|
59
|
treeComposite = new CheckBoxTreeComposite(parent, new TermDtoContentProvider(), new TermDtoLabelProvider(), SWT.NONE);
|
60
|
treeComposite.getViewer().setComparator(new DefinedTermSorter());
|
61
|
treeComposite.getViewer().setInput(areaVocabularies);
|
62
|
Collections.sort(selectedAreas, (o1, o2)->o1.getOrderIndex()-o2.getOrderIndex());
|
63
|
treeComposite.setCheckedElements(selectedAreas.toArray());
|
64
|
GridLayoutFactory.fillDefaults().applyTo(treeComposite);
|
65
|
return treeComposite;
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
protected void configureShell(Shell newShell) {
|
70
|
super.configureShell(newShell);
|
71
|
newShell.setText("Choose areas");
|
72
|
newShell.setSize(400, 600);
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
protected void okPressed() {
|
77
|
selectedAreas.clear();
|
78
|
List<Object> checkedElements = Arrays.asList(treeComposite.getViewer().getCheckedElements());
|
79
|
checkedElements = checkedElements.stream().filter(element->element instanceof TermDto).collect(Collectors.toList());
|
80
|
selectedAreas = new ArrayList(checkedElements);
|
81
|
super.okPressed();
|
82
|
}
|
83
|
|
84
|
@Override
|
85
|
protected boolean isResizable() {
|
86
|
return true;
|
87
|
}
|
88
|
|
89
|
public List<TermDto> getSelectedAreas(){
|
90
|
return selectedAreas;
|
91
|
}
|
92
|
}
|