Project

General

Profile

Download (4.27 KB) Statistics
| Branch: | Tag: | Revision:
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.ui.section.name;
12

    
13
import java.util.ArrayList;
14
import java.util.Collection;
15
import java.util.List;
16

    
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.element.CdmFormFactory;
27
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
28
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
29
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
30

    
31
/**
32
 * <p>ProtologueSection class.</p>
33
 *
34
 * @author n.hoffmann
35
 * @created Nov 5, 2009
36
 */
37
public class ProtologueSection extends AbstractEntityCollectionSection<TaxonNameBase, DescriptionElementBase> implements ITaxonBaseDetailSection{
38

    
39
	private TaxonBase taxonBase;
40

    
41
	/**
42
	 * <p>Constructor for ProtologueSection.</p>
43
	 *
44
	 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
45
	 * @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
46
	 * @param style a int.
47
	 * @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
48
	 */
49
	public ProtologueSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation, ICdmFormElement parentElement, int style) {
50
		super(cdmFormFactory, conversation, parentElement, "Protologues", style);
51
	}
52

    
53
	/** {@inheritDoc} */
54
	@Override
55
	public DescriptionElementBase createNewElement() {
56
		return TextData.NewInstance(Feature.PROTOLOGUE());
57
	}
58

    
59

    
60
	/** {@inheritDoc} */
61
	@Override
62
	public Collection<DescriptionElementBase> getCollection(TaxonNameBase entity) {
63
		Collection<DescriptionElementBase> result = new ArrayList<DescriptionElementBase>();
64
		List<TaxonNameDescription> descriptions = getTaxonNameDescriptions(entity);
65
		for (TaxonNameDescription desc : descriptions){
66
			result.addAll(desc.getElements());
67
		}
68
		return result;
69
//OLD:	return getTaxonNameDescription(entity).getElements();
70
	}
71

    
72

    
73
	/** {@inheritDoc} */
74
	@Override
75
	public String getEmptyString() {
76
		return "No protologues yet.";
77
	}
78

    
79

    
80
	/** {@inheritDoc} */
81
	@Override
82
	protected String getTooltipString() {
83
		return "Create a new protologue";
84
	}
85

    
86
	/** {@inheritDoc} */
87
	@Override
88
	public void addElement(DescriptionElementBase element) {
89
		//for simplification we always use the first description to add elements here
90
		getTaxonNameDescription(getEntity()).addElement(element);
91
	}
92

    
93
	/** {@inheritDoc} */
94
	@Override
95
	public void removeElement(DescriptionElementBase element) {
96
		List<TaxonNameDescription> descriptions = getTaxonNameDescriptions(getEntity());
97
		for (TaxonNameDescription desc : descriptions){
98
			desc.removeElement(element);
99
		}
100
	}
101

    
102
	/** {@inheritDoc} */
103
	@Override
104
    public void setTaxonBase(TaxonBase entity) {
105
		this.taxonBase = entity;
106
		NonViralName name = HibernateProxyHelper.deproxy(entity.getName(), NonViralName.class);
107
		setEntity(name);
108
	}
109

    
110
	/**
111
	 * NOTE: returns first description
112
	 * @param name
113
	 * @return
114
	 */
115
	private TaxonNameDescription getTaxonNameDescription(TaxonNameBase name){
116
		if(name.getDescriptions().size() == 0){
117
			name.addDescription(TaxonNameDescription.NewInstance(name));
118
		}
119
		return (TaxonNameDescription) name.getDescriptions().iterator().next();
120
	}
121

    
122
	/**
123
	 * Try to fix FIXME in {@link #getTaxonNameDescription(TaxonNameBase)}
124
	 * @param name
125
	 * @return
126
	 */
127
	private List<TaxonNameDescription> getTaxonNameDescriptions(TaxonNameBase<?,?> name){
128
		List<TaxonNameDescription> result = new ArrayList<TaxonNameDescription>();
129
		if (name == null){
130
			return result;
131
		}
132
		for (TaxonNameDescription desc : name.getDescriptions()){
133
			result.add(desc);
134
		}
135
		return result;
136
	}
137

    
138
	@Override
139
	public TaxonBase getTaxonBase() {
140
		return taxonBase;
141
	}
142
}
(19-19/21)