commit 9fcf05745e745c91676dbe6a6d9efba3465cef0f
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Thu Mar 9 18:30:01 2017 +0100

    ref #5923 "Open in.." menu restructuring for conecpt view
    
     - added "Open in" option for bulk editor and name editor coming from
    each of those

diff --git a/eu.etaxonomy.taxeditor.editor/plugin.xml b/eu.etaxonomy.taxeditor.editor/plugin.xml
index 5b32eb4b3..df790ac8b 100644
--- a/eu.etaxonomy.taxeditor.editor/plugin.xml
+++ b/eu.etaxonomy.taxeditor.editor/plugin.xml
@@ -1080,11 +1080,10 @@
                   id="eu.etaxonomy.taxeditor.editor.view.concept.menus.new">
             </dynamic>
          </menu>
-         <command
-               commandId="eu.etaxonomy.taxeditor.editor.view.concept.command.open"
-               label="%command.label.43"
-               style="push">
-         </command>
+         <dynamic
+               class="eu.etaxonomy.taxeditor.view.CdmViewerContextMenu"
+               id="eu.etaxonomy.taxeditor.view.context.CdmViewerContextMenu">
+         </dynamic>
          <separator
                name="eu.etaxonomy.taxeditor.editor.view.concept.menu.separator1"
                visible="true">
@@ -1142,7 +1141,6 @@
          </toolbar>
       </menuContribution>
       <menuContribution
-            allPopups="false"
             locationURI="menu:bulkeditor.menus.openmenu">
          <command
                commandId="eu.etaxonomy.taxeditor.editor.openSpecimenEditorFromMenu"
@@ -1770,6 +1768,11 @@
             id="eu.etaxonomy.taxeditor.openSpecimenEditorForTypeSpecimen"
             name="%command.name.OPEN_EDITOR_FOR_TYPE_SPECIMEN">
       </command>
+      <command
+            defaultHandler="eu.etaxonomy.taxeditor.editor.view.concept.handler.OpenRelatedConceptInBulkEditorHandler"
+            id="eu.etaxonomy.taxeditor.editor.openBulkEditorForTaxonRelationship"
+            name="Open bulk editor for taxon relationship">
+      </command>
         
    </extension>
    <extension
@@ -2106,5 +2109,15 @@
             selection="eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation"
             viewerName="%viewCommandMapping.viewerName.SPECIMEN_EDITOR">
       </viewCommandMapping>
