Project

General

Profile

Download (2.65 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2019 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.preference.wizard;
10

    
11
import java.util.ArrayList;
12
import java.util.Collection;
13
import java.util.List;
14
import java.util.UUID;
15

    
16
import org.eclipse.swt.SWT;
17
import org.eclipse.swt.layout.GridData;
18
import org.eclipse.swt.layout.GridLayout;
19
import org.eclipse.swt.widgets.Composite;
20

    
21
import eu.etaxonomy.cdm.api.service.IVocabularyService;
22
import eu.etaxonomy.cdm.model.location.NamedAreaLevel;
23
import eu.etaxonomy.cdm.persistence.dto.TermDto;
24
import eu.etaxonomy.taxeditor.editor.definedterm.DefinedTermSorter;
25
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoContentProvider;
26
import eu.etaxonomy.taxeditor.editor.definedterm.TermDtoLabelProvider;
27
import eu.etaxonomy.taxeditor.store.CdmStore;
28

    
29
/**
30
 * @author k.luther
31
 * @since 28.11.2019
32
 */
33
public class SuperAreaPage extends AvailableDistributionPage {
34

    
35
    private NamedAreaLevel level;
36
    /**
37
     * @param pageName
38
     * @param level
39
     */
40
    public SuperAreaPage(String pageName, NamedAreaLevel level) {
41
        super(pageName);
42
        this.level = level;
43
    }
44

    
45
    @Override
46
    public void createControl(Composite parent) {
47
        setTitle("Select super areas");
48
        setDescription("Select areas to which the sub areas should be aggregated");
49

    
50
        parent.setLayout(new GridLayout());
51
        treeComposite = new CheckBoxTreeComposite(parent, new TermDtoContentProvider(), new TermDtoLabelProvider(), SWT.NONE);
52
        treeComposite.getViewer().setComparator(new DefinedTermSorter());
53

    
54
        treeComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));
55
        setControl(treeComposite);
56
        setLevelChecked();
57

    
58
    }
59

    
60
    /**
61
     *
62
     */
63
    private void setLevelChecked() {
64
        initialiseVocabularies();
65
        List<TermDto> areasWithLevel= new ArrayList();
66
        List<UUID> uuidList = new ArrayList<>();
67
        getVocabularies().stream().forEach(p -> uuidList.add(p.getUuid()));
68
        Collection<TermDto> terms = CdmStore.getService(IVocabularyService.class).getTerms(uuidList);
69
        for (TermDto term: terms) {
70
            if (term.getLevel() != null && term.getLevel().equals(level)){
71
                areasWithLevel.add(term);
72
            }
73
        }
74

    
75
        treeComposite.getViewer().setInput(getVocabularies());
76

    
77
        treeComposite.setCheckedElements(areasWithLevel.toArray());
78
    }
79

    
80
    @Override
81
    protected String getCheckedValuesFromPreferences() {
82

    
83
        return null;
84
    }
85

    
86
}
(16-16/19)