commit aa744c3bd8fe6843a6b5e2deffa8ddca6797e70a
Author: Katja Luther <k.luther@bgbm.org>
Date:   Thu Jul 13 11:02:33 2017 +0200

    add distinction between misapplied name and other concept relationships

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonRelationshipDetailElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonRelationshipDetailElement.java
index 479fc85f7..1b4220b9e 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonRelationshipDetailElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/taxon/TaxonRelationshipDetailElement.java
@@ -19,6 +19,7 @@ import eu.etaxonomy.cdm.model.taxon.Synonym;
 import eu.etaxonomy.cdm.model.taxon.SynonymType;
 import eu.etaxonomy.cdm.model.taxon.Taxon;
 import eu.etaxonomy.cdm.model.taxon.TaxonRelationship;
+import eu.etaxonomy.cdm.model.taxon.TaxonRelationshipType;
 import eu.etaxonomy.taxeditor.model.TaxonRelationshipTypeInverseContainer;
 import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
@@ -40,9 +41,10 @@ import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
  */
 public class TaxonRelationshipDetailElement extends AbstractCdmDetailElement<TaxonRelationship> {
 
-//	private TermComboElement<TaxonRelationshipTypeInverseContainer> combo_taxonRelationshipType;
-//	
-//	private EntitySelectionElement<Taxon> selection_relatedTaxon;
+	private TermComboElement<TaxonRelationshipTypeInverseContainer> combo_taxonRelationshipType;
+	
+	private EntitySelectionElement<Taxon> selection_relatedTaxon;
+	private CheckboxElement checkBoxDoubtful;
 	 protected ToggleableTextElement toggleable_cache;
 	private  EntitySelectionElement<Reference> secReference;
 	private  EntitySelectionElement<Reference> sensuReference;
@@ -69,54 +71,57 @@ public class TaxonRelationshipDetailElement extends AbstractCdmDetailElement<Tax
 	@Override
 	protected void createControls(ICdmFormElement formElement,
 			TaxonRelationship entity, int style) {
-//		combo_taxonRelationshipType = formFactory.createTermComboElement(
-//				TaxonRelationshipTypeInverseContainer.class, 
-//				formElement, "Relationship Type", 
-//				getTaxonRelationshipTypeInverseContainer(), style);
-//		combo_taxonRelationshipType.setEnabled(false);
-//		selection_relatedTaxon = formFactory.createSelectionElement(
-//				Taxon.class, getConversationHolder(), 
-//				formElement, "Related Taxon", getRelatedTaxon(), 
-//				EntitySelectionElement.SELECTABLE, style);
-		taxon = entity.getFromTaxon();
-		toggleable_cache = formFactory.createToggleableTextField(formElement,
-				"Title Cache", taxon.getTitleCache(),
-				taxon.isProtectedTitleCache(), style);
-
-		text_appendedPhrase = formFactory.createTextWithLabelElement(
-				formElement, "Appended Phrase", taxon.getAppendedPhrase(),
-				SWT.WRAP);
-
-
-		sensuReference = formFactory.createSelectionElement(Reference.class,
-			getConversationHolder(), formElement, "Sensu",
-			taxon.getSec(), EntitySelectionElement.ALL,
-			style);
-
-		text_sensu_microreference = formFactory.createTextWithLabelElement(
-				formElement, "Detail",
-				taxon.getSecMicroReference(),null,
-				SWT.WRAP);
-
-		
+		if (!entity.getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
+			combo_taxonRelationshipType = formFactory.createTermComboElement(
+					TaxonRelationshipTypeInverseContainer.class, 
+					formElement, "Relationship Type", 
+					getTaxonRelationshipTypeInverseContainer(), style);
+			combo_taxonRelationshipType.setEnabled(false);
+			selection_relatedTaxon = formFactory.createSelectionElement(
+					Taxon.class, getConversationHolder(), 
+					formElement, "Related Taxon", getRelatedTaxon(), 
+					EntitySelectionElement.SELECTABLE, style);
+			checkBoxDoubtful = formFactory.createCheckbox(formElement, "Relation is doubtful", entity.isDoubtful(), style);
+		}else{
+			taxon = entity.getFromTaxon();
+			toggleable_cache = formFactory.createToggleableTextField(formElement,
+					"Title Cache", taxon.getTitleCache(),
+					taxon.isProtectedTitleCache(), style);
 	
+			text_appendedPhrase = formFactory.createTextWithLabelElement(
+					formElement, "Appended Phrase", taxon.getAppendedPhrase(),
+					SWT.WRAP);
 	
-		checkbox_published = formFactory.createCheckbox(formElement,
-					"Published", taxon.isPublish(), style);
-			
-			
-		secReference = formFactory.createSelectionElement(Reference.class,
-				getConversationHolder(), formElement, "Misappl. Sec.",
-				entity.getCitation(), EntitySelectionElement.ALL,
+	
+			sensuReference = formFactory.createSelectionElement(Reference.class,
+				getConversationHolder(), formElement, "Sensu",
+				taxon.getSec(), EntitySelectionElement.ALL,
 				style);
 	
-		text_secundum_microreference = formFactory.createTextWithLabelElement(
-	            formElement, "Detail",
-	            entity.getCitationMicroReference(),null,
-	            SWT.WRAP);
-		checkbox_doubtful = formFactory.createCheckbox(formElement,
-				"Misappl. Doubtful", entity.isDoubtful(), style);
-
+			text_sensu_microreference = formFactory.createTextWithLabelElement(
+					formElement, "Detail",
+					taxon.getSecMicroReference(),null,
+					SWT.WRAP);
+	
+			
+		
+		
+			checkbox_published = formFactory.createCheckbox(formElement,
+						"Published", taxon.isPublish(), style);
+				
+				
+			secReference = formFactory.createSelectionElement(Reference.class,
+					getConversationHolder(), formElement, "Misappl. Sec.",
+					entity.getCitation(), EntitySelectionElement.ALL,
+					style);
+		
+			text_secundum_microreference = formFactory.createTextWithLabelElement(
+		            formElement, "Detail",
+		            entity.getCitationMicroReference(),null,
+		            SWT.WRAP);
+			checkbox_doubtful = formFactory.createCheckbox(formElement,
+					"Misappl. Doubtful", entity.isDoubtful(), style);
+		}
 		
 	}
 	
@@ -135,23 +140,38 @@ public class TaxonRelationshipDetailElement extends AbstractCdmDetailElement<Tax
 
 	@Override
 	public void handleEvent(Object eventSource) {
-		if (eventSource== toggleable_cache) {
-		handleToggleableCacheField();
-	} else if (eventSource == checkbox_doubtful) {
-		taxon.setDoubtful(checkbox_doubtful.getSelection());
-	}  else if (eventSource == secReference) {
-		getEntity().setCitation(secReference.getSelection());
-	} else if (eventSource == text_appendedPhrase) {
-		taxon.setAppendedPhrase(text_appendedPhrase.getText());
-	} else if (eventSource == text_secundum_microreference) {
-		getEntity().setCitationMicroReference(text_secundum_microreference.getText());
-	} else if (eventSource == checkbox_published) {
-	    taxon.setPublish(checkbox_published.getSelection());
-	} else if (eventSource == text_sensu_microreference) {
-        taxon.setSecMicroReference(text_sensu_microreference.getText());
-	}else if (eventSource == sensuReference) {
-		taxon.setSec(sensuReference.getSelection());
-	}
+		if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
+			if (eventSource== toggleable_cache) {
+				handleToggleableCacheField();
+			} else if (eventSource == checkbox_doubtful) {
+				taxon.setDoubtful(checkbox_doubtful.getSelection());
+			}  else if (eventSource == secReference) {
+				getEntity().setCitation(secReference.getSelection());
+			} else if (eventSource == text_appendedPhrase) {
+				taxon.setAppendedPhrase(text_appendedPhrase.getText());
+			} else if (eventSource == text_secundum_microreference) {
+				getEntity().setCitationMicroReference(text_secundum_microreference.getText());
+			} else if (eventSource == checkbox_published) {
+			    taxon.setPublish(checkbox_published.getSelection());
+			} else if (eventSource == text_sensu_microreference) {
+		        taxon.setSecMicroReference(text_sensu_microreference.getText());
+			}else if (eventSource == sensuReference) {
+				taxon.setSec(sensuReference.getSelection());
+			}
+		}else{
+			if (eventSource == selection_relatedTaxon){
+				boolean inverse = getTaxonRelationshipTypeInverseContainer().isInverse();
+				Taxon relatedTaxon = selection_relatedTaxon.getEntity();
+				if(inverse){
+					getEntity().setFromTaxon(relatedTaxon);
+				}else{
+					getEntity().setToTaxon(relatedTaxon);
+				}
+			}else if(eventSource==checkBoxDoubtful){
+			    getEntity().setDoubtful(checkBoxDoubtful.getSelection());
+			}
+		}	
+		firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
 	}
 	
 	protected void handleToggleableCacheField() {
@@ -163,19 +183,24 @@ public class TaxonRelationshipDetailElement extends AbstractCdmDetailElement<Tax
     }
 	
 	 public void updateToggleableCacheField() {
+		 if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
 	        if (toggleable_cache != null){
 	            if (!taxon.isProtectedTitleCache()) {
 	                toggleable_cache.setText(taxon.generateTitle());
 	            }
 	        }
+		 }
 	    }
 	 
 	 @Override
 		protected void updateContent() {
-			super.updateContent();
+		 super.updateContent();
+		 if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
+			
 			toggleable_cache.setEnabled(taxon.isProtectedTitleCache());
 			setIrrelevant(toggleable_cache.getState(),
 					Arrays.asList(new Object[] { toggleable_cache, checkbox_published}));
+		 }
 		}
 	 @Override
 	    protected void updateControlStates() {
@@ -183,11 +208,13 @@ public class TaxonRelationshipDetailElement extends AbstractCdmDetailElement<Tax
 	       
 	    }
 	 @Override