+      <viewCommandMapping
+            commandId="eu.etaxonomy.taxeditor.editor.view.concept.command.open"
+            selection="eu.etaxonomy.cdm.model.taxon.TaxonRelationship"
+            viewerName="Name Editor">
+      </viewCommandMapping>
+      <viewCommandMapping
+            commandId="eu.etaxonomy.taxeditor.editor.openBulkEditorForTaxonRelationship"
+            selection="eu.etaxonomy.cdm.model.taxon.TaxonRelationship"
+            viewerName="Bulk Editor">
+      </viewCommandMapping>
     </extension>
 </plugin>
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/OpenRelatedConceptHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/OpenRelatedConceptHandler.java
index cd7b8a679..186b25bf6 100644
--- a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/OpenRelatedConceptHandler.java
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/OpenRelatedConceptHandler.java
@@ -1,29 +1,32 @@
 /**
 * Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy 
+* 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.editor.view.concept.handler;
 
-import java.util.Iterator;
-
 import org.eclipse.core.commands.AbstractHandler;
 import org.eclipse.core.commands.ExecutionEvent;
 import org.eclipse.core.commands.ExecutionException;
 import org.eclipse.jface.viewers.ISelection;
 import org.eclipse.jface.viewers.IStructuredSelection;
+import org.eclipse.ui.IEditorPart;
 import org.eclipse.ui.PartInitException;
 import org.eclipse.ui.handlers.HandlerUtil;
 
 import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
+import eu.etaxonomy.taxeditor.bulkeditor.BulkEditor;
 import eu.etaxonomy.taxeditor.editor.EditorUtil;
 import eu.etaxonomy.taxeditor.editor.MultiPageTaxonEditor;
 import eu.etaxonomy.taxeditor.editor.l10n.Messages;
+import eu.etaxonomy.taxeditor.model.AbstractUtility;
+import eu.etaxonomy.taxeditor.model.LineSelection;
 import eu.etaxonomy.taxeditor.model.MessagingUtils;
 
 /**
@@ -33,38 +36,55 @@ import eu.etaxonomy.taxeditor.model.MessagingUtils;
  */
 public class OpenRelatedConceptHandler extends AbstractHandler {
 
-	/* (non-Javadoc)
-	 * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
-	 */
 	@Override
 	public Object execute(ExecutionEvent event) throws ExecutionException {
-		MultiPageTaxonEditor editor = EditorUtil.getActiveMultiPageTaxonEditor();
-		
 		ISelection selection = HandlerUtil.getCurrentSelection(event);
-		
-		if(selection instanceof IStructuredSelection){
-			IStructuredSelection structuredSelection = (IStructuredSelection) selection;
-			Iterator iterator = structuredSelection.iterator();
-			
-			while (iterator.hasNext()){
-				Object element = iterator.next();
-				if(element instanceof TaxonRelationship){
-					Taxon relatedTaxon = getRelatedTaxon((TaxonRelationship) element, editor.getTaxon());
-					
-					try {
-						EditorUtil.openTaxonBase(relatedTaxon.getUuid());
-					} catch (PartInitException e) {
-						MessagingUtils.messageDialog(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN, getClass(), 
-								String.format(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN_MESSAGE ,relatedTaxon), e);
-					}
-				}
-			}
+        TaxonBase<?> relatedTaxon = null;
+
+        if(selection instanceof IStructuredSelection){
+            IStructuredSelection structuredSelection = (IStructuredSelection) selection;
+            Object selectedElement = structuredSelection.getFirstElement();
+
+            if(selectedElement instanceof TaxonRelationship){
+                IEditorPart activeEditor = AbstractUtility.getActiveEditor();
+                if(activeEditor instanceof MultiPageTaxonEditor){
+                    relatedTaxon = getRelatedTaxon((TaxonRelationship) selectedElement, ((MultiPageTaxonEditor) activeEditor).getTaxon());
+                }
+                else if(activeEditor instanceof BulkEditor){
+                    ISelection bulkSelection = ((BulkEditor)activeEditor).getSelectionProvider().getSelection();
+                    if(bulkSelection instanceof LineSelection){
+                        Object firstElement = ((LineSelection)bulkSelection).getFirstElement();
+                        if(firstElement instanceof Taxon){
+                            relatedTaxon = getRelatedTaxon((TaxonRelationship) selectedElement, (Taxon) firstElement);
+                        }
+                    }
+                }
+            }
+        }
+
+		if(relatedTaxon==null){
+		    MessagingUtils.messageDialog(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN, getClass(),
+		            String.format(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN_MESSAGE ,relatedTaxon), null);
 		}
-		
+		else{
+		    openConcept(relatedTaxon);
+		}
+
 		return null;
 	}
 
-	
+    /**
+     * @param relatedTaxon
+     */
+    protected void openConcept(TaxonBase<?> relatedTaxon) {
+        try {
+            EditorUtil.openTaxonBase(relatedTaxon.getUuid());
+        } catch (PartInitException e) {
+            MessagingUtils.messageDialog(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN, getClass(),
+                    String.format(Messages.OpenRelatedConceptHandler_COULD_NOT_OPEN_MESSAGE ,relatedTaxon), e);
+        }
+    }
+
 	private Taxon getRelatedTaxon(TaxonRelationship relationship, Taxon taxon){
 		if (relationship.getFromTaxon().equals(taxon)){
 			return relationship.getToTaxon();
diff --git a/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/OpenRelatedConceptInBulkEditorHandler.java b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/OpenRelatedConceptInBulkEditorHandler.java
new file mode 100644
index 000000000..1b3e6c1e2
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.editor/src/main/java/eu/etaxonomy/taxeditor/editor/view/concept/handler/OpenRelatedConceptInBulkEditorHandler.java
@@ -0,0 +1,21 @@
+package eu.etaxonomy.taxeditor.editor.view.concept.handler;
+
+import org.eclipse.ui.PartInitException;
+
+import eu.etaxonomy.cdm.model.taxon.TaxonBase;
+import eu.etaxonomy.taxeditor.bulkeditor.BulkEditorUtil;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+
+public class OpenRelatedConceptInBulkEditorHandler extends OpenRelatedConceptHandler{
+    /**
+     * {@inheritDoc}
+     */
+    @Override
+    protected void openConcept(TaxonBase<?> relatedTaxon) {
+        try {
+            BulkEditorUtil.openEditor(relatedTaxon);
+        } catch (PartInitException e) {
+            MessagingUtils.error(this.getClass(), "Bulk Editor could not be opened for "+relatedTaxon, e);
+        }
+    }
+}
