Project

General

Profile

Download (3.95 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.io.e4.out.owl;
10

    
11
import java.util.ArrayList;
12
import java.util.HashSet;
13
import java.util.List;
14
import java.util.Set;
15
import java.util.UUID;
16

    
17
import org.eclipse.jface.wizard.WizardPage;
18
import org.eclipse.swt.SWT;
19
import org.eclipse.swt.events.SelectionAdapter;
20
import org.eclipse.swt.events.SelectionEvent;
21
import org.eclipse.swt.widgets.Composite;
22
import org.eclipse.swt.widgets.FileDialog;
23

    
24
import eu.etaxonomy.cdm.api.service.IFeatureTreeService;
25
import eu.etaxonomy.cdm.api.service.IVocabularyService;
26
import eu.etaxonomy.cdm.model.term.FeatureTree;
27
import eu.etaxonomy.cdm.model.term.TermType;
28
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
29
import eu.etaxonomy.taxeditor.store.CdmStore;
30

    
31
/**
32
 * @author pplitzner
33
 * @since May 23, 2019
34
 *
35
 */
36
public class OwlTermExportWizardPage extends WizardPage {
37

    
38
    private OwlTermExportComposite composite;
39

    
40
    protected OwlTermExportWizardPage(String pageName) {
41
        super(pageName);
42
        setTitle("OWL Term Export");
43
        setDescription("Select the objects to export");
44
    }
45

    
46
    @Override
47
    public void createControl(Composite parent) {
48
        composite = new OwlTermExportComposite(parent, SWT.NONE);
49

    
50
        Set<TermType> termTypes = new HashSet<>();
51
        termTypes.add(TermType.Feature);
52
        termTypes.add(TermType.Structure);
53
        termTypes.add(TermType.Property);
54
        termTypes.add(TermType.State);
55
        termTypes.add(TermType.Character);
56
        List<TermVocabularyDto> areaVocabularies = CdmStore.getService(IVocabularyService.class).findVocabularyDtoByTermTypes(termTypes);
57
        composite.getSelectVocabularyComposite().getViewer().setInput(areaVocabularies);
58

    
59
        List<FeatureTree> trees = CdmStore.getService(IFeatureTreeService.class).list(FeatureTree.class, null, null, null, null);
60
        composite.getSelectFeatureTreeComposite().getViewer().setInput(trees);
61

    
62

    
63
        composite.getBtnSelectDirectory().addSelectionListener(new SelectionAdapter() {
64
            @Override
65
            public void widgetSelected(SelectionEvent e) {
66
                FileDialog dialog = new FileDialog(parent.getShell());
67
                String[] filterNames = {
68
                        "Web Ontology Language (*.owl)",
69
                        "Extensible Markup Language (*.xml)",
70
                        "All files (*.*)"
71
                        };
72
                String[] filterExtensions = { "*.owl", "*.xml", "*.*"};
73

    
74
                dialog.setOverwrite(true);
75
                dialog.setFilterNames(filterNames);
76
                dialog.setFilterExtensions(filterExtensions);
77
                String fileString = dialog.open();
78
                if(fileString!=null){
79
                    composite.getTxtExportDirectory().setText(fileString);
80
                }
81
            }
82
        });
83
        setControl(composite);
84
    }
85

    
86
    String getExportDirectory(){
87
        return composite.getExportDirectory();
88
    }
89

    
90
    List<FeatureTree> getSelectedTrees(){
91
        List<FeatureTree> selectedTrees = new ArrayList<>();
92
        Object[] checkedElements = composite.getSelectFeatureTreeComposite().getViewer().getCheckedElements();
93
        for (Object object : checkedElements) {
94
            if(object instanceof FeatureTree) {
95
                selectedTrees.add((FeatureTree) object);
96
            }
97
        }
98
        return selectedTrees;
99
    }
100

    
101
    List<UUID> getSelectedVocabularies(){
102
        List<UUID> vocs = new ArrayList<>();
103
        Object[] checkedElements = composite.getSelectVocabularyComposite().getViewer().getCheckedElements();
104
        for (Object object : checkedElements) {
105
            if(object instanceof TermVocabularyDto){
106
                vocs.add(((TermVocabularyDto) object).getUuid());
107
            }
108
        }
109
        return vocs;
110
    }
111

    
112
}
(4-4/4)