Initialize TypeDesignationSection
authorPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 2 Nov 2015 17:10:39 +0000 (18:10 +0100)
committerPatrick Plitzner <p.plitzner@bgbm.org>
Mon, 2 Nov 2015 17:10:39 +0000 (18:10 +0100)
eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/DerivedUnitTypeDesignationElement.java

index 9800e7df6a56caf3e3cb9db92222a011162d17e0..d9b695a58e318c32cb88c41e75fbf22d623f196a 100644 (file)
@@ -15,11 +15,11 @@ import java.util.Set;
 
 import org.eclipse.swt.events.SelectionListener;
 
+import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
 import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignationStatus;
 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
-import eu.etaxonomy.cdm.model.occurrence.DerivedUnit;
 import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
@@ -35,12 +35,13 @@ import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 public class DerivedUnitTypeDesignationElement extends AbstractTypeDesignationElement<SpecimenTypeDesignation> {
 
     private TermComboElement<SpecimenTypeDesignationStatus> combo_typeStatus;
-    private EntitySelectionElement<DerivedUnit> selection_typeSpecimen;
 
     private List<EntitySelectionElement<TaxonNameBase>> selectionTaxonNames;
     private ICdmFormElement parentFormElement;
     private int style;
 
+    private EntitySelectionElement<TaxonNameBase> selectionTaxonName;
+
     public DerivedUnitTypeDesignationElement(CdmFormFactory formFactory,
             AbstractFormSection section, SpecimenTypeDesignation entity,
             SelectionListener removeListener, int style) {
@@ -49,30 +50,27 @@ public class DerivedUnitTypeDesignationElement extends AbstractTypeDesignationEl
 
     @Override
     public void setEntity(SpecimenTypeDesignation entity) {
-        this.entity = entity;
+        super.setEntity(entity);
         Set<TaxonNameBase> typifiedNames = entity.getTypifiedNames();
-        if(typifiedNames.isEmpty()){
-            formFactory.createSelectionElement(
-                    TaxonNameBase.class, getConversationHolder(), parentFormElement, "Scientific Name", null,
-                    EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
+        if(typifiedNames.size()==1){
+            selectionTaxonName.setEntity(typifiedNames.iterator().next());
         }
-        else{
-            for (TaxonNameBase taxonNameBase : typifiedNames) {
-                EntitySelectionElement<TaxonNameBase> selectionElement = formFactory.createSelectionElement(
-                        TaxonNameBase.class, getConversationHolder(), parentFormElement, "Scientific Name", null,
-                        EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
-                selectionElement.setEntity(taxonNameBase);
-            }
+        else if(typifiedNames.size()>1){
+            formFactory.createLabel(getLayoutComposite(), "!!!!!!!!");
         }
 
-        checkbox_notDesignated = formFactory.createCheckbox(parentFormElement, "Not Designated", false, style);
+        SpecimenTypeDesignationStatus typeStatus = (SpecimenTypeDesignationStatus) HibernateProxyHelper
+                .deproxy(entity.getTypeStatus());
+        combo_typeStatus.setSelection(typeStatus);
+        checkbox_notDesignated.setSelection(entity.isNotDesignated());
+
+//        for (TaxonNameBase taxonNameBase : typifiedNames) {
+//            EntitySelectionElement<TaxonNameBase> selectionElement = formFactory.createSelectionElement(
+//                    TaxonNameBase.class, getConversationHolder(), parentFormElement, "Scientific Name", null,
+//                    EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
+//            selectionElement.setEntity(taxonNameBase);
+//        }
 
-        selection_typeSpecimen = formFactory
-                .createSelectionElement(DerivedUnit.class,
-                        getConversationHolder(), parentFormElement, "Specimen", null,
-                        EntitySelectionElement.ALL, style);
-        combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.SpecimenTypeDesignationStatus,
-                        parentFormElement, "Designation Status", null, style);
 
     }
 
@@ -81,21 +79,31 @@ public class DerivedUnitTypeDesignationElement extends AbstractTypeDesignationEl
     public void createControls(ICdmFormElement element, int style) {
         this.parentFormElement = element;
         this.style = style;
+
+        selectionTaxonName = formFactory.createSelectionElement(
+                TaxonNameBase.class, getConversationHolder(), parentFormElement, "Scientific Name", null,
+                EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
+
+        combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.SpecimenTypeDesignationStatus,
+                parentFormElement, "Designation Status", null, style);
+
         super.createControls(element, style);
     }
 
     /** {@inheritDoc} */
     @Override
     public void handleEvent(Object eventSource) {
-        if (selectionTaxonNames.contains(eventSource)) {
-            ((EntitySelectionElement<TaxonNameBase>) eventSource).getSelection().addTypeDesignation(getEntity(), false);
-        }
-        else if (eventSource == combo_typeStatus) {
+        if (eventSource == selectionTaxonName) {
+            selectionTaxonName.getSelection().addTypeDesignation(getEntity(), false);
+        } else if (eventSource == combo_typeStatus) {
             getEntity().setTypeStatus(combo_typeStatus.getSelection());
-        } else if (eventSource == selection_typeSpecimen) {
-            getEntity().setTypeSpecimen(selection_typeSpecimen.getSelection());
-        }  else if (eventSource == checkbox_notDesignated) {
+        } else if (eventSource == checkbox_notDesignated) {
             getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
+        } else if (eventSource == selection_reference) {
+            getEntity().setCitation(selection_reference.getSelection());
+        } else if (eventSource == text_referenceDetail) {
+            getEntity().setCitationMicroReference(
+                    text_referenceDetail.getText());
         }
     }