1 |
4b61c2b2
|
Patrick Plitzner
|
// $Id$
|
2 |
|
|
/**
|
3 |
|
|
* Copyright (C) 2015 EDIT
|
4 |
|
|
* European Distributed Institute of Taxonomy
|
5 |
|
|
* http://www.e-taxonomy.eu
|
6 |
|
|
*
|
7 |
|
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8 |
|
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9 |
|
|
*/
|
10 |
|
|
package eu.etaxonomy.taxeditor.ui.section.occurrence.association;
|
11 |
|
|
|
12 |
|
|
import java.util.ArrayList;
|
13 |
|
|
import java.util.Collection;
|
14 |
|
|
import java.util.List;
|
15 |
|
|
import java.util.Set;
|
16 |
|
|
|
17 |
|
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
18 |
|
|
import eu.etaxonomy.cdm.api.facade.DerivedUnitFacade;
|
19 |
|
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
20 |
|
|
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
|
21 |
|
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
22 |
|
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
23 |
|
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
|
24 |
|
|
|
25 |
|
|
/**
|
26 |
|
|
* @author pplitzner
|
27 |
|
|
* @date Oct 29, 2015
|
28 |
|
|
*
|
29 |
|
|
*/
|
30 |
|
|
public class DerivedUnitTypeDesignationSection extends AbstractEntityCollectionSection<DerivedUnitFacade, SpecimenTypeDesignation> {
|
31 |
|
|
|
32 |
|
|
private Collection<SpecimenTypeDesignation> typeDesignations;
|
33 |
|
|
|
34 |
|
|
public DerivedUnitTypeDesignationSection(CdmFormFactory formFactory,
|
35 |
|
|
ConversationHolder conversation, ICdmFormElement parentElement, int style) {
|
36 |
|
|
super(formFactory, conversation, parentElement, "Type Designations", style);
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
/** {@inheritDoc} */
|
40 |
|
|
@Override
|
41 |
|
|
public Collection<SpecimenTypeDesignation> getCollection(DerivedUnitFacade entity) {
|
42 |
|
|
typeDesignations = entity.innerDerivedUnit().getSpecimenTypeDesignations();
|
43 |
|
|
return typeDesignations;
|
44 |
|
|
}
|
45 |
|
|
|
46 |
|
|
/** {@inheritDoc} */
|
47 |
|
|
@Override
|
48 |
|
|
public SpecimenTypeDesignation createNewElement() {
|
49 |
|
|
return SpecimenTypeDesignation.NewInstance();
|
50 |
|
|
}
|
51 |
|
|
|
52 |
|
|
/** {@inheritDoc} */
|
53 |
|
|
@Override
|
54 |
|
|
public void addElement(SpecimenTypeDesignation element) {
|
55 |
|
|
element.setTypeSpecimen(getEntity().innerDerivedUnit());
|
56 |
|
|
typeDesignations.add(element);
|
57 |
|
|
}
|
58 |
|
|
|
59 |
|
|
/** {@inheritDoc} */
|
60 |
|
|
@Override
|
61 |
|
|
public void removeElement(SpecimenTypeDesignation element) {
|
62 |
|
|
List<SpecimenTypeDesignation> toRemove = new ArrayList<SpecimenTypeDesignation>();
|
63 |
|
|
for (SpecimenTypeDesignation specimenTypeDesignation : typeDesignations) {
|
64 |
|
|
if(element.equals(specimenTypeDesignation)){
|
65 |
|
|
toRemove.add(specimenTypeDesignation);
|
66 |
|
|
}
|
67 |
|
|
}
|
68 |
|
|
for (SpecimenTypeDesignation specimenTypeDesignation : toRemove) {
|
69 |
|
|
specimenTypeDesignation.removeType();
|
70 |
|
|
Set<TaxonNameBase> names = specimenTypeDesignation.getTypifiedNames();
|
71 |
|
|
for (TaxonNameBase taxonNameBase : names) {
|
72 |
|
|
taxonNameBase.removeTypeDesignation(specimenTypeDesignation);
|
73 |
|
|
}
|
74 |
|
|
}
|
75 |
|
|
typeDesignations.removeAll(toRemove);
|
76 |
|
|
}
|
77 |
|
|
|
78 |
|
|
/** {@inheritDoc} */
|
79 |
|
|
@Override
|
80 |
|
|
public String getEmptyString() {
|
81 |
|
|
return "No type designation yet.";
|
82 |
|
|
}
|
83 |
|
|
|
84 |
|
|
/** {@inheritDoc} */
|
85 |
|
|
@Override
|
86 |
|
|
protected String getTooltipString() {
|
87 |
|
|
return "Add a type designation";
|
88 |
|
|
}
|
89 |
|
|
|
90 |
|
|
|
91 |
|
|
}
|