Project

General

Profile

Download (2.67 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.view.webimport.termimport;
10

    
11
import java.util.ArrayList;
12
import java.util.Arrays;
13
import java.util.Collection;
14

    
15
import org.eclipse.jface.dialogs.Dialog;
16
import org.eclipse.jface.viewers.ArrayContentProvider;
17
import org.eclipse.jface.viewers.CheckboxTableViewer;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.widgets.Composite;
20
import org.eclipse.swt.widgets.Control;
21
import org.eclipse.swt.widgets.Shell;
22
import org.eclipse.swt.widgets.Table;
23

    
24
import eu.etaxonomy.taxeditor.view.webimport.termimport.wrapper.TerminologyWrapper;
25

    
26
/**
27
 * Dialog to choose specimens for the character matrix.<br>
28
 * Filters specimens that have already been added.
29
 * @author pplitzner
30
 * @since Jan 3, 2018
31
 *
32
 */
33
public class OntologySelectionDialog extends Dialog {
34

    
35
    private CheckboxTableViewer list;
36

    
37
    private Collection<TerminologyWrapper> selectedOntologies = new ArrayList<>();
38

    
39
    private Collection<TerminologyWrapper> initiallySelectedOntologies;
40

    
41
    private Collection<TerminologyWrapper> availableOntologies;
42

    
43

    
44
    protected OntologySelectionDialog(Shell parentShell, Collection<TerminologyWrapper> initiallySelectedOntologies, Collection<TerminologyWrapper> availableOntologies) {
45
        super(parentShell);
46
        this.initiallySelectedOntologies = initiallySelectedOntologies;
47
        this.availableOntologies = availableOntologies;
48
    }
49

    
50
    @Override
51
    protected Control createDialogArea(Composite parent) {
52
        Table table = new Table(parent, SWT.CHECK | SWT.MULTI);
53
        list = new CheckboxTableViewer(table);
54
        list.setLabelProvider(new TerminologyLabelProvider());
55
        list.setContentProvider(new ArrayContentProvider());
56
        list.setInput(availableOntologies);
57
        if(initiallySelectedOntologies!=null){
58
            initiallySelectedOntologies.stream().forEach(wrapper->list.setChecked(wrapper, true));
59
        }
60
        return table;
61
    }
62

    
63
    @Override
64
    protected void configureShell(Shell newShell) {
65
        super.configureShell(newShell);
66
        newShell.setText("Choose ontologies");
67
    }
68

    
69
    @Override
70
    protected void okPressed() {
71
        selectedOntologies.clear();
72
        selectedOntologies = new ArrayList(Arrays.asList(list.getCheckedElements()));
73
        super.okPressed();
74
    }
75

    
76
    @Override
77
    protected boolean isResizable() {
78
        return true;
79
    }
80

    
81
    public Collection<TerminologyWrapper> getSelectedOntologies(){
82
        return selectedOntologies;
83
    }
84

    
85
}
(4-4/7)