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.Arrays;
|
14
|
|
15
|
import org.eclipse.swt.SWT;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
18
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
19
|
import eu.etaxonomy.cdm.model.name.Rank;
|
20
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
21
|
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
|
22
|
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory;
|
23
|
import eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory.TermComboType;
|
24
|
import eu.etaxonomy.taxeditor.ui.forms.CheckboxElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement;
|
26
|
import eu.etaxonomy.taxeditor.ui.forms.IEnableableFormElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.forms.ISelectableElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.forms.NumberWithLabelElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator;
|
30
|
import eu.etaxonomy.taxeditor.ui.forms.TextWithLabelElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.term.AbstractTermComboElement;
|
33
|
|
34
|
/**
|
35
|
* <p>NameDetailElement class.</p>
|
36
|
*
|
37
|
* @author n.hoffmann
|
38
|
* @created Feb 26, 2010
|
39
|
* @version 1.0
|
40
|
*/
|
41
|
public class NameDetailElement extends AbstractIdentifiableEntityDetailElement<NonViralName> implements ISelectableElement, IEnableableFormElement{
|
42
|
|
43
|
private AbstractTermComboElement<Rank> combo_rank;
|
44
|
private TextWithLabelElement text_appendedPhrase;
|
45
|
private TextWithLabelElement text_uninomial;
|
46
|
private TextWithLabelElement text_infragenericEpithet;
|
47
|
private TextWithLabelElement text_specificEpithet;
|
48
|
private TextWithLabelElement text_infraspecificEpithet;
|
49
|
private SelectionArbitrator selectionArbitrator;
|
50
|
private CheckboxElement checkbox_anamorphic;
|
51
|
private TextWithLabelElement text_breed;
|
52
|
private NumberWithLabelElement text_publicationYear;
|
53
|
private NumberWithLabelElement text_originalPublicationYear;
|
54
|
private int cursorPosition;
|
55
|
|
56
|
/**
|
57
|
* <p>Constructor for NameDetailElement.</p>
|
58
|
*
|
59
|
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
|
60
|
* @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
|
61
|
* @param style a int.
|
62
|
*/
|
63
|
public NameDetailElement(CdmFormFactory cdmFormFactory, ICdmFormElement formElement,
|
64
|
int style) {
|
65
|
super(cdmFormFactory, formElement);
|
66
|
// register as selection listener
|
67
|
if(cdmFormFactory.getSelectionProvider() != null){
|
68
|
selectionArbitrator = cdmFormFactory.createSelectionArbitrator(this);
|
69
|
}
|
70
|
}
|
71
|
|
72
|
/** {@inheritDoc} */
|
73
|
@Override
|
74
|
protected void createControls(ICdmFormElement formElement, NonViralName nonViralName, int style) {
|
75
|
|
76
|
toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
|
77
|
|
78
|
combo_rank = formFactory.createTermComboElement(TermComboType.RANK, this, "Rank", nonViralName.getRank(), style);
|
79
|
|
80
|
createGenusOrUninomialControls(this, nonViralName, style);
|
81
|
createInfragenerericEpithetControls(this, nonViralName, style);
|
82
|
createSpecificEpithetControls(this, nonViralName, style);
|
83
|
createInfraSpecificEpithetControls(this, nonViralName, style);
|
84
|
|
85
|
createSpecificNameParts(this, nonViralName, style);
|
86
|
|
87
|
text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
|
88
|
|
89
|
}
|
90
|
|
91
|
/**
|
92
|
* <p>clearCheckRankWarnings</p>
|
93
|
*/
|
94
|
protected void clearCheckRankWarnings() {
|
95
|
if(getEntity().hasProblem(ParserProblem.CheckRank)){
|
96
|
getEntity().removeParsingProblem(ParserProblem.CheckRank);
|
97
|
|
98
|
// FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
|
99
|
// TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
|
100
|
// nameEditor.getSelectedContainer().getNameViewer().clearErrors();
|
101
|
}
|
102
|
}
|
103
|
|
104
|
/** {@inheritDoc} */
|
105
|
@Override
|
106
|
protected void updateContent() {
|
107
|
if(getEntity() == null){
|
108
|
setEntity(NonViralName.NewInstance(null));
|
109
|
}
|
110
|
|
111
|
super.updateContent();
|
112
|
|
113
|
if(isIrrelevant()){
|
114
|
setIrrelevant(isIrrelevant());
|
115
|
}else{
|
116
|
setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
|
117
|
}
|
118
|
}
|
119
|
|
120
|
|
121
|
private void createSpecificNameParts(ICdmFormElement formElement,
|
122
|
NonViralName nonViralName, int style) {
|
123
|
switch(nonViralName.getNomenclaturalCode()){
|
124
|
case ICBN:
|
125
|
createBotanicalNameParts(formElement, nonViralName, style);
|
126
|
break;
|
127
|
case ICZN:
|
128
|
createZoologicalNameParts(formElement, nonViralName, style);
|
129
|
break;
|
130
|
}
|
131
|
}
|
132
|
|
133
|
private void createBotanicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
|
134
|
BotanicalName botanicalName = (BotanicalName) nonViralName;
|
135
|
checkbox_anamorphic = formFactory.createCheckbox(formElement, "Anamorphic", botanicalName.isAnamorphic(), style);
|
136
|
}
|
137
|
|
138
|
private void createZoologicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
|
139
|
ZoologicalName zoologicalName = (ZoologicalName) nonViralName;
|
140
|
text_breed = formFactory.createTextWithLabelElement(formElement, "Breed", zoologicalName.getBreed(), style);
|
141
|
text_publicationYear = formFactory.createIntegerTextWithLabelElement(formElement, "Publication Year", zoologicalName.getPublicationYear(), style);
|
142
|
text_originalPublicationYear = formFactory.createIntegerTextWithLabelElement(formElement, "Orig. Publication Year", zoologicalName.getOriginalPublicationYear(), style);
|
143
|
}
|
144
|
|
145
|
private void createGenusOrUninomialControls(ICdmFormElement element, NonViralName nonViralName, int style){
|
146
|
String title = "Genus";
|
147
|
Rank rank = nonViralName.getRank();
|
148
|
if(rank != null && rank.isSupraGeneric()){
|
149
|
title = "Uninomial";
|
150
|
}
|
151
|
text_uninomial = formFactory.createTextWithLabelElement(element, title, nonViralName.getGenusOrUninomial(), style);
|
152
|
}
|
153
|
|
154
|
private void createInfragenerericEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
|
155
|
if(nonViralName.getRank() != null && nonViralName.getRank().isInfraGeneric() && !nonViralName.getRank().isSpeciesAggregate()){
|
156
|
text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
|
157
|
}
|
158
|
}
|
159
|
|
160
|
private void createSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
|
161
|
if(nonViralName.getRank() != null && (nonViralName.getRank().isSpecies() || nonViralName.getRank().isInfraSpecific() || nonViralName.getRank().isSpeciesAggregate())){
|
162
|
text_specificEpithet = formFactory.createTextWithLabelElement(element, "Specific Epithet", nonViralName.getSpecificEpithet(), SWT.NULL);
|
163
|
}
|
164
|
}
|
165
|
|
166
|
private void createInfraSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
|
167
|
if(nonViralName.getRank() != null && nonViralName.getRank().isInfraSpecific()){
|
168
|
text_infraspecificEpithet = formFactory.createTextWithLabelElement(element, "Infraspecific Epithet", nonViralName.getInfraSpecificEpithet(), SWT.NULL);
|
169
|
}
|
170
|
}
|
171
|
|
172
|
/** {@inheritDoc} */
|
173
|
@Override
|
174
|
public void handleEvent(Object eventSource){
|
175
|
if(eventSource == combo_rank){
|
176
|
getEntity().setRank(combo_rank.getSelection());
|
177
|
clearCheckRankWarnings();
|
178
|
updateContent();
|
179
|
}
|
180
|
else if(eventSource == text_appendedPhrase){
|
181
|
getEntity().setAppendedPhrase(text_appendedPhrase.getText());
|
182
|
}
|
183
|
else if(eventSource == toggleable_cache){
|
184
|
handleToggleableCacheField();
|
185
|
}
|
186
|
else if(eventSource == text_infragenericEpithet){
|
187
|
getEntity().setInfraGenericEpithet(text_infragenericEpithet.getText());
|
188
|
}
|
189
|
else if(eventSource == text_infraspecificEpithet){
|
190
|
getEntity().setInfraSpecificEpithet(text_infraspecificEpithet.getText());
|
191
|
}
|
192
|
else if(eventSource == text_specificEpithet){
|
193
|
getEntity().setSpecificEpithet(text_specificEpithet.getText());
|
194
|
}
|
195
|
else if(eventSource == text_uninomial){
|
196
|
getEntity().setGenusOrUninomial(text_uninomial.getText());
|
197
|
}
|
198
|
else if(eventSource == checkbox_anamorphic){
|
199
|
((BotanicalName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
|
200
|
}
|
201
|
}
|
202
|
|
203
|
/*
|
204
|
* (non-Javadoc)
|
205
|
* @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
|
206
|
*/
|
207
|
/**
|
208
|
* <p>Getter for the field <code>selectionArbitrator</code>.</p>
|
209
|
*
|
210
|
* @return a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator} object.
|
211
|
*/
|
212
|
public SelectionArbitrator getSelectionArbitrator() {
|
213
|
return selectionArbitrator;
|
214
|
}
|
215
|
|
216
|
@Override
|
217
|
public void updateToggleableCacheField() {
|
218
|
if(! getEntity().isProtectedNameCache()){
|
219
|
toggleable_cache.setText(getEntity().getNameCache());
|
220
|
}
|
221
|
}
|
222
|
}
|