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
|
|
15
|
import javax.inject.Named;
|
16
|
|
17
|
import org.eclipse.core.runtime.jobs.Job;
|
18
|
import org.eclipse.e4.core.di.annotations.CanExecute;
|
19
|
import org.eclipse.e4.core.di.annotations.Execute;
|
20
|
import org.eclipse.e4.core.di.annotations.Optional;
|
21
|
import org.eclipse.e4.ui.model.application.ui.basic.MPart;
|
22
|
import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
|
23
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
24
|
import org.eclipse.jface.viewers.IStructuredSelection;
|
25
|
import org.eclipse.swt.widgets.DirectoryDialog;
|
26
|
import org.eclipse.swt.widgets.Shell;
|
27
|
import org.eclipse.ui.progress.IProgressConstants;
|
28
|
|
29
|
import eu.etaxonomy.cdm.io.descriptive.owl.out.StructureTreeOwlExportConfigurator;
|
30
|
import eu.etaxonomy.cdm.model.term.FeatureTree;
|
31
|
import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
|
32
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
33
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
34
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
35
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
36
|
|
37
|
/**
|
38
|
* @author pplitzner
|
39
|
* @since Jul 12, 2017
|
40
|
*
|
41
|
*/
|
42
|
public class FeatureTreeExportOntologyHandler {
|
43
|
|
44
|
@Execute
|
45
|
public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
|
46
|
@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
47
|
@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
|
48
|
IFeatureTreeEditor editor = (IFeatureTreeEditor) thisPart.getObject();
|
49
|
|
50
|
if(StoreUtil.promptCheckIsDirty(editor)){
|
51
|
return;
|
52
|
}
|
53
|
|
54
|
List<FeatureTree> featureTrees = new ArrayList<>();
|
55
|
selection.toList().stream().filter(o->o instanceof FeatureTree).forEach(tree->featureTrees.add((FeatureTree)tree));
|
56
|
DirectoryDialog dialog = new DirectoryDialog(shell);
|
57
|
String directoryString = dialog.open();
|
58
|
if(directoryString!=null){
|
59
|
// create job
|
60
|
Job job = CdmStore.getExportManager().createIOServiceJob(StructureTreeOwlExportConfigurator.NewInstance(), new File(directoryString+"/term_trees.owl"));
|
61
|
// configure the job
|
62
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
63
|
job.setUser(true);
|
64
|
// schedule job
|
65
|
job.schedule();
|
66
|
}
|
67
|
}
|
68
|
|
69
|
@CanExecute
|
70
|
public boolean canExecute(
|
71
|
@Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
|
72
|
MHandledMenuItem menuItem) {
|
73
|
boolean canExecute = false;
|
74
|
canExecute = PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES)
|
75
|
&& selection!=null
|
76
|
&& selection.size()==1
|
77
|
&& selection.getFirstElement() instanceof FeatureTree;
|
78
|
menuItem.setVisible(canExecute);
|
79
|
return canExecute;
|
80
|
}
|
81
|
|
82
|
}
|