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.Collection;
|
13
|
import java.util.Comparator;
|
14
|
|
15
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
16
|
import eu.etaxonomy.cdm.api.service.INameService;
|
17
|
import eu.etaxonomy.cdm.api.service.name.TypeDesignationComparator;
|
18
|
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
|
19
|
import eu.etaxonomy.cdm.model.name.NameTypeDesignation;
|
20
|
import eu.etaxonomy.cdm.model.name.Rank;
|
21
|
import eu.etaxonomy.cdm.model.name.SpecimenTypeDesignation;
|
22
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
23
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
24
|
import eu.etaxonomy.cdm.model.taxon.TaxonBase;
|
25
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
26
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
27
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
|
31
|
import eu.etaxonomy.taxeditor.ui.section.ITaxonBaseDetailSection;
|
32
|
|
33
|
/**
|
34
|
* <p>TypeDesignationSection class.</p>
|
35
|
*
|
36
|
* @author n.hoffmann
|
37
|
* @created May 17, 2010
|
38
|
*/
|
39
|
public class TypeDesignationSection extends AbstractEntityCollectionSection<TaxonName, TypeDesignationBase> implements ITaxonBaseDetailSection {
|
40
|
|
41
|
private TaxonBase taxonBase;
|
42
|
|
43
|
/**
|
44
|
* <p>Constructor for TypeDesignationSection.</p>
|
45
|
*
|
46
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
47
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
48
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
49
|
* @param style a int.
|
50
|
*/
|
51
|
public TypeDesignationSection(CdmFormFactory formFactory, ConversationHolder conversation,
|
52
|
ICdmFormElement parentElement, int style) {
|
53
|
super(formFactory, conversation, parentElement, "Type Designations", style);
|
54
|
}
|
55
|
|
56
|
/** {@inheritDoc} */
|
57
|
@Override
|
58
|
public void addElement(TypeDesignationBase element) {
|
59
|
getEntity().addTypeDesignation(element, PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ADD_TYPES_TO_ALL_NAMES));
|
60
|
}
|
61
|
|
62
|
/** {@inheritDoc} */
|
63
|
@Override
|
64
|
public TypeDesignationBase createNewElement() {
|
65
|
if(isSpecimenType()){
|
66
|
return SpecimenTypeDesignation.NewInstance();
|
67
|
}else{
|
68
|
return NameTypeDesignation.NewInstance();
|
69
|
}
|
70
|
}
|
71
|
|
72
|
/** {@inheritDoc} */
|
73
|
@Override
|
74
|
public Collection<TypeDesignationBase> getCollection(TaxonName entity) {
|
75
|
if (entity == null){
|
76
|
return null;
|
77
|
}
|
78
|
return entity.getTypeDesignations();
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
public Comparator<TypeDesignationBase> getComparator() {
|
83
|
return new TypeDesignationComparator();
|
84
|
}
|
85
|
|
86
|
/** {@inheritDoc} */
|
87
|
@Override
|
88
|
public String getEmptyString() {
|
89
|
return "No type designations yet.";
|
90
|
}
|
91
|
|
92
|
/** {@inheritDoc} */
|
93
|
@Override
|
94
|
protected String getTooltipString() {
|
95
|
return "Add a type designation";
|
96
|
}
|
97
|
|
98
|
/** {@inheritDoc} */
|
99
|
@Override
|
100
|
public void removeElement(TypeDesignationBase element) {
|
101
|
boolean removeTypeDesignationFromAllTypifiedNames = PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.ADD_TYPES_TO_ALL_NAMES);
|
102
|
TaxonName entity = removeTypeDesignationFromAllTypifiedNames ? null : getEntity();
|
103
|
CdmStore.getService(INameService.class).deleteTypeDesignation(entity.getUuid(), element.getUuid());
|
104
|
}
|
105
|
|
106
|
/** {@inheritDoc} */
|
107
|
@Override
|
108
|
public void setTaxonBase(TaxonBase entity) {
|
109
|
this.taxonBase = entity;
|
110
|
TaxonName name = HibernateProxyHelper.deproxy(entity.getName());
|
111
|
setEntity(name);
|
112
|
}
|
113
|
|
114
|
private boolean isSpecimenType(){
|
115
|
Rank rank = getEntity().getRank();
|
116
|
if(rank==null){
|
117
|
return false;
|
118
|
}
|
119
|
return rank.isSpecies() || rank.isInfraSpecific();
|
120
|
}
|
121
|
|
122
|
@Override
|
123
|
public TaxonBase getTaxonBase() {
|
124
|
return taxonBase;
|
125
|
}
|
126
|
|
127
|
/**
|
128
|
* {@inheritDoc}
|
129
|
*/
|
130
|
@Override
|
131
|
public TypeDesignationBase addExisting() {
|
132
|
return null;
|
133
|
}
|
134
|
|
135
|
/**
|
136
|
* {@inheritDoc}
|
137
|
*/
|
138
|
@Override
|
139
|
public boolean allowAddExisting() {
|
140
|
return false;
|
141
|
}
|
142
|
}
|