Project

General

Profile

Download (2.35 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

    
13
import javax.inject.Named;
14

    
15
import org.eclipse.core.runtime.jobs.Job;
16
import org.eclipse.e4.core.di.annotations.CanExecute;
17
import org.eclipse.e4.core.di.annotations.Execute;
18
import org.eclipse.e4.core.di.annotations.Optional;
19
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
20
import org.eclipse.e4.ui.services.IServiceConstants;
21
import org.eclipse.jface.viewers.IStructuredSelection;
22
import org.eclipse.swt.widgets.DirectoryDialog;
23
import org.eclipse.swt.widgets.Shell;
24
import org.eclipse.ui.progress.IProgressConstants;
25

    
26
import eu.etaxonomy.cdm.io.descriptive.owl.out.OwlExportConfigurator;
27
import eu.etaxonomy.cdm.model.description.FeatureTree;
28
import eu.etaxonomy.taxeditor.store.CdmStore;
29

    
30
/**
31
 * @author pplitzner
32
 * @since Jul 12, 2017
33
 *
34
 */
35
public class FeatureTreeExportHandler {
36

    
37
    @Execute
38
    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
39
            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection){
40
        FeatureTree selectedFeatureTree = (FeatureTree) selection.iterator().next();
41
        DirectoryDialog dialog = new DirectoryDialog(shell);
42
        String directoryString = dialog.open();
43
        if(directoryString!=null){
44
            // create job
45
            Job job = CdmStore.getExportManager().createIOServiceJob(OwlExportConfigurator.NewInstance(null, null, selectedFeatureTree), new File(directoryString+"/owl.owl"));
46
            // configure the job
47
            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
48
            job.setUser(true);
49
            // schedule job
50
            job.schedule();
51
        }
52
    }
53

    
54
    @CanExecute
55
    public boolean canExecute(
56
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
57
            MHandledMenuItem menuItem) {
58
        boolean canExecute = false;
59
        canExecute = selection!=null
60
                && selection.size()==1
61
                && selection.iterator().next() instanceof FeatureTree;
62
        menuItem.setVisible(canExecute);
63
        return canExecute;
64
    }
65

    
66
}
(3-3/5)