-		protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
+	 protected void handleTitleCacheRelevantChange(PropertyChangeEvent event) {
+		 if (getEntity().getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())){
 			String title = taxon.generateTitle();
 			taxon.setTitleCache(title);
 			super.handleTitleCacheRelevantChange(event);
-		}
+		 }
+	 }
 	 
 	@Override
 	public void refresh(){
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 f6a9b5b37..760fc6a06 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
@@ -35,7 +35,7 @@ public class TaxonRelationshipDetailSection extends AbstractCdmDetailSection<Tax
 	public TaxonRelationshipDetailSection(CdmFormFactory formFactory,
 			ConversationHolder conversation, ICdmFormElement parentElement,
 			ISelectionProvider selectionProvider, int style) {
-		super(formFactory, conversation, parentElement, selectionProvider, style);
+		super(formFactory, conversation, parentElement,  selectionProvider, style);
 	}
 
 	@Override
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java
index 25fee3aef..c2182cfb4 100755
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java
@@ -46,6 +46,7 @@ import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
 import eu.etaxonomy.cdm.model.reference.Reference;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
 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.model.AbstractUtility;
 import eu.etaxonomy.taxeditor.model.FeatureNodeContainer;
@@ -66,6 +67,7 @@ import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementDetailSec
 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementMediaSection;
 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionElementSourceSection;
 import eu.etaxonomy.taxeditor.ui.section.description.DescriptionSourceSection;
+import eu.etaxonomy.taxeditor.ui.section.description.IntextReferenceSection;
 import eu.etaxonomy.taxeditor.ui.section.description.MediaDetailsSection;
 import eu.etaxonomy.taxeditor.ui.section.description.NaturalLanguageSection;
 import eu.etaxonomy.taxeditor.ui.section.description.ScopeSection;
@@ -140,6 +142,7 @@ public class DetailsViewer extends AbstractCdmDataViewer {
 
     @Override
     public void setInput(Object input) {
+    	
         if(input instanceof TreeNode){
             input = ((TreeNode) input).getValue();
         }
@@ -187,6 +190,7 @@ public class DetailsViewer extends AbstractCdmDataViewer {
         // Too much type checking to decide which detail view to display.
         // Need to build in a mechanism where navigators / editors are 'aware'
         // of the corresponding detail viewer.
+    	
         Object input = getInput();
 
         destroySections();
@@ -307,7 +311,9 @@ public class DetailsViewer extends AbstractCdmDataViewer {
             createUserSection(rootElement);
         } else if (input instanceof Group) {
             createGroupSection(rootElement);
-        } else if (input instanceof TaxonRelationship) {
+        } else if (input instanceof TaxonRelationship && ((TaxonRelationship)input).getType().equals(TaxonRelationshipType.MISAPPLIED_NAME_FOR())) {
+            createMisappliedNameSection(rootElement);
+        }else if (input instanceof TaxonRelationship ) {
             createTaxonRelationshipSection(rootElement);
         } else if (input instanceof TermVocabulary) {
             createTermVocabularySection(rootElement);
@@ -318,6 +324,7 @@ public class DetailsViewer extends AbstractCdmDataViewer {
             createEmptySection(rootElement);
         }
         layout();
+       
     }
 
 
@@ -350,11 +357,14 @@ public class DetailsViewer extends AbstractCdmDataViewer {
     /** {@inheritDoc} */
     @Override
     public void setSelection(ISelection selection, boolean reveal) {
-        this.selection = selection;
-        if(this.selection!=null){
-            SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(this, selection);
-            fireSelectionChanged(selectionChangedEvent);
-        }
+    	
+    		this.selection = selection;
+	      
+	        if(this.selection!=null){
+	            SelectionChangedEvent selectionChangedEvent = new SelectionChangedEvent(this, selection);
+	            fireSelectionChanged(selectionChangedEvent);
+	        }
+    	
     }
 
     private void createTaxonSections(RootElement parent) {
@@ -485,7 +495,9 @@ public class DetailsViewer extends AbstractCdmDataViewer {
         destroySections();
 
         DescriptionElementDetailSection descriptionElementDetailSection = formFactory.createDescriptionElementDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
-
+        
+      //  IntextReferenceSection intextReferenceSection = formFactory.createIntextReferenceSection(getConversationHolder(), parent,  ExpandableComposite.TWISTIE);
+        
         formFactory.createHorizontalSeparator(parent, SWT.BORDER);
 
         DescriptionElementSourceSection descriptionElementSourceSection = formFactory.createDescriptionElementSourceSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
@@ -766,14 +778,15 @@ public class DetailsViewer extends AbstractCdmDataViewer {
         addPart(groupByUserDetailSection);
     }
 
-    private void createTaxonRelationshipSection(RootElement parent) {
+    private void createMisappliedNameSection(RootElement parent) {
         destroySections();
 
         TaxonRelationshipDetailSection taxonRelationshipDetailSection = formFactory.createTaxonRelationshipDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
 
        // ReferencedEntityDetailSection referencedEntityBaseDetailSection = formFactory.createReferencedEntityDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
         addPart(taxonRelationshipDetailSection);
-     //   addPart(referencedEntityBaseDetailSection);
+        //addPart(referencedEntityBaseDetailSection);
+       
         NonViralNameDetailSection nonViralNameSection = formFactory
                 .createNonViralNameDetailSection(getConversationHolder(), parent, this, true,
                         ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
@@ -814,6 +827,15 @@ public class DetailsViewer extends AbstractCdmDataViewer {
         //}
     }
 
+    private void createTaxonRelationshipSection(RootElement parent) {
+    	destroySections();
+
+    	TaxonRelationshipDetailSection taxonRelationshipDetailSection = formFactory.createTaxonRelationshipDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+
+        ReferencedEntityDetailSection referencedEntityBaseDetailSection = formFactory.createReferencedEntityDetailSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+        addPart(taxonRelationshipDetailSection);
+        addPart(referencedEntityBaseDetailSection);
+    }
     private void createTermVocabularySection(RootElement parent) {
         destroySections();
 
