2 * Copyright (C) 2018 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.editor
.descriptiveDataSet
;
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
;
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
.widgets
.Composite
;
22 import org
.eclipse
.swt
.widgets
.Control
;
23 import org
.eclipse
.swt
.widgets
.Shell
;
25 import eu
.etaxonomy
.cdm
.api
.service
.IVocabularyService
;
26 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
27 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermDto
;
28 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermVocabularyDto
;
29 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.DefinedTermSorter
;
30 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.TermDtoContentProvider
;
31 import eu
.etaxonomy
.taxeditor
.editor
.definedterm
.TermDtoLabelProvider
;
32 import eu
.etaxonomy
.taxeditor
.preference
.wizard
.CheckBoxTreeComposite
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
40 public class AreasSelectionDialog
extends Dialog
{
42 private CheckBoxTreeComposite treeComposite
;
44 private List
<TermDto
> selectedAreas
;
46 private Collection
<TermVocabularyDto
> areaVocabularies
;
49 protected AreasSelectionDialog(Shell parentShell
, List
<TermDto
> selectedAreas
) {
51 this.selectedAreas
= selectedAreas
;
52 this.areaVocabularies
= CdmStore
.getService(IVocabularyService
.class).findVocabularyDtoByTermType(TermType
.NamedArea
);
56 protected Control
createDialogArea(Composite parent
) {
57 treeComposite
= new CheckBoxTreeComposite(parent
, new TermDtoContentProvider(), new TermDtoLabelProvider(), SWT
.NONE
);
58 treeComposite
.getViewer().setComparator(new DefinedTermSorter());
59 treeComposite
.getViewer().setInput(areaVocabularies
);
60 Collections
.sort(selectedAreas
, (o1
, o2
)->o1
.getOrderIndex()-o2
.getOrderIndex());
61 treeComposite
.setCheckedElements(selectedAreas
.toArray());
62 GridLayoutFactory
.fillDefaults().applyTo(treeComposite
);
67 protected void configureShell(Shell newShell
) {
68 super.configureShell(newShell
);
69 newShell
.setText("Choose areas");
70 newShell
.setSize(400, 600);
74 protected void okPressed() {
75 selectedAreas
.clear();
76 List
<Object
> checkedElements
= Arrays
.asList(treeComposite
.getViewer().getCheckedElements());
77 checkedElements
= checkedElements
.stream()
78 .filter(element
->element
instanceof TermDto
&& !treeComposite
.getViewer().getGrayed(element
))
79 .collect(Collectors
.toList());
80 selectedAreas
= new ArrayList(checkedElements
);
85 protected boolean isResizable() {
89 public List
<TermDto
> getSelectedAreas(){