commit c2b6c2d3bc10ea16d9087a50b8449aa76b55706f
Author: Katja Luther <k.luther@bgbm.org>
Date:   Fri Aug 18 14:26:19 2017 +0200

    fix details view for misapplied names and add choosable taxon for misapplied name relationsip

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonRelationshipDetailSection.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonRelationshipDetailSection.java
index 760fc6a06..ca27ca98c 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonRelationshipDetailSection.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonRelationshipDetailSection.java
@@ -9,7 +9,12 @@
 package eu.etaxonomy.taxeditor.ui.section.taxon;
 
 import org.apache.commons.lang.StringUtils;
+import org.eclipse.jface.action.Action;
+import org.eclipse.jface.action.IAction;
+import org.eclipse.jface.action.ToolBarManager;
 import org.eclipse.jface.viewers.ISelectionProvider;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.widgets.Control;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
@@ -17,11 +22,15 @@ import eu.etaxonomy.cdm.model.name.TaxonName;
 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.model.ImageResources;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.NameSelectionDialog;
+import eu.etaxonomy.taxeditor.ui.dialog.selection.TaxonBaseSelectionDialog;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.name.NonViralNameDetailSection;
 
 /**
  * @author n.hoffmann
@@ -31,11 +40,13 @@ import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
 public class TaxonRelationshipDetailSection extends AbstractCdmDetailSection<TaxonRelationship> implements ITaxonBaseDetailSection {
 	Taxon taxon;
 	TaxonName name;
+	boolean taxonChoosable = false;
 
 	public TaxonRelationshipDetailSection(CdmFormFactory formFactory,
 			ConversationHolder conversation, ICdmFormElement parentElement,
-			ISelectionProvider selectionProvider, int style) {
+			ISelectionProvider selectionProvider, int style, boolean taxonChoosable) {
 		super(formFactory, conversation, parentElement,  selectionProvider, style);
+		this.taxonChoosable = taxonChoosable;
 	}
 
 	@Override
@@ -68,5 +79,35 @@ public class TaxonRelationshipDetailSection extends AbstractCdmDetailSection<Tax
 	private void setName(TaxonName name){
 		this.name = name;
 	}
+	
+	@Override
+	protected Control createToolbar() {
+	        ToolBarManager toolBarManager = new ToolBarManager(SWT.FLAT);
+
+	        if(taxonChoosable){
+	            //choose name
+	            Action chooseTaxonAction = new Action("Choose Taxon", IAction.AS_PUSH_BUTTON){
+	                @Override
+	                public void run() {
+	                    Taxon taxon = TaxonBaseSelectionDialog.selectTaxon(getShell(), getConversationHolder(), getEntity().getFromTaxon());
+	                    if(taxon!=null){
+                            taxon = HibernateProxyHelper.deproxy(taxon);
+                            name = taxon.getName();
+                            TaxonRelationship rel = getEntity();
+                            rel.setFromTaxon(taxon);
+                            setEntity(rel);
+                            //				        taxonBase.getTitleCache();
+                            
+                            firePropertyChangeEvent(TaxonRelationshipDetailSection.this);
+	                    }
+	                }
+	            };
+	            chooseTaxonAction.setToolTipText("Choose taxon for this Relationship");
+	            chooseTaxonAction.setImageDescriptor(ImageResources.getImageDescriptor(ImageResources.BROWSE_ICON));
+
+	            toolBarManager.add(chooseTaxonAction);
+	    }
+	        return toolBarManager.createControl(this);
+	}
 
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java
index f548d8e2a..17fcaea53 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/e4/AbstractCdmEditorPartE4.java
@@ -8,6 +8,8 @@
 */
 package eu.etaxonomy.taxeditor.view.e4;
 
+import java.util.Set;
+
 import javax.annotation.PreDestroy;
 
 import org.eclipse.e4.ui.di.PersistState;
@@ -19,8 +21,14 @@ import org.eclipse.ui.IEditorPart;
 
 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
 import eu.etaxonomy.cdm.api.conversation.IConversationEnabled;
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.CdmBase;
+import eu.etaxonomy.cdm.model.taxon.Taxon;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
 import eu.etaxonomy.cdm.persistence.hibernate.CdmDataChangeMap;
+import eu.etaxonomy.taxeditor.editor.ITaxonEditor;
+
 import eu.etaxonomy.taxeditor.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.IDirtyMarkable;
 import eu.etaxonomy.taxeditor.operation.IPostOperationEnabled;
@@ -60,7 +68,32 @@ public abstract class AbstractCdmEditorPartE4
         if(viewer!=null){
             Object element = selection.getFirstElement();
             if(selection.getFirstElement()!=null){
-                viewer.setInput(element);
+            	if (element instanceof Taxon){
+                	Taxon taxon = HibernateProxyHelper.deproxy(element, Taxon.class);
+                	if (taxon.isMisapplication()){
+                		Object part = createPartObject(activePart);
+                		 if(part instanceof ITaxonEditor){
+                			 Taxon accepted = ((ITaxonEditor) part).getTaxon();
+                        
+//                			Taxon accepted= ((ITaxonEditor)activePart).getTaxon();
+                			Set<TaxonRelationship> rels =  taxon.getTaxonRelations(accepted);
+
+                			 if (rels.iterator().hasNext()){
+                				 TaxonRelationship rel = rels.iterator().next();
+                				 if (rel.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
+        	        				 viewer.setInput(rel);
+        	        				 
+        	        				 return;
+                				 }
+                			 }
+                		}
+
+
+                	}
+                }
+            	viewer.setInput(element);
+               
+                
             }
             selectionProvidingPart = activePart;
         }
