Project

General

Profile

Download (3.19 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.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.swt.SWT;
20
import org.eclipse.swt.layout.GridData;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.Control;
23
import org.eclipse.swt.widgets.Shell;
24

    
25
import eu.etaxonomy.cdm.api.service.IVocabularyService;
26
import eu.etaxonomy.cdm.model.term.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;
34

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

    
42
    private CheckBoxTreeComposite treeComposite;
43

    
44
    private List<TermDto> selectedAreas;
45

    
46
    private Collection<TermVocabularyDto> areaVocabularies;
47

    
48

    
49
    protected AreasSelectionDialog(Shell parentShell, List<TermDto> selectedAreas) {
50
        super(parentShell);
51
        this.selectedAreas = selectedAreas;
52
        this.areaVocabularies = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermType(TermType.NamedArea);
53
    }
54

    
55
    @Override
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
        treeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
63
        return treeComposite;
64
    }
65

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

    
73
    @Override
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);
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
}
(1-1/5)