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