Add menu option to open specimens from navigator
authorPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 9 Feb 2016 06:37:57 +0000 (07:37 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Tue, 16 Feb 2016 14:14:49 +0000 (15:14 +0100)
eu.etaxonomy.taxeditor.editor/plugin.xml
eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/OpenDerivativeEditorForTaxonNode.java [new file with mode: 0644]
eu.etaxonomy.taxeditor.navigation/plugin.xml

index 64aa8f2cf55f7c3dd463ec4a7b4ffd33327b7168..0db8a38fe9ac7b01e87383a22525c6d6d9dae82f 100644 (file)
               </or>
             </visibleWhen>
          </command>
+         <separator
+               name="eu.etaxonomy.taxeditor.editor.separator1">
+         </separator>
          <dynamic
                class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
                id="eu.etaxonomy.taxeditor.editor.descriptive.cdmViewerContextMenu">
             </with>
          </activeWhen>
       </handler>
+      <handler
+            class="eu.etaxonomy.taxeditor.editor.view.derivate.handler.OpenDerivativeEditorForDescriptionElement"
+            commandId="eu.etaxonomy.taxeditor.editor.openSpecimenEditor">
+         <activeWhen>
+            <with
+                  variable="selection">
+               <reference
+                     definitionId="isTaxonNode">
+               </reference>
+            </with>
+         </activeWhen>
+      </handler>
    </extension>
    <extension
          name="%extension.name"
             selection="eu.etaxonomy.cdm.model.description.IndividualsAssociation"
             viewerName="Derivative Editor">
       </viewCommandMapping>
+      <viewCommandMapping
+            commandId="eu.etaxonomy.taxeditor.editor.openSpecimenEditor"
+            selection="eu.etaxonomy.cdm.model.taxon.TaxonNode"
+            viewerName="Derivative Editor">
+      </viewCommandMapping>
     </extension>
 </plugin>
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/OpenDerivativeEditorForTaxonNode.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/OpenDerivativeEditorForTaxonNode.java
new file mode 100644 (file)
index 0000000..6fdbcd4
--- /dev/null
@@ -0,0 +1,44 @@
+package eu.etaxonomy.taxeditor.editor.view.derivate.handler;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.UUID;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.ui.PartInitException;
+
+import eu.etaxonomy.cdm.api.service.IOccurrenceService;
+import eu.etaxonomy.cdm.api.service.ITaxonNodeService;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+import eu.etaxonomy.cdm.model.taxon.TaxonNode;
+import eu.etaxonomy.taxeditor.editor.EditorUtil;
+import eu.etaxonomy.taxeditor.editor.handler.OpenDerivateViewHandler;
+import eu.etaxonomy.taxeditor.editor.view.derivate.DerivateViewEditorInput;
+import eu.etaxonomy.taxeditor.handler.defaultHandler.DefaultOpenHandlerBase;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+
+public class OpenDerivativeEditorForTaxonNode extends DefaultOpenHandlerBase<TaxonNode> {
+
+    @Override
+    protected TaxonNode getEntity(UUID uuid) {
+        return CdmStore.getService(ITaxonNodeService.class).load(uuid);
+    }
+
+    @Override
+    protected void open(ExecutionEvent event, TaxonNode entity) {
+        List<SpecimenOrObservationBase> specimens = CdmStore.getService(IOccurrenceService.class).listByAssociatedTaxon(SpecimenOrObservationBase.class, null, entity.getTaxon(), null, null, null, null, null);
+        Collection<UUID> specimenUuids = new ArrayList<UUID>();
+        for (SpecimenOrObservationBase specimenOrObservationBase : specimens) {
+            specimenUuids.add(specimenOrObservationBase.getUuid());
+        }
+        try {
+            EditorUtil.open(new DerivateViewEditorInput(specimenUuids));
+        } catch (PartInitException e) {
+            MessagingUtils.error(OpenDerivateViewHandler.class, "Derivative Editor could not be opened", e);
+        }
+
+    }
+
+}
index 85bdb483836641ab6d19fdd0a49c8158ef069118..bb559905435cd298792a810b3fdd8ad7d890f350 100644 (file)
                class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
                id="eu.etaxonomy.taxeditor.navigation.cdmViewerContextMenu">
          </dynamic>
+         <separator
+               name="eu.etaxonomy.taxeditor.navigation.separator2">
+         </separator>
          <command
                commandId="eu.etaxonomy.taxeditor.navigator.command.update.changeAcceptedToSynonym"
                label="%command.label.6"