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