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.ui.model.application.ui.basic.MPart;
|
19
|
import org.eclipse.e4.ui.services.IServiceConstants;
|
20
|
import org.eclipse.swt.widgets.DirectoryDialog;
|
21
|
import org.eclipse.swt.widgets.Shell;
|
22
|
import org.eclipse.ui.progress.IProgressConstants;
|
23
|
|
24
|
import eu.etaxonomy.cdm.io.descriptive.owl.out.OwlExportConfigurator;
|
25
|
import eu.etaxonomy.cdm.model.description.FeatureTree;
|
26
|
import eu.etaxonomy.taxeditor.featuretree.e4.FeatureTreeEditor;
|
27
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
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_PART)MPart thisPart){
|
40
|
FeatureTreeEditor editor = ((FeatureTreeEditor) thisPart.getObject());
|
41
|
FeatureTree selectedFeatureTree = editor.getSelectedFeatureTree();
|
42
|
if(selectedFeatureTree==null){
|
43
|
MessagingUtils.informationDialog("Export not possible", "There is no feature tree selected.");
|
44
|
return;
|
45
|
}
|
46
|
DirectoryDialog dialog = new DirectoryDialog(shell);
|
47
|
String directoryString = dialog.open();
|
48
|
if(directoryString!=null){
|
49
|
// create job
|
50
|
Job job = CdmStore.getExportManager().createIOServiceJob(OwlExportConfigurator.NewInstance(null, null, selectedFeatureTree), new File(directoryString+"/owl.owl"));
|
51
|
// configure the job
|
52
|
job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
|
53
|
job.setUser(true);
|
54
|
// schedule job
|
55
|
job.schedule();
|
56
|
}
|
57
|
}
|
58
|
|
59
|
@CanExecute
|
60
|
public boolean canExecute(@Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
|
61
|
return thisPart.getObject() instanceof FeatureTreeEditor && ((FeatureTreeEditor) thisPart.getObject()).getSelectedFeatureTree()!=null;
|
62
|
}
|
63
|
|
64
|
}
|