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.Arrays;
|
12
|
import java.util.Collection;
|
13
|
import java.util.HashSet;
|
14
|
import java.util.List;
|
15
|
import java.util.Set;
|
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.jface.viewers.StyledString.Styler;
|
21
|
import org.eclipse.swt.SWT;
|
22
|
import org.eclipse.swt.graphics.TextStyle;
|
23
|
import org.eclipse.swt.layout.GridLayout;
|
24
|
import org.eclipse.swt.widgets.Composite;
|
25
|
import org.eclipse.swt.widgets.Control;
|
26
|
import org.eclipse.swt.widgets.Display;
|
27
|
import org.eclipse.swt.widgets.Shell;
|
28
|
|
29
|
import eu.etaxonomy.cdm.api.service.IVocabularyService;
|
30
|
import eu.etaxonomy.cdm.model.common.TermType;
|
31
|
import eu.etaxonomy.cdm.model.common.TermVocabulary;
|
32
|
import eu.etaxonomy.cdm.model.location.NamedArea;
|
33
|
import eu.etaxonomy.taxeditor.editor.definedterm.TermContentProvider;
|
34
|
import eu.etaxonomy.taxeditor.preference.wizard.AreaLabelProvider;
|
35
|
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite;
|
36
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
37
|
|
38
|
/**
|
39
|
* @author pplitzner
|
40
|
* @since Oct 29, 2018
|
41
|
*
|
42
|
*/
|
43
|
public class AreasSelectionDialog extends Dialog{
|
44
|
|
45
|
private CheckBoxTreeComposite treeComposite;
|
46
|
|
47
|
private Set<NamedArea> selectedAreas = new HashSet<>();
|
48
|
|
49
|
private Collection<TermVocabulary<NamedArea>> namedAreas;
|
50
|
|
51
|
|
52
|
protected AreasSelectionDialog(Shell parentShell, Set<NamedArea> selectedAreas) {
|
53
|
super(parentShell);
|
54
|
this.selectedAreas = selectedAreas;
|
55
|
this.namedAreas = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea, null);
|
56
|
}
|
57
|
|
58
|
@Override
|
59
|
protected Control createDialogArea(Composite parent) {
|
60
|
parent.setLayout(new GridLayout());
|
61
|
Styler styler = new Styler() {
|
62
|
@Override
|
63
|
public void applyStyles(TextStyle textStyle) {
|
64
|
textStyle.foreground = Display.getCurrent().getSystemColor(SWT.COLOR_BLACK);
|
65
|
}
|
66
|
};
|
67
|
treeComposite = new CheckBoxTreeComposite(parent, new TermContentProvider(), new AreaLabelProvider(styler), SWT.NONE);
|
68
|
treeComposite.getViewer().setInput(namedAreas);
|
69
|
treeComposite.setCheckedElements(selectedAreas.toArray());
|
70
|
treeComposite.getViewer().reveal(selectedAreas);
|
71
|
GridLayoutFactory.fillDefaults().applyTo(treeComposite);
|
72
|
return treeComposite;
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
protected void configureShell(Shell newShell) {
|
77
|
super.configureShell(newShell);
|
78
|
newShell.setText("Choose areas");
|
79
|
newShell.setSize(400, 600);
|
80
|
}
|
81
|
|
82
|
@Override
|
83
|
protected void okPressed() {
|
84
|
selectedAreas.clear();
|
85
|
List<Object> checkedElements = Arrays.asList(treeComposite.getViewer().getCheckedElements());
|
86
|
checkedElements = checkedElements.stream().filter(element->element instanceof NamedArea).collect(Collectors.toList());
|
87
|
selectedAreas = new HashSet(checkedElements);
|
88
|
super.okPressed();
|
89
|
}
|
90
|
|
91
|
@Override
|
92
|
protected boolean isResizable() {
|
93
|
return true;
|
94
|
}
|
95
|
|
96
|
public Set<NamedArea> getSelectedAreas(){
|
97
|
return selectedAreas;
|
98
|
}
|
99
|
}
|