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.Arrays;
|
13
|
|
14
|
import org.apache.log4j.Logger;
|
15
|
import org.eclipse.swt.SWT;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.common.TermType;
|
18
|
import eu.etaxonomy.cdm.model.name.BotanicalName;
|
19
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
20
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
21
|
import eu.etaxonomy.cdm.model.name.Rank;
|
22
|
import eu.etaxonomy.cdm.model.name.ZoologicalName;
|
23
|
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
|
24
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
25
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
26
|
import eu.etaxonomy.taxeditor.ui.combo.TermComboElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.IEnableableFormElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
|
33
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
34
|
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
|
35
|
|
36
|
/**
|
37
|
* <p>NameDetailElement class.</p>
|
38
|
*
|
39
|
* @author n.hoffmann
|
40
|
* @created Feb 26, 2010
|
41
|
* @version 1.0
|
42
|
*/
|
43
|
public class NameDetailElement extends AbstractIdentifiableEntityDetailElement<NonViralName> implements ISelectableElement, IEnableableFormElement{
|
44
|
|
45
|
private final Logger logger = Logger.getLogger(NameDetailElement.class);
|
46
|
|
47
|
private TermComboElement<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.element.CdmFormFactory} object.
|
64
|
* @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
65
|
* @param style a int.
|
66
|
*/
|
67
|
public NameDetailElement(CdmFormFactory cdmFormFactory, ICdmFormElement formElement,
|
68
|
int style) {
|
69
|
super(cdmFormFactory, formElement);
|
70
|
// make this element selectable
|
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
|
if (isAdvancedView){
|
81
|
toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
|
82
|
combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
|
83
|
createGenusOrUninomialControls(this, nonViralName, style);
|
84
|
createInfragenerericEpithetControls(this, nonViralName, style);
|
85
|
createSpecificEpithetControls(this, nonViralName, style);
|
86
|
createInfraSpecificEpithetControls(this, nonViralName, style);
|
87
|
createSpecificNameParts(this, nonViralName, style);
|
88
|
text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
|
89
|
}else{
|
90
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAMECACHE)){
|
91
|
toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
|
92
|
}
|
93
|
|
94
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_RANK)){
|
95
|
combo_rank = formFactory.createDefinedTermComboElement(TermType.Rank, this, "Rank", nonViralName.getRank(), style);
|
96
|
}
|
97
|
|
98
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS)){
|
99
|
createGenusOrUninomialControls(this, nonViralName, style);
|
100
|
createInfragenerericEpithetControls(this, nonViralName, style);
|
101
|
createSpecificEpithetControls(this, nonViralName, style);
|
102
|
createInfraSpecificEpithetControls(this, nonViralName, style);
|
103
|
createSpecificNameParts(this, nonViralName, style);
|
104
|
}
|
105
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE)){
|
106
|
text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
|
107
|
}
|
108
|
}
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* <p>clearCheckRankWarnings</p>
|
113
|
*/
|
114
|
protected void clearCheckRankWarnings() {
|
115
|
if(getEntity().hasProblem(ParserProblem.CheckRank)){
|
116
|
getEntity().removeParsingProblem(ParserProblem.CheckRank);
|
117
|
|
118
|
// FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
|
119
|
// TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
|
120
|
// nameEditor.getSelectedContainer().getNameViewer().clearErrors();
|
121
|
}
|
122
|
}
|
123
|
|
124
|
/** {@inheritDoc} */
|
125
|
@Override
|
126
|
protected void updateContent() {
|
127
|
if(getEntity() == null){
|
128
|
setEntity(NonViralName.NewInstance(null));
|
129
|
}
|
130
|
|
131
|
super.updateContent();
|
132
|
if (isAdvancedView){
|
133
|
if(isIrrelevant()){
|
134
|
setIrrelevant(isIrrelevant());
|
135
|
}else{
|
136
|
setIrrelevant(toggleable_cache.getState(), Arrays.asList(new Object[]{toggleable_cache}));
|
137
|
}
|
138
|
}
|
139
|
}
|
140
|
|
141
|
|
142
|
private void createSpecificNameParts(ICdmFormElement formElement,
|
143
|
NonViralName nonViralName, int style) {
|
144
|
NomenclaturalCode code = nonViralName.getNomenclaturalCode();
|
145
|
if (code != null){
|
146
|
switch(nonViralName.getNomenclaturalCode()){
|
147
|
case ICNAFP :
|
148
|
// TODO RL
|
149
|
if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL) && isAdvancedView)
|
150
|
{
|
151
|
createBotanicalNameParts(formElement, nonViralName, style);
|
152
|
}
|
153
|
break;
|
154
|
case ICZN:
|
155
|
createZoologicalNameParts(formElement, nonViralName, style);
|
156
|
break;
|
157
|
case ICVCN:
|
158
|
//TODO implement
|
159
|
logger.warn("ICVCN not yet implemented");
|
160
|
break;
|
161
|
case ICNB:
|
162
|
//TODO implement
|
163
|
logger.warn("ICNB not yet implemented");
|
164
|
break;
|
165
|
case ICNCP:
|
166
|
//TODO implement
|
167
|
logger.warn("ICNCP not yet implemented");
|
168
|
break;
|
169
|
}
|
170
|
}
|
171
|
}
|
172
|
|
173
|
private void createBotanicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
|
174
|
BotanicalName botanicalName = (BotanicalName) nonViralName;
|
175
|
checkbox_anamorphic = formFactory.createCheckbox(formElement, "Anamorphic", botanicalName.isAnamorphic(), style);
|
176
|
}
|
177
|
|
178
|
private void createZoologicalNameParts(ICdmFormElement formElement, NonViralName nonViralName, int style){
|
179
|
ZoologicalName zoologicalName = (ZoologicalName) nonViralName;
|
180
|
|
181
|
if (isAdvancedView){
|
182
|
text_breed = formFactory.createTextWithLabelElement(formElement, "Breed", zoologicalName.getBreed(), style);
|
183
|
}
|
184
|
}
|
185
|
|
186
|
private void createGenusOrUninomialControls(ICdmFormElement element, NonViralName nonViralName, int style){
|
187
|
String title = "Genus";
|
188
|
Rank rank = nonViralName.getRank();
|
189
|
if(rank != null && rank.isSupraGeneric()){
|
190
|
title = "Uninomial";
|
191
|
}
|
192
|
text_uninomial = formFactory.createTextWithLabelElement(element, title, nonViralName.getGenusOrUninomial(), style);
|
193
|
}
|
194
|
|
195
|
private void createInfragenerericEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
|
196
|
if (nonViralName.getNomenclaturalCode() == null || nonViralName.getNomenclaturalCode().equals(NomenclaturalCode.ICZN)){
|
197
|
if(nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS()) ){
|
198
|
text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
|
199
|
}
|
200
|
} else{
|
201
|
if((nonViralName.getRank() != null && nonViralName.getRank().isLower(Rank.GENUS())) && !nonViralName.getRank().isLower(Rank.SPECIES()) && !nonViralName.getRank().isSpeciesAggregate()){
|
202
|
text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
|
203
|
}
|
204
|
}
|
205
|
}
|
206
|
|
207
|
private void createSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
|
208
|
if(nonViralName.getRank() != null && (nonViralName.getRank().isSpecies() || nonViralName.getRank().isInfraSpecific() || nonViralName.getRank().isSpeciesAggregate())){
|
209
|
text_specificEpithet = formFactory.createTextWithLabelElement(element, "Specific Epithet", nonViralName.getSpecificEpithet(), SWT.NULL);
|
210
|
}
|
211
|
}
|
212
|
|
213
|
private void createInfraSpecificEpithetControls(ICdmFormElement element, NonViralName nonViralName, int style){
|
214
|
if(nonViralName.getRank() != null && nonViralName.getRank().isInfraSpecific()){
|
215
|
text_infraspecificEpithet = formFactory.createTextWithLabelElement(element, "Infraspecific Epithet", nonViralName.getInfraSpecificEpithet(), SWT.NULL);
|
216
|
}
|
217
|
}
|
218
|
|
219
|
/** {@inheritDoc} */
|
220
|
@Override
|
221
|
public void handleEvent(Object eventSource){
|
222
|
if (eventSource == toggleable_cache) {
|
223
|
getEntity().setNameCache(toggleable_cache.getText(),
|
224
|
toggleable_cache.getState());
|
225
|
if (!isIrrelevant()) {
|
226
|
setIrrelevant(toggleable_cache.getState(),
|
227
|
Arrays.asList(new Object[] { toggleable_cache }));
|
228
|
}
|
229
|
}
|
230
|
else if(eventSource == combo_rank){
|
231
|
getEntity().setRank(combo_rank.getSelection());
|
232
|
clearCheckRankWarnings();
|
233
|
updateContent();
|
234
|
}
|
235
|
else if(eventSource == text_appendedPhrase){
|
236
|
getEntity().setAppendedPhrase(text_appendedPhrase.getText());
|
237
|
}
|
238
|
else if(eventSource == text_infragenericEpithet){
|
239
|
getEntity().setInfraGenericEpithet(text_infragenericEpithet.getText());
|
240
|
}
|
241
|
else if(eventSource == text_infraspecificEpithet){
|
242
|
getEntity().setInfraSpecificEpithet(text_infraspecificEpithet.getText());
|
243
|
}
|
244
|
else if(eventSource == text_specificEpithet){
|
245
|
getEntity().setSpecificEpithet(text_specificEpithet.getText());
|
246
|
}
|
247
|
else if(eventSource == text_uninomial){
|
248
|
getEntity().setGenusOrUninomial(text_uninomial.getText());
|
249
|
}
|
250
|
else if(eventSource == checkbox_anamorphic){
|
251
|
((BotanicalName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
|
252
|
}else if(eventSource == text_breed){
|
253
|
((ZoologicalName)getEntity()).setBreed(text_breed.getText());
|
254
|
}
|
255
|
|
256
|
}
|
257
|
|
258
|
/*
|
259
|
* (non-Javadoc)
|
260
|
* @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
|
261
|
*/
|
262
|
/**
|
263
|
* <p>Getter for the field <code>selectionArbitrator</code>.</p>
|
264
|
*
|
265
|
* @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
|
266
|
*/
|
267
|
@Override
|
268
|
public SelectionArbitrator getSelectionArbitrator() {
|
269
|
return selectionArbitrator;
|
270
|
}
|
271
|
|
272
|
@Override
|
273
|
public void updateToggleableCacheField() {
|
274
|
if (toggleable_cache != null){
|
275
|
if(! getEntity().isProtectedNameCache()){
|
276
|
toggleable_cache.setText(getEntity().getNameCache());
|
277
|
}
|
278
|
}
|
279
|
}
|
280
|
|
281
|
@Override
|
282
|
protected void handleToggleableCacheField() {
|
283
|
boolean pushedState = toggleable_cache.getState();
|
284
|
|
285
|
getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
|
286
|
setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, text_appendedPhrase, checkbox_anamorphic }));
|
287
|
updateToggleableCacheField();
|
288
|
}
|
289
|
|
290
|
|
291
|
|
292
|
|
293
|
}
|