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