ref #10202: disable specimen selection or reference selection if the other possibilit...
authorKatja Luther <k.luther@bgbm.org>
Tue, 20 Dec 2022 08:45:18 +0000 (09:45 +0100)
committerKatja Luther <k.luther@bgbm.org>
Tue, 20 Dec 2022 08:45:18 +0000 (09:45 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/description/DescriptionElementSourceElement.java
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/supplemental/AbstractOriginalSourceElement.java

index 49729085de8b10bc82ea4e5ad5ff7e30fa018da6..89909930c704dfc08775fa3a38de7c9f7a0a5e15 100644 (file)
@@ -8,8 +8,11 @@
  */
 package eu.etaxonomy.taxeditor.ui.section.description;
 
+import java.util.Iterator;
+
 import org.eclipse.swt.SWT;
 import org.eclipse.swt.events.SelectionListener;
+import org.eclipse.swt.widgets.Control;
 
 import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
@@ -21,8 +24,11 @@ import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
 import eu.etaxonomy.taxeditor.ui.element.IEntityElement;
+import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
 import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
+import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
 import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection;
+import eu.etaxonomy.taxeditor.ui.section.reference.OriginalSourceElement;
 import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractOriginalSourceElement;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 
@@ -35,7 +41,6 @@ public class DescriptionElementSourceElement extends
                IEntityElement<DescriptionElementSource>{
 
        private EntitySelectionElement<TaxonName> selection_name;
-       private EntitySelectionElement<SpecimenOrObservationBase> selection_specimen;
        boolean isEnabled = true;
 
        public DescriptionElementSourceElement(CdmFormFactory cdmFormFactory,
@@ -52,12 +57,7 @@ public class DescriptionElementSourceElement extends
                                .createSelectionElement(TaxonName.class,
                                        formElement, "Name in Source",
                                                null, EntitySelectionElement.ALL, SWT.NULL);
-               if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimenInFactSource.getKey())) {
-                       selection_specimen = formFactory
-                                       .createSelectionElement(SpecimenOrObservationBase.class,
-                                               formElement, "Specimen",
-                                                       null, EntitySelectionElement.ALL, SWT.NULL);
-               }
+               
                externalLinks = formFactory.createExternalLinksSection(formElement, StoreUtil.getSectionStyle(ExternalLinksSection.class, DescriptionElementSource.class.getCanonicalName()));
         externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
         if (getEntity() != null){
@@ -68,7 +68,7 @@ public class DescriptionElementSourceElement extends
        @Override
        public void setEntity(DescriptionElementSource entity) {
                super.setEntity(entity);
-               if (selection_reference != null){
+               if (selection_reference != null ){
                        if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSource.getKey())){
                            text_idInSource.setText(entity.getIdInSource());
                        }
@@ -80,9 +80,7 @@ public class DescriptionElementSourceElement extends
                        text_referenceDetail.setText(entity.getCitationMicroReference());
                        text_originalInfo.setText(entity.getOriginalInfo());
                        selection_name.setEntity(entity.getNameUsedInSource());
-                       if (selection_specimen != null) {
-                               selection_specimen.setEntity(entity.getSpecimen());
-                       }
+                       
                        combo_origsourcetype.setSelection(entity.getType());
                        externalLinks.setEntity(entity);
                }
@@ -96,9 +94,15 @@ public class DescriptionElementSourceElement extends
            super.handleEvent(eventSource);
         if (eventSource == selection_name) {
             getEntity().setNameUsedInSource(selection_name.getSelection());
+           
         }
         if (eventSource == selection_specimen) {
             getEntity().setSpecimen(selection_specimen.getSelection());
+            this.selection_reference.setEnabled(selection_specimen.getSelection() == null);
+        }
+        if (eventSource == selection_reference) {
+
+            this.selection_specimen.setEnabled(selection_reference.getSelection() == null);
         }
        }
 
@@ -107,4 +111,5 @@ public class DescriptionElementSourceElement extends
                super.setEnabled(enabled);
                externalLinks.setEnabled(isEnabled);
        }
+        
 }
\ No newline at end of file
index 1fd7c9d296495316d6a404574a56719b724015c8..77ee10e75ab7a26d68f3e0ee6bb6162c40e820a3 100644 (file)
@@ -16,7 +16,9 @@ import eu.etaxonomy.cdm.common.CdmUtils;
 import eu.etaxonomy.cdm.model.common.CdmBase;
 import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
 import eu.etaxonomy.cdm.model.common.TimePeriod;
+import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
 import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
+import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
 import eu.etaxonomy.cdm.model.reference.ICdmTarget;
 import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
 import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
@@ -45,6 +47,7 @@ public abstract class AbstractOriginalSourceElement<T extends OriginalSourceBase
 
     protected boolean isCommonNameReference = false;
     protected EntitySelectionElement<Reference> selection_reference;
+    protected EntitySelectionElement<SpecimenOrObservationBase> selection_specimen;
     protected TextWithLabelElement text_referenceDetail;
     protected TimePeriodElement accessed;
        protected EnumComboElement<OriginalSourceType> combo_origsourcetype;
@@ -108,7 +111,16 @@ public abstract class AbstractOriginalSourceElement<T extends OriginalSourceBase
           selection_reference = formFactory
                     .createCommonNameReferenceSelectionElement(formElement, "Reference",
                             null, EntitySelectionElement.ALL, style);
-        }else{
+        }else if (entity instanceof DescriptionElementSource && PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimenInFactSource.getKey())) {
+               selection_reference = formFactory
+                    .createSelectionElement(Reference.class,
+                             formElement, "Reference",
+                            null, EntitySelectionElement.ALL, style);
+               selection_specimen = formFactory
+                                       .createSelectionElement(SpecimenOrObservationBase.class,
+                                               formElement, "or Specimen",
+                                                       null, EntitySelectionElement.ALL, SWT.NULL);
+               }else{
            selection_reference = formFactory
                       .createSelectionElement(Reference.class,
                                formElement, "Reference",
@@ -147,6 +159,9 @@ public abstract class AbstractOriginalSourceElement<T extends OriginalSourceBase
 
                if (entity != null){
                        selection_reference.setEntity(entity.getCitation());
+                       if (selection_specimen != null && entity instanceof DescriptionElementSource) {
+                               selection_specimen.setEntity(((DescriptionElementSource)entity).getSpecimen());
+                       }
                text_referenceDetail.setText(entity.getCitationMicroReference());
                text_originalInfo.setText(entity.getOriginalInfo());