Project

General

Profile

Download (3.38 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2017 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.featuretree.e4.handler;
10

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

    
16
import javax.inject.Named;
17

    
18
import org.eclipse.core.runtime.jobs.Job;
19
import org.eclipse.e4.core.di.annotations.CanExecute;
20
import org.eclipse.e4.core.di.annotations.Execute;
21
import org.eclipse.e4.core.di.annotations.Optional;
22
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
23
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
24
import org.eclipse.e4.ui.services.IServiceConstants;
25
import org.eclipse.jface.viewers.IStructuredSelection;
26
import org.eclipse.swt.widgets.FileDialog;
27
import org.eclipse.swt.widgets.Shell;
28
import org.eclipse.ui.progress.IProgressConstants;
29

    
30
import eu.etaxonomy.cdm.io.descriptive.owl.out.StructureTreeOwlExportConfigurator;
31
import eu.etaxonomy.cdm.model.term.TermTree;
32
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
33
import eu.etaxonomy.taxeditor.store.CdmStore;
34
import eu.etaxonomy.taxeditor.store.StoreUtil;
35

    
36
/**
37
 * @author pplitzner
38
 * @since Jul 12, 2017
39
 *
40
 */
41
public class FeatureTreeExportOntologyHandler {
42

    
43
    @Execute
44
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
45
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
46
            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
47
        IFeatureTreeEditor editor = (IFeatureTreeEditor) thisPart.getObject();
48

    
49
        if(StoreUtil.promptCheckIsDirty(editor)){
50
            return;
51
        }
52

    
53
        List<UUID> featureTreeUuids = new ArrayList<>();
54
        selection.toList().stream().filter(o->o instanceof TermTree).forEach(tree->featureTreeUuids.add(((TermTree)tree).getUuid()));
55

    
56
        FileDialog dialog = new FileDialog(shell);
57
        String[] filterNames = {
58
                "Web Ontology Language (*.owl)",
59
                "Extensible Markup Language (*.xml)",
60
                "All files (*.*)"
61
                };
62
        String[] filterExtensions = { "*.owl", "*.xml", "*.*"};
63

    
64
        dialog.setOverwrite(true);
65
        dialog.setFilterNames(filterNames);
66
        dialog.setFilterExtensions(filterExtensions);
67
        String fileString = dialog.open();
68
        if(fileString!=null){
69
            // create job
70
            StructureTreeOwlExportConfigurator configurator = StructureTreeOwlExportConfigurator.NewInstance();
71

    
72
            configurator.setFeatureTreeUuids(featureTreeUuids);
73

    
74
            Job job = CdmStore.getExportManager().createIOServiceJob(configurator, new File(fileString));
75
            // configure the job
76
            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
77
            job.setUser(true);
78
            // schedule job
79
            job.schedule();
80
        }
81
    }
82

    
83
    @CanExecute
84
    public boolean canExecute(
85
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
86
            MHandledMenuItem menuItem) {
87
        boolean canExecute = false;
88
        canExecute = selection!=null
89
                && selection.size()==1
90
                && selection.getFirstElement() instanceof TermTree;
91
        menuItem.setVisible(canExecute);
92
        return canExecute;
93
    }
94

    
95
}
(5-5/9)