ref #10222 adapt taxeditor to changes (DerivedUnitFacade and CondensedDistributionRec...
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / DeterminationEventDetailElement.java
index 4aabff99e2106d6dca26c1dc0e65c72d3b7de6c8..2f85aefa262dd98492ed4532f0f5fa49d711beb6 100644 (file)
@@ -6,33 +6,33 @@
  * 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.occurrence;
 
 import org.eclipse.swt.events.SelectionListener;
 
-import eu.etaxonomy.cdm.model.common.DefinedTerm;
-import eu.etaxonomy.cdm.model.common.TermType;
 import eu.etaxonomy.cdm.model.name.TaxonName;
 import eu.etaxonomy.cdm.model.occurrence.DeterminationEvent;
 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
-import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
+import eu.etaxonomy.cdm.model.term.DefinedTerm;
+import eu.etaxonomy.cdm.model.term.TermType;
+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.CheckboxElement;
 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
+import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
 
 /**
- * <p>
- * DeterminationEventDetailElement class.
- * </p>
- *
  * @author n.hoffmann
  * @created Oct 13, 2010
  */
-public class DeterminationEventDetailElement extends
-               AbstractEventDetailElement<DeterminationEvent> {
+public class DeterminationEventDetailElement
+            extends AbstractEventDetailElement<DeterminationEvent>
+            implements ISelectableElement{
+
+    private SelectionArbitrator selectionArbitrator;
 
        private TermComboElement<DefinedTerm> combo_determinationModifier;
        private CheckboxElement checkbox_preferredFlag;
@@ -41,53 +41,36 @@ public class DeterminationEventDetailElement extends
 
        // private TODO a set of references
 
-       /**
-        * <p>
-        * Constructor for DeterminationEventDetailElement.
-        * </p>
-        *
-        * @param formFactory
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
-        *            object.
-        * @param section
-        *            a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
-        *            object.
-        * @param entity
-        *            a {@link eu.etaxonomy.cdm.model.occurrence.DeterminationEvent}
-        *            object.
-        * @param removeListener
-        *            a {@link org.eclipse.swt.events.SelectionListener} object.
-        * @param style
-        *            a int.
-        */
        public DeterminationEventDetailElement(CdmFormFactory formFactory,
                        AbstractFormSection<?> section, DeterminationEvent entity,
                        SelectionListener removeListener, int style) {
                super(formFactory, section, entity, removeListener, style);
+               if (formFactory.getSelectionProvider() != null) {
+                   selectionArbitrator = formFactory.createSelectionArbitrator(this);
+               }
        }
 
-       /** {@inheritDoc} */
        @Override
        public void setEntity(DeterminationEvent entity) {
                this.entity = entity;
-               combo_determinationModifier.setSelection(entity.getModifier());
-               selection_taxonBase.setEntity(entity.getTaxon());
-               selectionTaxonNameBase.setEntity(entity.getTaxonName());
+               if (combo_determinationModifier != null){
+                       combo_determinationModifier.setSelection(entity.getModifier());
+                       selection_taxonBase.setEntity(entity.getTaxon());
+                       selectionTaxonNameBase.setEntity(entity.getTaxonName());
+               }
                super.setEntity(entity);
        }
 
-       /** {@inheritDoc} */
        @Override
        public void createControls(ICdmFormElement element, int style) {
            selectionTaxonNameBase = formFactory
-                   .createSelectionElement(TaxonName.class,//getConversationHolder(),
+                   .createSelectionElement(TaxonName.class,
                             element, "Taxon Name", null,
-                           EntitySelectionElement.NOTHING, style);
+                           EntitySelectionElement.ALL, style);
                selection_taxonBase = formFactory
-                               .createSelectionElement(TaxonBase.class,//getConversationHolder(),
+                               .createSelectionElement(TaxonBase.class,
                                                 element, "Taxon", null,
-                                               EntitySelectionElement.NOTHING, style);
-
+                                               EntitySelectionElement.ALL, style);
 
                // TODO set of references
 
@@ -99,9 +82,13 @@ public class DeterminationEventDetailElement extends
 
                combo_determinationModifier = formFactory.createDefinedTermComboElement(TermType.DeterminationModifier,
                                element, "Modifier", null, style);
+               if (entity != null){
+                       combo_determinationModifier.setSelection(entity.getModifier());
+                       selection_taxonBase.setEntity(entity.getTaxon());
+                       selectionTaxonNameBase.setEntity(entity.getTaxonName());
+               }
        }
 
-       /** {@inheritDoc} */
        @Override
        public void handleEvent(Object eventSource) {
                if (eventSource == combo_determinationModifier) {
@@ -109,18 +96,24 @@ public class DeterminationEventDetailElement extends
                } else if (eventSource == checkbox_preferredFlag) {
                        getEntity().setPreferredFlag(checkbox_preferredFlag.getSelection());
                } else if (eventSource == selectionTaxonNameBase) {
-                   getEntity().setTaxonName(selectionTaxonNameBase.getSelection());
-                   //empty taxon field if name does not belong the taxon
-                   TaxonBase taxonBase = selection_taxonBase.getEntity();
-                       if(taxonBase!=null && taxonBase.getName()!=null
-                                       && !taxonBase.getName().equals(selectionTaxonNameBase.getSelection())){
+                   TaxonName name = selectionTaxonNameBase.getSelection();
+            getEntity().setTaxonName(name);
+                   //empty taxon field if name was deleted
+            //or does not belong the taxon
+                   TaxonBase<?> taxonBase = selection_taxonBase.getEntity();
+                       if(name==null ||
+                               (taxonBase!=null && taxonBase.getName()!=null
+                                       && !taxonBase.getName().equals(name))){
                                selection_taxonBase.setEntity(null);
+                               getEntity().setTaxon(null);
                        }
                } else if (eventSource == selection_taxonBase) {
-                       TaxonBase taxon = selection_taxonBase.getSelection();
+                       TaxonBase<?> taxon = selection_taxonBase.getSelection();
             getEntity().setTaxon(taxon);
-            getEntity().setTaxonName(taxon.getName());
-            selectionTaxonNameBase.setEntity(taxon.getName());
+            if(taxon!=null){
+                getEntity().setTaxonName(taxon.getName());
+                selectionTaxonNameBase.setEntity(taxon.getName());
+            }
                }
                // else if(eventSource == TODO set of references){
                //
@@ -134,4 +127,8 @@ public class DeterminationEventDetailElement extends
                }
        }
 
-}
+    @Override
+    public SelectionArbitrator getSelectionArbitrator() {
+        return selectionArbitrator;
+    }
+}
\ No newline at end of file