commit 9f40979f5e0d2fc55100acc5a7fabac00d48ce12
Author: Katja Luther <k.luther@bgbm.org>
Date:   Tue Mar 12 09:30:00 2019 +0100

    fix #8136: update type section when changing type to or from lectotype

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/AbstractTypeDesignationElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/AbstractTypeDesignationElement.java
index dbc7738f9..6b829d3bc 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/AbstractTypeDesignationElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/AbstractTypeDesignationElement.java
@@ -9,15 +9,20 @@
 
 package eu.etaxonomy.taxeditor.ui.section.name;
 
+import java.util.Iterator;
+
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionListener;
 
 import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
 import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
+import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractSourcedEntityBaseElement;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
@@ -62,13 +67,74 @@ public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBa
 	@Override
 	public void setEntity(T entity){
 	    super.setEntity(entity);
+
 	    if (this.entity != null && this.entity.isLectoType()){
-            selection_reference = formFactory
-                    .createSelectionElement(Reference.class, formElement, "Reference",
-                            null, EntitySelectionElement.ALL, SWT.NULL);
-            text_referenceDetail = formFactory.createTextWithLabelElement(
-                formElement, "Reference Detail", null, SWT.NULL);
+	        if (selection_reference == null){
+    	        selection_reference = formFactory
+                        .createSelectionElement(Reference.class, formElement, "Reference",
+                                null, EntitySelectionElement.ALL, SWT.NULL);
+
+                text_referenceDetail = formFactory.createTextWithLabelElement(
+                    formElement, "Reference Detail", null, SWT.NULL);
+	        }
+        }else{
+            if (selection_reference != null){
+                removeReferenceControls();
+            }
         }
+        StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
+
 	}
 
+	/**
+     * Updates all widgets to display the latest data
+     */
+    protected void updateContent() {
+      // if (this.getParentElement() instanceof NameDetailSection
+
+    }
+
+
+    public void removeReferenceControls(){
+        for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
+            ICdmFormElement childElement = iterator.next();
+            // recursion
+           if (childElement instanceof EntitySelectionElement && ((EntitySelectionElement)childElement).equals(selection_reference)) {
+                childElement.removeElements();
+
+                // unregister selection arbitrator
+                if(childElement instanceof ISelectableElement){
+                    SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
+                    if(selectionArbitrator != null){
+                        formFactory.destroySelectionArbitrator(selectionArbitrator);
+                    }
+                }
+
+                // unregister from property changes
+                formFactory.removePropertyChangeListener(childElement);
+                selection_reference = null;
+           }
+          if (childElement instanceof TextWithLabelElement && ((TextWithLabelElement)childElement).equals(text_referenceDetail)) {
+
+                  childElement.removeElements();
+
+                  // unregister selection arbitrator
+                  if(childElement instanceof ISelectableElement){
+                      SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
+                      if(selectionArbitrator != null){
+                          formFactory.destroySelectionArbitrator(selectionArbitrator);
+                      }
+                  }
+
+                  // unregister from property changes
+                  formFactory.removePropertyChangeListener(childElement);
+                  text_referenceDetail = null;
+
+
+          }
+        }
+
+    }
+
+
 }
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameTypeDesignationElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameTypeDesignationElement.java
index 90b172951..af1eafb06 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameTypeDesignationElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/NameTypeDesignationElement.java
@@ -12,10 +12,10 @@ package eu.etaxonomy.taxeditor.ui.section.name;
 import org.eclipse.swt.events.SelectionListener;
 
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.term.TermType;
 import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
 import eu.etaxonomy.cdm.model.name.NameTypeDesignationStatus;
 import eu.etaxonomy.cdm.model.name.TaxonName;
+import eu.etaxonomy.cdm.model.term.TermType;
 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
@@ -86,7 +86,7 @@ public class NameTypeDesignationElement extends
 			getEntity().setTypeName(selection_typeName.getEntity());
 		} else if (eventSource == combo_typeStatus) {
 			getEntity().setTypeStatus(combo_typeStatus.getSelection());
-
+			setEntity(entity);
 		} else if (eventSource == checkbox_notDesignated) {
 			getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
 		}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/SpecimenTypeDesignationElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/SpecimenTypeDesignationElement.java
index 34b3acf71..f88f72f52 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/SpecimenTypeDesignationElement.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/SpecimenTypeDesignationElement.java
@@ -13,15 +13,14 @@ import org.eclipse.swt.events.SelectionListener;
 
 import eu.etaxonomy.cdm.api.service.name.TypeDesignationStatusComparator;
 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
-import eu.etaxonomy.cdm.model.term.TermType;
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
 import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
+import eu.etaxonomy.cdm.model.term.TermType;
 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
-import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
@@ -79,9 +78,7 @@ public class SpecimenTypeDesignationElement extends
 	public void handleEvent(Object eventSource) {
 		if (eventSource == combo_typeStatus) {
 			getEntity().setTypeStatus(combo_typeStatus.getSelection());
-
-			firePropertyChangeEvent(new CdmPropertyChangeEvent(this, null));
-
+			setEntity(entity);
 		}
 		// TODO remove this once specimens are correctly implemented
 		else if (eventSource == text_specimenTypeText) {
