Project

General

Profile

Download (3.17 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.Collections;
14
import java.util.List;
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.DirectoryDialog;
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.FeatureTree;
32
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
33
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
34
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
35
import eu.etaxonomy.taxeditor.store.CdmStore;
36
import eu.etaxonomy.taxeditor.store.StoreUtil;
37

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

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

    
51
        if(StoreUtil.promptCheckIsDirty(editor)){
52
            return;
53
        }
54

    
55
        List<FeatureTree> featureTrees = new ArrayList<>();
56
        selection.toList().stream().filter(o->o instanceof FeatureTree).forEach(tree->featureTrees.add((FeatureTree)tree));
57
        DirectoryDialog dialog = new DirectoryDialog(shell);
58
        String directoryString = dialog.open();
59
        if(directoryString!=null){
60
            // create job
61
            Job job = CdmStore.getExportManager().createIOServiceJob(StructureTreeOwlExportConfigurator.NewInstance(null, null, featureTrees, Collections.EMPTY_LIST), new File(directoryString+"/term_trees.owl"));
62
            // configure the job
63
            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
64
            job.setUser(true);
65
            // schedule job
66
            job.schedule();
67
        }
68
    }
69

    
70
    @CanExecute
71
    public boolean canExecute(
72
            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
73
            MHandledMenuItem menuItem) {
74
        boolean canExecute = false;
75
        canExecute = PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES)
76
                && selection!=null
77
                && selection.size()==1
78
                && selection.getFirstElement() instanceof FeatureTree;
79
        menuItem.setVisible(canExecute);
80
        return canExecute;
81
    }
82

    
83
}
(5-5/9)