Project

General

Profile

Download (4.5 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
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.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.ui.section.name;
11

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

    
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.NonViralName;
23
import eu.etaxonomy.cdm.model.name.TaxonNameBase;
24
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
25
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
26
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
27
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
28
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
29

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

    
38
	private TaxonBase taxonBase;
39

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

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

    
58

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

    
71

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

    
78

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

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

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

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

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

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

    
137
	@Override
138
	public TaxonBase getTaxonBase() {
139
		return taxonBase;
140
	}
141

    
142
    /**
143
     * {@inheritDoc}
144
     */
145
    @Override
146
    public DescriptionElementBase addExisting() {
147
        return null;
148
    }
149

    
150
    /**
151
     * {@inheritDoc}
152
     */
153
    @Override
154
    public boolean allowAddExisting() {
155
        return false;
156
    }
157
}
(19-19/21)