commit 4b61c2b2d5f13e3015fab17406dc1ada40c7f5b8
Author: Patrick Plitzner <p.plitzner@bgbm.org>
Date:   Mon Nov 2 11:49:33 2015 +0100

    Add type designation collection elemetn to derived unit details view

diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
index d02552384..1ba3c42dd 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/element/CdmFormFactory.java
@@ -232,6 +232,8 @@ import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailElem
 import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenCollectionDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenHierarchyDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.SpecimenHierarchyDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.occurrence.association.DerivedUnitTypeDesignationElement;
+import eu.etaxonomy.taxeditor.ui.section.occurrence.association.DerivedUnitTypeDesignationSection;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.association.TaxonAssociationDetailElement;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.association.TaxonAssociationDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.derivedUnit.PreservedSpecimenCurrentDeterminationDetailSection;
@@ -1589,6 +1591,12 @@ public class CdmFormFactory extends FormToolkit {
         return section;
     }
 
+    public DerivedUnitTypeDesignationSection createDerivedUnitTypeDesignationSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
+        DerivedUnitTypeDesignationSection section = new DerivedUnitTypeDesignationSection(this, conversation, parentElement, style);
+        addAndAdaptSection(parentElement, section);
+        return section;
+    }
+
     public TaxonAssociationDetailSection createTaxonAssociationDetailSection(ConversationHolder conversation, ICdmFormElement parentElement, ISelectionProvider selectionProvider, int style){
         TaxonAssociationDetailSection section = new TaxonAssociationDetailSection(this, conversation, parentElement, selectionProvider, style);
         addAndAdaptSection(parentElement, section);
@@ -2503,8 +2511,14 @@ public class CdmFormFactory extends FormToolkit {
             element = new SynonymRelationshipDetailElement(this, parentElement, (SynonymRelationship) entity, removeListener,
                     style);
         } else if (entity instanceof SpecimenTypeDesignation) {
-            element = new SpecimenTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
-                    removeListener, style);
+            if(parentElement instanceof DerivedUnitTypeDesignationSection){
+                element = new DerivedUnitTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
+                        removeListener, style);
+            }
+            else{
+                element = new SpecimenTypeDesignationElement(this, parentElement, (SpecimenTypeDesignation) entity,
+                        removeListener, style);
+            }
         } else if (entity instanceof StateData) {
             element = new StateDataElement(this, parentElement, (StateData) entity, removeListener, style);
         } else if (entity instanceof StatisticalMeasurementValue) {
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/DerivedUnitTypeDesignationElement.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/DerivedUnitTypeDesignationElement.java
new file mode 100644
index 000000000..16249fe38
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/DerivedUnitTypeDesignationElement.java
@@ -0,0 +1,78 @@
+// $Id$
+/**
+ * Copyright (C) 2007 EDIT
+ * European Distributed Institute of Taxonomy
+ * http://www.e-taxonomy.eu
+ *
+ * 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.association;
+
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.swt.events.SelectionListener;
+
+import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+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.section.AbstractEntityCollectionElement;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
+
+/**
+ * @author n.hoffmann
+ * @created May 17, 2010
+ * @version 1.0
+ */
+public class DerivedUnitTypeDesignationElement extends
+		AbstractEntityCollectionElement<SpecimenTypeDesignation> {
+
+    private List<EntitySelectionElement<TaxonNameBase>> selectionTaxonNames;
+    private ICdmFormElement parentFormElement;
+    private int style;
+
+    public DerivedUnitTypeDesignationElement(CdmFormFactory formFactory,
+            AbstractFormSection section, SpecimenTypeDesignation entity,
+            SelectionListener removeListener, int style) {
+        super(formFactory, section, entity, removeListener, null, style);
+    }
+
+    @Override
+    public void setEntity(SpecimenTypeDesignation entity) {
+        this.entity = entity;
+        Set<TaxonNameBase> typifiedNames = entity.getTypifiedNames();
+        if(typifiedNames.isEmpty()){
+            formFactory.createSelectionElement(
+                    TaxonNameBase.class, getConversationHolder(), parentFormElement, "Taxon Name", null,
+                    EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
+        }
+        else{
+            for (TaxonNameBase taxonNameBase : typifiedNames) {
+                EntitySelectionElement<TaxonNameBase> selectionElement = formFactory.createSelectionElement(
+                        TaxonNameBase.class, getConversationHolder(), parentFormElement, "Taxon Name", null,
+                        EntitySelectionElement.EDITABLE | EntitySelectionElement.SELECTABLE, style);
+                selectionElement.setEntity(taxonNameBase);
+            }
+        }
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void createControls(ICdmFormElement element, int style) {
+        this.parentFormElement = element;
+        this.style = style;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void handleEvent(Object eventSource) {
+        if (eventSource instanceof EntitySelectionElement) {
+            ((EntitySelectionElement<TaxonNameBase>) eventSource).getSelection().addTypeDesignation(getEntity(), false);
+        }
+    }
+
+}
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/DerivedUnitTypeDesignationSection.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/DerivedUnitTypeDesignationSection.java
new file mode 100644
index 000000000..d41ddfda8
--- /dev/null
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/ui/section/occurrence/association/DerivedUnitTypeDesignationSection.java
@@ -0,0 +1,96 @@
+// $Id$
+/**
+* Copyright (C) 2015 EDIT
+* European Distributed Institute of Taxonomy
+* http://www.e-taxonomy.eu
+*
+* 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.association;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
+import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
+import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
+import eu.etaxonomy.cdm.api.service.INameService;
+import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
+import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.taxeditor.store.CdmStore;
+import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
+
+/**
+ * @author pplitzner
+ * @date Oct 29, 2015
+ *
+ */
+public class DerivedUnitTypeDesignationSection extends AbstractEntityCollectionSection<DerivedUnitFacade, SpecimenTypeDesignation> {
+
+    private Collection<SpecimenTypeDesignation> typeDesignations;
+
+    public DerivedUnitTypeDesignationSection(CdmFormFactory formFactory,
+            ConversationHolder conversation, ICdmFormElement parentElement, int style) {
+        super(formFactory, conversation, parentElement, "Type Designations", style);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public Collection<SpecimenTypeDesignation> getCollection(DerivedUnitFacade entity) {
+        typeDesignations = entity.innerDerivedUnit().getSpecimenTypeDesignations();
+        return typeDesignations;
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public SpecimenTypeDesignation createNewElement() {
+        return SpecimenTypeDesignation.NewInstance();
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void addElement(SpecimenTypeDesignation element) {
+        element.setTypeSpecimen(getEntity().innerDerivedUnit());
+        typeDesignations.add(element);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public void removeElement(SpecimenTypeDesignation element) {
+        List<SpecimenTypeDesignation> toRemove = new ArrayList<SpecimenTypeDesignation>();
+        for (SpecimenTypeDesignation specimenTypeDesignation : typeDesignations) {
+            if(element.equals(specimenTypeDesignation)){
+                toRemove.add(specimenTypeDesignation);
+            }
+        }
+        for (SpecimenTypeDesignation specimenTypeDesignation : toRemove) {
+            specimenTypeDesignation.removeType();
+            Set<TaxonNameBase> names = specimenTypeDesignation.getTypifiedNames();
+            for (TaxonNameBase taxonNameBase : names) {
+                taxonNameBase.removeTypeDesignation(specimenTypeDesignation);
+                if(CdmStore.getCurrentSessionManager().isRemoting()){
+                    CdmStore.getService(INameService.class).merge(taxonNameBase);
+                }
+            }
+        }
+        typeDesignations.removeAll(toRemove);
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    public String getEmptyString() {
+        return "No type designation yet.";
+    }
+
+    /** {@inheritDoc} */
+    @Override
+    protected String getTooltipString() {
+        return "Add a type designation";
+    }
+
+
+}
\ No newline at end of file
diff --git a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java
index 051397d9c..5908ab91e 100644
--- a/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java
+++ b/eu.etaxonomy.taxeditor.store/src/main/java/eu/etaxonomy/taxeditor/view/detail/DetailsViewer.java
@@ -90,6 +90,7 @@ import eu.etaxonomy.taxeditor.ui.section.occurrence.EmptySection;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.FieldUnitGeneralDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.GatheringEventDetailSection;
+import eu.etaxonomy.taxeditor.ui.section.occurrence.association.DerivedUnitTypeDesignationSection;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.association.TaxonAssociationDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.DnaQualityDetailSection;
 import eu.etaxonomy.taxeditor.ui.section.occurrence.dna.DnaSampleGeneralDetailSection;
@@ -589,6 +590,10 @@ public class DetailsViewer extends AbstractCdmDataViewer {
             addPart(taxonAssociationDetailSection);
         }
 
+        formFactory.createHorizontalSeparator(parent, SWT.BORDER);
+        DerivedUnitTypeDesignationSection derivedUnitTypeDesignationSection = formFactory.createDerivedUnitTypeDesignationSection(getConversationHolder(), parent, this, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
+        addPart(derivedUnitTypeDesignationSection);
+
         formFactory.createHorizontalSeparator(parent, SWT.BORDER);
         IdentifierDetailSection identifierDetailSection = formFactory.createIdentifierDetailSection(getConversationHolder(), parent, ExpandableComposite.TWISTIE);
         addPart(identifierDetailSection);
