Merge branch 'release/5.28.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / SpecimenTypeDesignationElement.java
index a7cc8010170345968144b529f846e4992353f915..dc0b93d52a5929713f57f6fad8955c62db4d7012 100644 (file)
@@ -1,4 +1,3 @@
-// $Id$
 /**
  * Copyright (C) 2007 EDIT
  * European Distributed Institute of Taxonomy
@@ -7,18 +6,21 @@
  * The contents of this file are subject to the Mozilla Public License Version 1.1
  * See LICENSE.TXT at the top of this package for the full license terms.
  */
-
 package eu.etaxonomy.taxeditor.ui.section.name;
 
 import org.eclipse.swt.events.SelectionListener;
 
+import eu.etaxonomy.cdm.compare.name.TypeDesignationStatusComparator;
 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.occurrence.DerivedUnit;
 import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationType;
-import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.cdm.model.reference.NamedSource;
+import eu.etaxonomy.cdm.model.term.TermType;
+import eu.etaxonomy.taxeditor.l10n.Messages;
+import eu.etaxonomy.taxeditor.model.MessagingUtils;
+import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
 import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
@@ -28,7 +30,6 @@ import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 /**
  * @author n.hoffmann
  * @created May 17, 2010
- * @version 1.0
  */
 public class SpecimenTypeDesignationElement extends
                AbstractTypeDesignationElement<SpecimenTypeDesignation> {
@@ -43,36 +44,56 @@ public class SpecimenTypeDesignationElement extends
                super(formFactory, section, entity, removeListener, style);
        }
 
-       /** {@inheritDoc} */
        @Override
        public void createControls(ICdmFormElement formElement, int style) {
                selection_typeSpecimen = formFactory
                                .createSelectionElement(DerivedUnit.class,
-                                               getConversationHolder(), formElement, "Specimen", null,
+                                       formElement, "Specimen", null,
                                                EntitySelectionElement.ALL, style);
                combo_typeStatus = formFactory.createDefinedTermComboElement(TermType.SpecimenTypeDesignationStatus,
-                                               formElement, "Designation Status", null, style);
+                                               formElement, "Designation Status", null, style, new TypeDesignationStatusComparator<SpecimenTypeDesignationStatus>());
 
                super.createControls(formElement, style);
+               setEntity(entity);
        }
 
-       /** {@inheritDoc} */
        @Override
        public void setEntity(SpecimenTypeDesignation entity) {
-               super.setEntity(entity);
-               selection_typeSpecimen.setEntity(entity.getTypeSpecimen());
-
-               SpecimenTypeDesignationStatus typeStatus = HibernateProxyHelper
-                               .deproxy(entity.getTypeStatus(), SpecimenTypeDesignationStatus.class);
-               combo_typeStatus.setSelection(typeStatus);
-               checkbox_notDesignated.setSelection(entity.isNotDesignated());
+           super.setEntity(entity);
+           if (selection_typeSpecimen != null){
+               if (entity.getTypeSpecimen() != null){
+                   selection_typeSpecimen.setEntity(entity.getTypeSpecimen());
+               }else{
+                   selection_typeSpecimen.setEntity(entity.getTypeSpecimen());
+               }
+       
+                       SpecimenTypeDesignationStatus typeStatus = HibernateProxyHelper
+                                       .deproxy(entity.getTypeStatus(), SpecimenTypeDesignationStatus.class);
+                   combo_typeStatus.setSelection(typeStatus);
+       
+                       checkbox_notDesignated.setSelection(entity.isNotDesignated());
+           }
        }
 
-       /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
+           super.handleEvent(eventSource);
                if (eventSource == combo_typeStatus) {
+
+                   if ((combo_typeStatus.getSelection() == null && entity.getCitation() != null) || ( entity.getTypeStatus() != null && getEntity().getTypeStatus().hasDesignationSource() && !combo_typeStatus.getSelection().hasDesignationSource() && entity.getCitation() != null)){
+                       boolean ok = MessagingUtils.confirmDialog(Messages.NameTypeDesignationElement_4, Messages.NameTypeDesignationElement_5);
+                       if (!ok){
+                           combo_typeStatus.setSelection(entity.getTypeStatus());
+                           return;
+                       }
+                   }
                        getEntity().setTypeStatus(combo_typeStatus.getSelection());
+                       if (entity.hasDesignationSource()){
+                           NamedSource source = NamedSource.NewPrimarySourceInstance(null, null);
+                           entity.setDesignationSource(source);
+                       }
+                       setEntity(entity);
+
                }
                // TODO remove this once specimens are correctly implemented
                else if (eventSource == text_specimenTypeText) {
@@ -88,11 +109,12 @@ public class SpecimenTypeDesignationElement extends
                        getEntity().setTypeSpecimen(selection_typeSpecimen.getSelection());
                } 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());
                }
+//             else if (eventSource == selection_reference) {
+//                     getEntity().setCitation(selection_reference.getSelection());
+//             } else if (eventSource == text_referenceDetail) {
+//                     getEntity().setCitationMicroReference(
+//                                     text_referenceDetail.getText());
+//             }
        }
-}
+}
\ No newline at end of file