Project

General

Profile

Download (4.53 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
 * @version 1.0
37
 */
38
public class ProtologueSection extends AbstractEntityCollectionSection<TaxonNameBase, DescriptionElementBase> implements ITaxonBaseDetailSection{
39

    
40
	private TaxonBase taxonBase;
41

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

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

    
60

    
61
	/** {@inheritDoc} */
62
	@Override
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());
68
		}
69
		return result;
70
//OLD:	return getTaxonNameDescription(entity).getElements();
71
	}
72

    
73

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

    
80

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

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

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

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

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

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

    
142
	/* (non-Javadoc)
143
	 * @see eu.etaxonomy.taxeditor.section.ITaxonDetailSection#getTaxon(eu.etaxonomy.cdm.model.taxon.TaxonBase)
144
	 */
145
	@Override
146
	public TaxonBase getTaxonBase() {
147
		return taxonBase;
148
	}
149
}
(19-19/25)