ref #6774 Add owl export to feature tree editor context menu
authorPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 5 Dec 2018 10:26:32 +0000 (11:26 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Wed, 5 Dec 2018 10:26:32 +0000 (11:26 +0100)
eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle.properties
eu.etaxonomy.taxeditor.store/OSGI-INF/l10n/bundle_de.properties
eu.etaxonomy.taxeditor.store/fragment.e4xmi
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/FeatureTreeExportOntologyHandler.java [new file with mode: 0644]

index 8337db8f9229279eedbeb3877f5f75b8014bac44..6b5e44d90b52c96263ce46745ed35b7101e721fc 100644 (file)
@@ -203,7 +203,7 @@ command.name.112 = Open Admin CommonNameArea-Wizard
 handledmenuitem.label.1 = New Feature Tree
 handledmenuitem.label.2 = Add Child Feature
 handledmenuitem.label.3 = Add Feature
-handledmenuitem.label.4 = Export Feature Tree
+handledmenuitem.label.4 = Export as Word file
 handledmenuitem.label.5 = Remove Feature
 handledmenuitem.label.6 = Delete Feature Tree
 handledmenuitem.label.7 = Kind Of Term
@@ -236,3 +236,7 @@ handledmenuitem.label.13 = Copy
 command.commandname.11 = Copy Feature\r
 command.commandname.12 = Paste Feature\r
 command.commandname.13 = Open Distribution Status Wizard\r
+
+menu.label.4 = Export
+handledmenuitem.label.14 = Export as Ontology
+command.commandname.14 = Export as Ontology
index d61606aff7452c74eb738ff5b90155211884197d..79d1115fff1a4a7752ef220f79550be4a18483d3 100644 (file)
@@ -203,7 +203,7 @@ command.name.112 = \u00d6ffne Admin Common Name Areal-Wizard
 handledmenuitem.label.1 = Neuer Merkmalsbaum
 handledmenuitem.label.2 = Merkmal als Kind hinzufügen
 handledmenuitem.label.3 = Merkmal hinzufügen
-handledmenuitem.label.4 = Merkmalsbaum exportieren
+handledmenuitem.label.4 = Als Word-Datei exportieren
 handledmenuitem.label.5 = Merkmal entfernen
 handledmenuitem.label.6 = Merkmalsbaum löschen
 handledmenuitem.label.7 = Kind-Of Term
@@ -230,4 +230,8 @@ menu.label.2 = Export
 menu.label.3 = Import
 handledmenuitem.label.10 = Neustarten
 handledmenuitem.label.11 = Nach Updates suchen
-command.commandname.13 = Öffne Verbreitungsstatus Wizard
\ No newline at end of file
+command.commandname.13 = Öffne Verbreitungsstatus Wizard
+
+menu.label.4 = Export
+handledmenuitem.label.14 = Export als Ontologie
+command.commandname.14 = Export als Ontologie
\ No newline at end of file
index fbd3c68e3d571e408f8eaa75bad8340be1478b2a..4e8f81be54c8b3be6e079fe3b91ca6bea8e2f397 100644 (file)
@@ -13,6 +13,7 @@
       <handlers xmi:id="_Bb0TwCFeEeiVXriJfxPIuA" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureTreeHandlers" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureTreeHandler" command="_3mqzkCFdEeiVXriJfxPIuA"/>
       <handlers xmi:id="_VSc2UGcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportHandler" command="_I_yx4GcqEee0qLTtA2ZpVQ"/>
       <handlers xmi:id="_3wq0cGceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.AddFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.AddFeatureHandler" command="_oftL0GceEee0qLTtA2ZpVQ"/>
+      <handlers xmi:id="_DcmpgPhnEei8uPv-H2wqnw" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportOntologyHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.FeatureTreeExportOntologyHandler" command="_xyZ4oPhmEei8uPv-H2wqnw"/>
       <menus xsi:type="menu:PopupMenu" xmi:id="__Jwh4GceEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.popupmenu.featureTreeEditor">
         <children xsi:type="menu:HandledMenuItem" xmi:id="_GuuM0CHXEeiP8eNo0PEm1g" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.newfeaturetree" label="%handledmenuitem.label.1" iconURI="platform:/plugin/org.eclipse.ui/icons/full/etool16/new_wiz.png" command="_AJtnsCHXEeiP8eNo0PEm1g"/>
         <children xsi:type="menu:MenuSeparator" xmi:id="_eIB1kCHXEeiP8eNo0PEm1g" elementId="eu.etaxonomy.taxeditor.store.menuseparator.5"/>
         <children xsi:type="menu:HandledMenuItem" xmi:id="_G_IOENj3EeidDMMI9xTsbQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.paste" label="%handledmenuitem.label.12" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/paste_edit.png" command="_xDk5kNjyEeidDMMI9xTsbQ"/>
         <children xsi:type="menu:HandledMenuItem" xmi:id="_QXkWYNjyEeidDMMI9xTsbQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.copy" label="%handledmenuitem.label.13" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/copy_edit.png" command="_cMyQ4NjyEeidDMMI9xTsbQ"/>
         <children xsi:type="menu:MenuSeparator" xmi:id="_So5f0NjyEeidDMMI9xTsbQ" elementId="eu.etaxonomy.taxeditor.store.menuseparator.7"/>
-        <children xsi:type="menu:HandledMenuItem" xmi:id="_7vaEcGcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.exportFeatureTree" label="%handledmenuitem.label.4" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/export.gif" command="_I_yx4GcqEee0qLTtA2ZpVQ">
-          <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_-91IQGcqEee0qLTtA2ZpVQ" coreExpressionId="isShowExperimentalFeatures"/>
+        <children xsi:type="menu:Menu" xmi:id="_jPawUPhmEei8uPv-H2wqnw" elementId="eu.etaxonomy.taxeditor.store.menu.export" label="%menu.label.4">
+          <children xsi:type="menu:HandledMenuItem" xmi:id="_7vaEcGcqEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.exportFeatureTreeOwl" label="%handledmenuitem.label.14" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/export.gif" command="_xyZ4oPhmEei8uPv-H2wqnw">
+            <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_-91IQGcqEee0qLTtA2ZpVQ" coreExpressionId="isShowExperimentalFeatures"/>
+          </children>
+          <children xsi:type="menu:HandledMenuItem" xmi:id="_qcmvwPhmEei8uPv-H2wqnw" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.exportFeatureTree" label="%handledmenuitem.label.4" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/export.gif" command="_I_yx4GcqEee0qLTtA2ZpVQ">
+            <visibleWhen xsi:type="ui:CoreExpression" xmi:id="_qcmvwfhmEei8uPv-H2wqnw" coreExpressionId="isShowExperimentalFeatures"/>
+          </children>
         </children>
         <children xsi:type="menu:MenuSeparator" xmi:id="_TFRL0CFgEeiVXriJfxPIuA" elementId="eu.etaxonomy.taxeditor.store.menuseparator.0"/>
         <children xsi:type="menu:HandledMenuItem" xmi:id="_Beb6QGcfEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.store.handledmenuitem.removeFeature" label="%handledmenuitem.label.5" iconURI="platform:/plugin/eu.etaxonomy.taxeditor.store/icons/delete.gif" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
     <elements xsi:type="commands:Command" xmi:id="_cMyQ4NjyEeidDMMI9xTsbQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.copyFeature" commandName="%command.commandname.11"/>
     <elements xsi:type="commands:Command" xmi:id="_xDk5kNjyEeidDMMI9xTsbQ" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.pasteFeature" commandName="%command.commandname.12"/>
     <elements xsi:type="commands:Command" xmi:id="_Za5DYO5vEeizn7bmbAeBkw" elementId="eu.etaxonomy.taxeditor.store.open.OpenDistributionStatusWizardHandler" commandName="%command.commandname.13"/>
+    <elements xsi:type="commands:Command" xmi:id="_xyZ4oPhmEei8uPv-H2wqnw" elementId="eu.etaxonomy.taxeditor.store.command.featureTree.exportTreeOntology" commandName="%command.commandname.14"/>
   </fragments>
   <fragments xsi:type="fragment:StringModelFragment" xmi:id="_swGH0GhvEee3K4uKJljEYg" featurename="handlers" parentElementId="xpath:/">
     <elements xsi:type="commands:Handler" xmi:id="_rVEdIGcjEee0qLTtA2ZpVQ" elementId="eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" contributionURI="bundleclass://eu.etaxonomy.taxeditor.store/eu.etaxonomy.taxeditor.featuretree.e4.handler.RemoveFeatureHandler" command="_fNBtQGcjEee0qLTtA2ZpVQ"/>
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/FeatureTreeExportOntologyHandler.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/featuretree/e4/handler/FeatureTreeExportOntologyHandler.java
new file mode 100644 (file)
index 0000000..522b55c
--- /dev/null
@@ -0,0 +1,79 @@
+/**
+* Copyright (C) 2017 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* The contents of this file are subject to the Mozilla Public License Version 1.1
+* See LICENSE.TXT at the top of this package for the full license terms.
+*/
+package eu.etaxonomy.taxeditor.featuretree.e4.handler;
+
+import java.io.File;
+
+import javax.inject.Named;
+
+import org.eclipse.core.runtime.jobs.Job;
+import org.eclipse.e4.core.di.annotations.CanExecute;
+import org.eclipse.e4.core.di.annotations.Execute;
+import org.eclipse.e4.core.di.annotations.Optional;
+import org.eclipse.e4.ui.model.application.ui.basic.MPart;
+import org.eclipse.e4.ui.model.application.ui.menu.MHandledMenuItem;
+import org.eclipse.e4.ui.services.IServiceConstants;
+import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.swt.widgets.DirectoryDialog;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.progress.IProgressConstants;
+
+import eu.etaxonomy.cdm.io.descriptive.owl.out.OwlExportConfigurator;
+import eu.etaxonomy.cdm.model.description.FeatureTree;
+import eu.etaxonomy.taxeditor.featuretree.e4.IFeatureTreeEditor;
+import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
+import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
+
+/**
+ * @author pplitzner
+ * @since Jul 12, 2017
+ *
+ */
+public class FeatureTreeExportOntologyHandler {
+
+    @Execute
+    public void execute(@Named(IServiceConstants.ACTIVE_SHELL) Shell shell,
+            @Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
+            @Named(IServiceConstants.ACTIVE_PART)MPart thisPart){
+        IFeatureTreeEditor editor = (IFeatureTreeEditor) thisPart.getObject();
+
+        if(StoreUtil.checkDirty(editor)){
+            return;
+        }
+
+        FeatureTree selectedFeatureTree = (FeatureTree) selection.getFirstElement();
+        DirectoryDialog dialog = new DirectoryDialog(shell);
+        String directoryString = dialog.open();
+        if(directoryString!=null){
+            // create job
+            Job job = CdmStore.getExportManager().createIOServiceJob(OwlExportConfigurator.NewInstance(null, null, selectedFeatureTree), new File(directoryString+"/"+selectedFeatureTree.getTitleCache()+".owl"));
+            // configure the job
+            job.setProperty(IProgressConstants.KEEP_PROPERTY, true);
+            job.setUser(true);
+            // schedule job
+            job.schedule();
+        }
+    }
+
+    @CanExecute
+    public boolean canExecute(
+            @Optional@Named(IServiceConstants.ACTIVE_SELECTION)IStructuredSelection selection,
+            MHandledMenuItem menuItem) {
+        boolean canExecute = false;
+        canExecute = PreferencesUtil.getBooleanValue(IPreferenceKeys.SHOW_EXPERIMENTAL_FEATURES)
+                && selection!=null
+                && selection.size()==1
+                && selection.getFirstElement() instanceof FeatureTree;
+        menuItem.setVisible(canExecute);
+        return canExecute;
+    }
+
+}