Project

General

Profile

Download (4.7 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.Comparator;
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.TaxonName;
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.DefaultCdmBaseComparator;
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<TaxonName, 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 / Original Publications", 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(TaxonName entity) {
63
		Collection<DescriptionElementBase> result = new ArrayList<>();
64
		List<TaxonNameDescription> descriptions = getTaxonNameDescriptions(entity);
65
		for (TaxonNameDescription desc : descriptions){
66
			desc.getElements()
67
			.stream()
68
			.filter(element -> element.getFeature().equals(Feature.PROTOLOGUE()))
69
			.forEach(element -> result.add(element));
70
		}
71
		return result;
72
//OLD:	return getTaxonNameDescription(entity).getElements();
73
	}
74

    
75
	@Override
76
	public Comparator<DescriptionElementBase> getComparator() {
77
        return new DefaultCdmBaseComparator<>();
78
	}
79

    
80

    
81
	/** {@inheritDoc} */
82
	@Override
83
	public String getEmptyString() {
84
		return "No protologues yet.";
85
	}
86

    
87

    
88
	/** {@inheritDoc} */
89
	@Override
90
	protected String getTooltipString() {
91
		return "Create a new protologue";
92
	}
93

    
94
	/** {@inheritDoc} */
95
	@Override
96
	public void addElement(DescriptionElementBase element) {
97
		//for simplification we always use the first description to add elements here
98
		getTaxonNameDescription(getEntity()).addElement(element);
99
	}
100

    
101
	/** {@inheritDoc} */
102
	@Override
103
	public void removeElement(DescriptionElementBase element) {
104
		List<TaxonNameDescription> descriptions = getTaxonNameDescriptions(getEntity());
105
		for (TaxonNameDescription desc : descriptions){
106
			desc.removeElement(element);
107
		}
108
	}
109

    
110
	/** {@inheritDoc} */
111
	@Override
112
    public void setTaxonBase(TaxonBase entity) {
113
		this.taxonBase = entity;
114
		TaxonName name = HibernateProxyHelper.deproxy(entity.getName());
115
		setEntity(name);
116
	}
117

    
118
	/**
119
	 * NOTE: returns first description
120
	 * @param name
121
	 * @return
122
	 */
123
	private TaxonNameDescription getTaxonNameDescription(TaxonName name){
124
		if(name.getDescriptions().size() == 0){
125
			name.addDescription(TaxonNameDescription.NewInstance(name));
126
		}
127
		return name.getDescriptions().iterator().next();
128
	}
129

    
130
	/**
131
	 * Try to fix FIXME in {@link #getTaxonNameDescription(TaxonNameBase)}
132
	 * @param name
133
	 * @return
134
	 */
135
	private List<TaxonNameDescription> getTaxonNameDescriptions(TaxonName name){
136
		List<TaxonNameDescription> result = new ArrayList<>();
137
		if (name == null){
138
			return result;
139
		}
140
		for (TaxonNameDescription desc : name.getDescriptions()){
141
			result.add(desc);
142
		}
143
		return result;
144
	}
145

    
146
	@Override
147
	public TaxonBase getTaxonBase() {
148
		return taxonBase;
149
	}
150

    
151
    /**
152
     * {@inheritDoc}
153
     */
154
    @Override
155
    public DescriptionElementBase addExisting() {
156
        return null;
157
    }
158

    
159
    /**
160
     * {@inheritDoc}
161
     */
162
    @Override
163
    public boolean allowAddExisting() {
164
        return false;
165
    }
166
}
(19-19/21)