performed javacscript:fix and worked on documentation
[taxeditor.git] / taxeditor-editor / src / main / java / eu / etaxonomy / taxeditor / section / name / ProtologueSection.java
1 // $Id$
2 /**
3 * Copyright (C) 2007 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
11 package eu.etaxonomy.taxeditor.section.name;
12
13 import java.util.Collection;
14
15 import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
16 import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
17 import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
18 import eu.etaxonomy.cdm.model.description.Feature;
19 import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
20 import eu.etaxonomy.cdm.model.description.TextData;
21 import eu.etaxonomy.cdm.model.name.NonViralName;
22 import eu.etaxonomy.cdm.model.name.TaxonNameBase;
23 import eu.etaxonomy.cdm.model.taxon.TaxonBase;
24 import eu.etaxonomy.taxeditor.forms.CdmFormFactory;
25 import eu.etaxonomy.taxeditor.forms.ICdmFormElement;
26 import eu.etaxonomy.taxeditor.section.AbstractEntityCollectionSection;
27 import eu.etaxonomy.taxeditor.section.ITaxonDetailSection;
28
29 /**
30 * <p>ProtologueSection class.</p>
31 *
32 * @author n.hoffmann
33 * @created Nov 5, 2009
34 * @version 1.0
35 */
36 public class ProtologueSection extends AbstractEntityCollectionSection<TaxonNameBase, DescriptionElementBase> implements ITaxonDetailSection{
37
38 /**
39 * <p>Constructor for ProtologueSection.</p>
40 *
41 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
42 * @param parentElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
43 * @param style a int.
44 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
45 */
46 public ProtologueSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation, ICdmFormElement parentElement, int style) {
47 super(cdmFormFactory, conversation, parentElement, "Protologues", style);
48 }
49
50 /** {@inheritDoc} */
51 @Override
52 public DescriptionElementBase createNewElement() {
53 return TextData.NewInstance(Feature.PROTOLOGUE());
54 }
55
56
57 /** {@inheritDoc} */
58 @Override
59 public Collection<DescriptionElementBase> getCollection(
60 TaxonNameBase entity) {
61 return getTaxonNameDescription(entity).getElements();
62 }
63
64
65 /** {@inheritDoc} */
66 @Override
67 public String getEmptyString() {
68 return "No protologues yet.";
69 }
70
71
72 /** {@inheritDoc} */
73 @Override
74 protected String getTooltipString() {
75 return "Create a new protologue";
76 }
77
78 /** {@inheritDoc} */
79 @Override
80 public void addElement(DescriptionElementBase element) {
81 getTaxonNameDescription(getEntity()).addElement(element);
82 }
83
84 /** {@inheritDoc} */
85 @Override
86 public void removeElement(DescriptionElementBase element) {
87 getTaxonNameDescription(getEntity()).removeElement(element);
88 }
89
90 /** {@inheritDoc} */
91 public void setTaxon(TaxonBase taxon) {
92
93 NonViralName name = (NonViralName) HibernateProxyHelper.deproxy(taxon.getName());
94
95 setEntity(name);
96 }
97
98 private TaxonNameDescription getTaxonNameDescription(TaxonNameBase name){
99 // FIXME does not handle multiple name descriptions at the moment
100 if(name.getDescriptions().size() == 0){
101 name.addDescription(TaxonNameDescription.NewInstance(name));
102 }
103 return (TaxonNameDescription) name.getDescriptions().iterator().next();
104 }
105 }