ref #8136: move not designated checkbox
authorKatja Luther <k.luther@bgbm.org>
Thu, 11 Apr 2019 08:09:53 +0000 (10:09 +0200)
committerKatja Luther <k.luther@bgbm.org>
Thu, 11 Apr 2019 08:09:53 +0000 (10:09 +0200)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CheckboxElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/name/AbstractTypeDesignationElement.java

index 09e7948..e1f2ea1 100644 (file)
@@ -131,7 +131,10 @@ public class CheckboxElement extends AbstractCdmFormElement implements Selection
        /** {@inheritDoc} */
        @Override
        public void setBackground(Color color) {
-               checkbox.setBackground(color);
+           if (checkbox.isDisposed()){
+               return;
+           }
+           checkbox.setBackground(color);
                if (label != null) {
             label.setBackground(color);
         }
index eb1c0df..3346742 100644 (file)
@@ -70,12 +70,14 @@ public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBa
 
            if (this.entity != null && this.entity.isLectoType()){
                if (selection_reference == null){
+                   removeNotDesignatedControls();
                selection_reference = formFactory
                         .createSelectionElement(Reference.class, formElement, "Status Reference",
                                 entity.getCitation(), EntitySelectionElement.ALL, SWT.NULL);
 
                 text_referenceDetail = formFactory.createTextWithLabelElement(
                     formElement, "Status Reference Detail", entity.getCitationMicroReference(), SWT.NULL);
+                checkbox_notDesignated = formFactory.createCheckbox(formElement, "Not Designated", entity.isNotDesignated(), SWT.NONE);
                }
         }else{
             if (selection_reference != null){
@@ -140,6 +142,30 @@ public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBa
         }
 
     }
+
+    public void removeNotDesignatedControls(){
+        for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
+            ICdmFormElement childElement = iterator.next();
+            // recursion
+           if (childElement instanceof CheckboxElement && ((CheckboxElement)childElement).equals(this.checkbox_notDesignated)) {
+                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);
+                checkbox_notDesignated = null;
+           }
+
+        }
+
+    }
     @Override
     public void handleEvent(Object eventSource) {
         if (eventSource == selection_reference) {
@@ -150,6 +176,9 @@ public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBa
             getEntity().setCitationMicroReference(text_referenceDetail.getText());
             setEntity(entity);
         }
+        if (eventSource == checkbox_notDesignated) {
+            getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
+        }
     }
 
 }