d41ddfda8747d8aacdab1946995da006537992cb
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / occurrence / association / DerivedUnitTypeDesignationSection.java
1 // $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.api.service.INameService;
20 import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
21 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
22 import eu.etaxonomy.taxeditor.store.CdmStore;
23 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
25 import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
26
27 /**
28 * @author pplitzner
29 * @date Oct 29, 2015
30 *
31 */
32 public class DerivedUnitTypeDesignationSection extends AbstractEntityCollectionSection<DerivedUnitFacade, SpecimenTypeDesignation> {
33
34 private Collection<SpecimenTypeDesignation> typeDesignations;
35
36 public DerivedUnitTypeDesignationSection(CdmFormFactory formFactory,
37 ConversationHolder conversation, ICdmFormElement parentElement, int style) {
38 super(formFactory, conversation, parentElement, "Type Designations", style);
39 }
40
41 /** {@inheritDoc} */
42 @Override
43 public Collection<SpecimenTypeDesignation> getCollection(DerivedUnitFacade entity) {
44 typeDesignations = entity.innerDerivedUnit().getSpecimenTypeDesignations();
45 return typeDesignations;
46 }
47
48 /** {@inheritDoc} */
49 @Override
50 public SpecimenTypeDesignation createNewElement() {
51 return SpecimenTypeDesignation.NewInstance();
52 }
53
54 /** {@inheritDoc} */
55 @Override
56 public void addElement(SpecimenTypeDesignation element) {
57 element.setTypeSpecimen(getEntity().innerDerivedUnit());
58 typeDesignations.add(element);
59 }
60
61 /** {@inheritDoc} */
62 @Override
63 public void removeElement(SpecimenTypeDesignation element) {
64 List<SpecimenTypeDesignation> toRemove = new ArrayList<SpecimenTypeDesignation>();
65 for (SpecimenTypeDesignation specimenTypeDesignation : typeDesignations) {
66 if(element.equals(specimenTypeDesignation)){
67 toRemove.add(specimenTypeDesignation);
68 }
69 }
70 for (SpecimenTypeDesignation specimenTypeDesignation : toRemove) {
71 specimenTypeDesignation.removeType();
72 Set<TaxonNameBase> names = specimenTypeDesignation.getTypifiedNames();
73 for (TaxonNameBase taxonNameBase : names) {
74 taxonNameBase.removeTypeDesignation(specimenTypeDesignation);
75 if(CdmStore.getCurrentSessionManager().isRemoting()){
76 CdmStore.getService(INameService.class).merge(taxonNameBase);
77 }
78 }
79 }
80 typeDesignations.removeAll(toRemove);
81 }
82
83 /** {@inheritDoc} */
84 @Override
85 public String getEmptyString() {
86 return "No type designation yet.";
87 }
88
89 /** {@inheritDoc} */
90 @Override
91 protected String getTooltipString() {
92 return "Add a type designation";
93 }
94
95
96 }