Project

General

Profile

Download (3.14 KB) Statistics
| Branch: | Tag: | Revision:
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.Collections;
14
import java.util.HashSet;
15
import java.util.List;
16
import java.util.Set;
17
import java.util.stream.Collectors;
18

    
19
import org.eclipse.jface.dialogs.Dialog;
20
import org.eclipse.jface.layout.GridLayoutFactory;
21
import org.eclipse.swt.SWT;
22
import org.eclipse.swt.layout.GridLayout;
23
import org.eclipse.swt.widgets.Composite;
24
import org.eclipse.swt.widgets.Control;
25
import org.eclipse.swt.widgets.Shell;
26

    
27
import eu.etaxonomy.cdm.api.service.IVocabularyService;
28
import eu.etaxonomy.cdm.model.common.TermType;
29
import eu.etaxonomy.cdm.model.common.TermVocabulary;
30
import eu.etaxonomy.cdm.model.location.NamedArea;
31
import eu.etaxonomy.cdm.persistence.dto.TermDto;
32
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider;
33
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider;
34
import eu.etaxonomy.taxeditor.preference.wizard.CheckBoxTreeComposite;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
36

    
37
/**
38
 * @author pplitzner
39
 * @since Oct 29, 2018
40
 *
41
 */
42
public class AreasSelectionDialog extends Dialog{
43

    
44
    private CheckBoxTreeComposite treeComposite;
45

    
46
    private Set<TermDto> selectedAreas = new HashSet<>();
47

    
48
    private Collection<TermVocabulary<NamedArea>> areaVocabularies;
49

    
50

    
51
    protected AreasSelectionDialog(Shell parentShell, Set<TermDto> selectedAreas) {
52
        super(parentShell);
53
        this.selectedAreas = selectedAreas;
54
        this.areaVocabularies = CdmStore.getService(IVocabularyService.class).findByTermType(TermType.NamedArea, null);
55
    }
56

    
57
    @Override
58
    protected Control createDialogArea(Composite parent) {
59
        parent.setLayout(new GridLayout());
60
        treeComposite = new CheckBoxTreeComposite(parent, new TermDtoContentProvider(), new TermDtoLabelProvider(), SWT.NONE);
61
        treeComposite.getViewer().setInput(areaVocabularies);
62
        treeComposite.setCheckedElements(selectedAreas.toArray());
63
        GridLayoutFactory.fillDefaults().applyTo(treeComposite);
64
        return treeComposite;
65
    }
66

    
67
    @Override
68
    protected void configureShell(Shell newShell) {
69
        super.configureShell(newShell);
70
        newShell.setText("Choose areas");
71
        newShell.setSize(400, 600);
72
    }
73

    
74
    @Override
75
    protected void okPressed() {
76
        selectedAreas.clear();
77
        List<Object> checkedElements = Arrays.asList(treeComposite.getViewer().getCheckedElements());
78
        checkedElements = checkedElements.stream().filter(element->element instanceof TermDto).collect(Collectors.toList());
79
        Collections.sort(checkedElements, (o1, o2)->((TermDto)o1).getOrderIndex()-((TermDto)o2).getOrderIndex());
80
        selectedAreas = new HashSet(checkedElements);
81
        super.okPressed();
82
    }
83

    
84
    @Override
85
    protected boolean isResizable() {
86
        return true;
87
    }
88

    
89
    public Set<TermDto> getSelectedAreas(){
90
        return selectedAreas;
91
    }
92
}
(1-1/5)