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