2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
12 import java
.util
.ArrayList
;
13 import java
.util
.Collection
;
14 import java
.util
.List
;
16 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
17 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
18 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
19 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
20 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
21 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
22 import eu
.etaxonomy
.cdm
.model
.name
.TaxonName
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractEntityCollectionSection
;
27 import eu
.etaxonomy
.taxeditor
.ui
.section
.ITaxonBaseDetailSection
;
30 * <p>ProtologueSection class.</p>
33 * @created Nov 5, 2009
35 public class ProtologueSection
extends AbstractEntityCollectionSection
<TaxonName
, DescriptionElementBase
> implements ITaxonBaseDetailSection
{
37 private TaxonBase taxonBase
;
40 * <p>Constructor for ProtologueSection.</p>
42 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
43 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
45 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
47 public ProtologueSection(CdmFormFactory cdmFormFactory
, ConversationHolder conversation
, ICdmFormElement parentElement
, int style
) {
48 super(cdmFormFactory
, conversation
, parentElement
, "Protologues / Original Publications", style
);
53 public DescriptionElementBase
createNewElement() {
54 return TextData
.NewInstance(Feature
.PROTOLOGUE());
60 public Collection
<DescriptionElementBase
> getCollection(TaxonName entity
) {
61 Collection
<DescriptionElementBase
> result
= new ArrayList
<>();
62 List
<TaxonNameDescription
> descriptions
= getTaxonNameDescriptions(entity
);
63 for (TaxonNameDescription desc
: descriptions
){
64 result
.addAll(desc
.getElements());
67 //OLD: return getTaxonNameDescription(entity).getElements();
73 public String
getEmptyString() {
74 return "No protologues yet.";
80 protected String
getTooltipString() {
81 return "Create a new protologue";
86 public void addElement(DescriptionElementBase element
) {
87 //for simplification we always use the first description to add elements here
88 getTaxonNameDescription(getEntity()).addElement(element
);
93 public void removeElement(DescriptionElementBase element
) {
94 List
<TaxonNameDescription
> descriptions
= getTaxonNameDescriptions(getEntity());
95 for (TaxonNameDescription desc
: descriptions
){
96 desc
.removeElement(element
);
102 public void setTaxonBase(TaxonBase entity
) {
103 this.taxonBase
= entity
;
104 TaxonName name
= HibernateProxyHelper
.deproxy(entity
.getName());
109 * NOTE: returns first description
113 private TaxonNameDescription
getTaxonNameDescription(TaxonName name
){
114 if(name
.getDescriptions().size() == 0){
115 name
.addDescription(TaxonNameDescription
.NewInstance(name
));
117 return (TaxonNameDescription
) name
.getDescriptions().iterator().next();
121 * Try to fix FIXME in {@link #getTaxonNameDescription(TaxonNameBase)}
125 private List
<TaxonNameDescription
> getTaxonNameDescriptions(TaxonName name
){
126 List
<TaxonNameDescription
> result
= new ArrayList
<>();
130 for (TaxonNameDescription desc
: name
.getDescriptions()){
137 public TaxonBase
getTaxonBase() {
145 public DescriptionElementBase
addExisting() {
153 public boolean allowAddExisting() {