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
.NullProgressMonitor
;
16 import org
.eclipse
.core
.runtime
.jobs
.Job
;
17 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
18 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
19 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
20 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
21 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
22 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
23 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
24 import org
.eclipse
.swt
.widgets
.DirectoryDialog
;
25 import org
.eclipse
.swt
.widgets
.Shell
;
26 import org
.eclipse
.ui
.progress
.IProgressConstants
;
28 import eu
.etaxonomy
.cdm
.io
.descriptive
.owl
.out
.OwlExportConfigurator
;
29 import eu
.etaxonomy
.cdm
.model
.description
.FeatureTree
;
30 import eu
.etaxonomy
.taxeditor
.featuretree
.e4
.FeatureNodeDropAdapter
;
31 import eu
.etaxonomy
.taxeditor
.featuretree
.e4
.FeatureTreeEditor
;
32 import eu
.etaxonomy
.taxeditor
.model
.MessagingUtils
;
33 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
40 public class FeatureTreeExportHandler
{
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 FeatureTreeEditor editor
= (FeatureTreeEditor
) thisPart
.getObject();
48 if (editor
.isDirty()) {
49 if (MessagingUtils
.confirmDialog(FeatureNodeDropAdapter
.SAVE_CHANGES_TITLE
,
50 FeatureNodeDropAdapter
.SAVE_CHANGES_MESSAGE
)){
51 editor
.save(new NullProgressMonitor());
58 FeatureTree selectedFeatureTree
= (FeatureTree
) selection
.getFirstElement();
59 DirectoryDialog dialog
= new DirectoryDialog(shell
);
60 String directoryString
= dialog
.open();
61 if(directoryString
!=null){
63 Job job
= CdmStore
.getExportManager().createIOServiceJob(OwlExportConfigurator
.NewInstance(null, null, selectedFeatureTree
), new File(directoryString
+"/owl.owl"));
65 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
73 public boolean canExecute(
74 @Optional@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
75 MHandledMenuItem menuItem
) {
76 boolean canExecute
= false;
77 canExecute
= selection
!=null
78 && selection
.size()==1
79 && selection
.getFirstElement() instanceof FeatureTree
;
80 menuItem
.setVisible(canExecute
);