Merge branch 'release/5.11.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / AbstractTypeDesignationElement.java
index 5ce3fedff7cc4331e4a9f47b48c8545c7dece31d..bc5ad43946d5f745c1b54eab93209d61501f7699 100644 (file)
@@ -74,9 +74,9 @@ public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBa
        @Override
        public void setEntity(T entity){
            super.setEntity(entity);
-           sourceSection.setEntity(entity);
+           removeSourcesControls();
 
-           if (this.entity != null && this.entity.isLectoType()){
+           if (this.entity != null && this.entity.hasDesignationSource()){
                if (selection_reference == null){
                    removeNotDesignatedControls();
                selection_reference = formFactory
@@ -97,6 +97,9 @@ public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBa
                 }
             }
         }
+           sourceSection = formFactory.createSourceSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(SourceSection.class, IdentifiableSource.class.getCanonicalName()));
+        sourceSection.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
+        sourceSection.setEntity(entity);
         StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
 
        }
@@ -173,6 +176,34 @@ public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBa
 
         }
 
+    }
+
+    public void removeSourcesControls(){
+        for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
+            ICdmFormElement childElement = iterator.next();
+            // recursion
+           if (childElement instanceof SourceSection) {
+                childElement.removeElements();
+
+                getElements().remove(childElement);
+
+                // 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);
+                ((SourceSection)childElement).dispose();
+                sourceSection = null;
+                break;
+           }
+
+        }
+
     }
     @Override
     public void handleEvent(Object eventSource) {