2 * Copyright (C) 2017 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.featuretree
.e4
.handler
;
13 import javax
.inject
.Named
;
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
;
27 import eu
.etaxonomy
.cdm
.io
.descriptive
.word
.out
.WordExportConfigurator
;
28 import eu
.etaxonomy
.cdm
.model
.term
.TermTree
;
29 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermTreeDto
;
30 import eu
.etaxonomy
.taxeditor
.featuretree
.e4
.IFeatureTreeEditor
;
31 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
32 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
34 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
41 public class FeatureTreeExportWordHandler
{
44 public void execute(@Named(IServiceConstants
.ACTIVE_SHELL
) Shell shell
,
45 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
46 @Named(IServiceConstants
.ACTIVE_PART
)MPart thisPart
){
47 IFeatureTreeEditor editor
= (IFeatureTreeEditor
) thisPart
.getObject();
49 if(StoreUtil
.promptCheckIsDirty(editor
)){
53 TermTree selectedFeatureTree
= (TermTree
) selection
.getFirstElement();
54 DirectoryDialog dialog
= new DirectoryDialog(shell
);
55 String directoryString
= dialog
.open();
56 if(directoryString
!=null){
58 Job job
= CdmStore
.getExportManager().createIOServiceJob(WordExportConfigurator
.NewInstance(null, null, selectedFeatureTree
), new File(directoryString
+"/"+selectedFeatureTree
.getTitleCache()+".docx"));
60 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
68 public boolean canExecute(
69 @Optional@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
70 MHandledMenuItem menuItem
) {
71 boolean canExecute
= false;
72 canExecute
= PreferencesUtil
.getBooleanValue(IPreferenceKeys
.SHOW_EXPERIMENTAL_FEATURES
)
74 && selection
.size()==1
75 && selection
.getFirstElement() instanceof TermTreeDto
;
76 menuItem
.setVisible(canExecute
);