3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
13 import java
.util
.ArrayList
;
14 import java
.util
.Collection
;
15 import java
.util
.List
;
17 import eu
.etaxonomy
.cdm
.api
.conversation
.ConversationHolder
;
18 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
19 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementBase
;
20 import eu
.etaxonomy
.cdm
.model
.description
.Feature
;
21 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
22 import eu
.etaxonomy
.cdm
.model
.description
.TextData
;
23 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
24 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
25 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonBase
;
26 import eu
.etaxonomy
.taxeditor
.ui
.campanula
.compatibility
.ICdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
28 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractEntityCollectionSection
;
29 import eu
.etaxonomy
.taxeditor
.ui
.section
.ITaxonBaseDetailSection
;
32 * <p>ProtologueSection class.</p>
35 * @created Nov 5, 2009
38 public class ProtologueSection
extends AbstractEntityCollectionSection
<TaxonNameBase
, DescriptionElementBase
> implements ITaxonBaseDetailSection
{
40 private TaxonBase taxonBase
;
43 * <p>Constructor for ProtologueSection.</p>
45 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
46 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
48 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
50 public ProtologueSection(CdmFormFactory cdmFormFactory
, ConversationHolder conversation
, ICdmFormElement parentElement
, int style
) {
51 super(cdmFormFactory
, conversation
, parentElement
, "Protologues", style
);
56 public DescriptionElementBase
createNewElement() {
57 return TextData
.NewInstance(Feature
.PROTOLOGUE());
63 public Collection
<DescriptionElementBase
> getCollection(TaxonNameBase entity
) {
64 Collection
<DescriptionElementBase
> result
= new ArrayList
<DescriptionElementBase
>();
65 List
<TaxonNameDescription
> descriptions
= getTaxonNameDescriptions(entity
);
66 for (TaxonNameDescription desc
: descriptions
){
67 result
.addAll(desc
.getElements());
70 //OLD: return getTaxonNameDescription(entity).getElements();
76 public String
getEmptyString() {
77 return "No protologues yet.";
83 protected String
getTooltipString() {
84 return "Create a new protologue";
89 public void addElement(DescriptionElementBase element
) {
90 //for simplification we always use the first description to add elements here
91 getTaxonNameDescription(getEntity()).addElement(element
);
96 public void removeElement(DescriptionElementBase element
) {
97 List
<TaxonNameDescription
> descriptions
= getTaxonNameDescriptions(getEntity());
98 for (TaxonNameDescription desc
: descriptions
){
99 desc
.removeElement(element
);
104 public void setTaxonBase(TaxonBase entity
) {
105 this.taxonBase
= entity
;
106 NonViralName name
= (NonViralName
) HibernateProxyHelper
.deproxy(entity
.getName());
111 * NOTE: returns first description
115 private TaxonNameDescription
getTaxonNameDescription(TaxonNameBase name
){
116 if(name
.getDescriptions().size() == 0){
117 name
.addDescription(TaxonNameDescription
.NewInstance(name
));
119 return (TaxonNameDescription
) name
.getDescriptions().iterator().next();
123 * Try to fix FIXME in {@link #getTaxonNameDescription(TaxonNameBase)}
127 private List
<TaxonNameDescription
> getTaxonNameDescriptions(TaxonNameBase
<?
,?
> name
){
128 List
<TaxonNameDescription
> result
= new ArrayList
<TaxonNameDescription
>();
129 if(name
.getDescriptions().size() == 0){
130 name
.addDescription(TaxonNameDescription
.NewInstance(name
));
132 for (TaxonNameDescription desc
: name
.getDescriptions()){
139 * @see eu.etaxonomy.taxeditor.section.ITaxonDetailSection#getTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)
142 public TaxonBase
getTaxonBase() {