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
;
12 import java
.util
.ArrayList
;
13 import java
.util
.List
;
14 import java
.util
.UUID
;
16 import javax
.inject
.Named
;
18 import org
.eclipse
.core
.runtime
.jobs
.Job
;
19 import org
.eclipse
.e4
.core
.di
.annotations
.CanExecute
;
20 import org
.eclipse
.e4
.core
.di
.annotations
.Execute
;
21 import org
.eclipse
.e4
.core
.di
.annotations
.Optional
;
22 import org
.eclipse
.e4
.ui
.model
.application
.ui
.basic
.MPart
;
23 import org
.eclipse
.e4
.ui
.model
.application
.ui
.menu
.MHandledMenuItem
;
24 import org
.eclipse
.e4
.ui
.services
.IServiceConstants
;
25 import org
.eclipse
.jface
.viewers
.IStructuredSelection
;
26 import org
.eclipse
.swt
.widgets
.FileDialog
;
27 import org
.eclipse
.swt
.widgets
.Shell
;
28 import org
.eclipse
.ui
.progress
.IProgressConstants
;
30 import eu
.etaxonomy
.cdm
.io
.descriptive
.owl
.out
.StructureTreeOwlExportConfigurator
;
31 import eu
.etaxonomy
.cdm
.model
.term
.TermTree
;
32 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermTreeDto
;
33 import eu
.etaxonomy
.taxeditor
.featuretree
.e4
.IFeatureTreeEditor
;
34 import eu
.etaxonomy
.taxeditor
.store
.CdmStore
;
35 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
42 public class FeatureTreeExportOntologyHandler
{
45 public void execute(@Named(IServiceConstants
.ACTIVE_SHELL
) Shell shell
,
46 @Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
47 @Named(IServiceConstants
.ACTIVE_PART
)MPart thisPart
){
48 IFeatureTreeEditor editor
= (IFeatureTreeEditor
) thisPart
.getObject();
50 if(StoreUtil
.promptCheckIsDirty(editor
)){
54 List
<UUID
> featureTreeUuids
= new ArrayList
<>();
55 selection
.toList().stream().filter(o
->o
instanceof TermTree
).forEach(tree
->featureTreeUuids
.add(((TermTree
)tree
).getUuid()));
57 FileDialog dialog
= new FileDialog(shell
);
58 String
[] filterNames
= {
59 "Web Ontology Language (*.owl)",
60 "Extensible Markup Language (*.xml)",
63 String
[] filterExtensions
= { "*.owl", "*.xml", "*.*"};
65 dialog
.setOverwrite(true);
66 dialog
.setFilterNames(filterNames
);
67 dialog
.setFilterExtensions(filterExtensions
);
68 String fileString
= dialog
.open();
71 StructureTreeOwlExportConfigurator configurator
= StructureTreeOwlExportConfigurator
.NewInstance();
73 configurator
.setFeatureTreeUuids(featureTreeUuids
);
75 Job job
= CdmStore
.getExportManager().createIOServiceJob(configurator
, new File(fileString
));
77 job
.setProperty(IProgressConstants
.KEEP_PROPERTY
, true);
85 public boolean canExecute(
86 @Optional@Named(IServiceConstants
.ACTIVE_SELECTION
)IStructuredSelection selection
,
87 MHandledMenuItem menuItem
) {
88 boolean canExecute
= false;
89 canExecute
= selection
!=null
90 && selection
.size()==1
91 && selection
.getFirstElement() instanceof TermTreeDto
;
92 menuItem
.setVisible(canExecute
);