Extend factual data view context menu with option to open specimen directly in Deriva...
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 8 Feb 2016 17:05:18 +0000 (18:05 +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/OpenDerivativeEditorForDescriptionElement.java [new file with mode: 0644]

index eb5070d240c4b7d07f9e684db1852bc657e7df43..64aa8f2cf55f7c3dd463ec4a7b4ffd33327b7168 100644 (file)
                label="%command.label.27"
                style="push">
          </command>
-         <separator
-               name="eu.etaxonomy.taxeditor.taxonDescriptionEditor.separator3"
-               visible="true">
-         </separator>
-         <menu
-               label="%menu.label.1">
-            <dynamic
-                  class="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.DynamicFeatureMenu"
-                  id="eu.etaxonomy.taxeditor.dynamicFeatureMenu">
-            </dynamic>
-            <visibleWhen
-                  checkEnabled="true">
-               <or>
-                  <reference
-                        definitionId="isDescription">
-                  </reference>
-                  <reference
-                        definitionId="isDescriptionElement">
-                  </reference>
-                  <reference
-                        definitionId="isFeatureNodeContainer">
-                  </reference>
-               </or>
-            </visibleWhen>
-         </menu>
          <command
                commandId="eu.etaxonomy.taxeditor.editor.view.descriptive.command.moveDescriptionToTaxon"
                label="%command.label.28"
               </or>
             </visibleWhen>
          </command>
+         <dynamic
+               class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
+               id="eu.etaxonomy.taxeditor.editor.descriptive.cdmViewerContextMenu">
+         </dynamic>
+         <separator
+               name="eu.etaxonomy.taxeditor.editor.separator1">
+         </separator>
          <separator
                name="eu.etaxonomy.taxeditor.taxonDescriptionEditor.separator.afterNew"
                visible="true">
          <separator
                name="eu.etaxonomy.taxeditor.editor.separator1">
          </separator>
+         <separator
+               name="eu.etaxonomy.taxeditor.taxonDescriptionEditor.separator3"
+               visible="true">
+         </separator>
+         <menu
+               label="%menu.label.1">
+            <dynamic
+                  class="eu.etaxonomy.taxeditor.editor.view.descriptive.handler.DynamicFeatureMenu"
+                  id="eu.etaxonomy.taxeditor.dynamicFeatureMenu">
+            </dynamic>
+            <visibleWhen
+                  checkEnabled="true">
+               <or>
+                  <reference
+                        definitionId="isDescription">
+                  </reference>
+                  <reference
+                        definitionId="isDescriptionElement">
+                  </reference>
+                  <reference
+                        definitionId="isFeatureNodeContainer">
+                  </reference>
+               </or>
+            </visibleWhen>
+         </menu>
       </menuContribution>
       <menuContribution
             locationURI="popup:eu.etaxonomy.taxeditor.editor.view.derivate.DerivateView">
             </with>
          </activeWhen>
       </handler>
+      <handler
+            class="eu.etaxonomy.taxeditor.editor.view.derivate.handler.OpenDerivativeEditorForDescriptionElement"
+            commandId="eu.etaxonomy.taxeditor.editor.openSpecimenEditor">
+         <activeWhen>
+            <with
+                  variable="activePartId">
+               <equals
+                     value="eu.etaxonomy.taxeditor.editor.view.descriptive">
+               </equals>
+            </with>
+         </activeWhen>
+      </handler>
    </extension>
    <extension
          name="%extension.name"
             defaultHandler="eu.etaxonomy.taxeditor.editor.handler.OpenDerivateViewHandler"
             id="eu.etaxonomy.taxeditor.editor.openSpecimenEditor"
             name="Open Derivative Editor">
+         <commandParameter
+               id="eu.etaxonomy.taxeditor.editor.openSpecimenEditor.uuid"
+               name="Specimen Uuids"
+               optional="true"
+               typeId="eu.etaxonomy.taxeditor.uuidParameterType">
+         </commandParameter>
       </command>
       <command
             defaultHandler="eu.etaxonomy.taxeditor.editor.view.derivate.handler.ListenToSelectionChangeHandler"
             selection="eu.etaxonomy.cdm.model.taxon.TaxonBase"
             viewerName="TaxonEditor">
       </viewCommandMapping>
+      <viewCommandMapping
+            commandId="eu.etaxonomy.taxeditor.editor.openSpecimenEditor"
+            selection="eu.etaxonomy.cdm.model.description.IndividualsAssociation"
+            viewerName="Derivative Editor">
+      </viewCommandMapping>
     </extension>
 </plugin>
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/OpenDerivativeEditorForDescriptionElement.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/derivate/handler/OpenDerivativeEditorForDescriptionElement.java
new file mode 100644 (file)
index 0000000..7e3b08b
--- /dev/null
@@ -0,0 +1,45 @@
+package eu.etaxonomy.taxeditor.editor.view.derivate.handler;
+
+import java.util.Collections;
+import java.util.UUID;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.ui.PartInitException;
+
+import eu.etaxonomy.cdm.api.service.IDescriptionService;
+import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
+import eu.etaxonomy.cdm.model.description.IndividualsAssociation;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
+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 OpenDerivativeEditorForDescriptionElement extends DefaultOpenHandlerBase<IndividualsAssociation> {
+
+    @Override
+    protected IndividualsAssociation getEntity(UUID uuid) {
+        DescriptionElementBase descriptionElement = CdmStore.getService(IDescriptionService.class).loadDescriptionElement(uuid, null);
+        if(descriptionElement.isInstanceOf(IndividualsAssociation.class)){
+            return (IndividualsAssociation) descriptionElement;
+        }
+        return null;
+    }
+
+    @Override
+    protected void open(ExecutionEvent event, IndividualsAssociation entity) {
+        SpecimenOrObservationBase associatedSpecimenOrObservation = entity.getAssociatedSpecimenOrObservation();
+        if(associatedSpecimenOrObservation!=null){
+            UUID specimenUuid = associatedSpecimenOrObservation.getUuid();
+            try {
+                EditorUtil.open(new DerivateViewEditorInput(Collections.singletonList(specimenUuid)));
+            } catch (PartInitException e) {
+                MessagingUtils.error(OpenDerivateViewHandler.class, "Derivative Editor could not be opened", e);
+            }
+        }
+
+    }
+
+}