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