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
|
package eu.etaxonomy.taxeditor.ui.section.name;
|
10
|
|
11
|
import java.util.ArrayList;
|
12
|
import java.util.Comparator;
|
13
|
import java.util.List;
|
14
|
|
15
|
import org.apache.logging.log4j.LogManager;import org.apache.logging.log4j.Logger;
|
16
|
import org.eclipse.swt.SWT;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
19
|
import eu.etaxonomy.cdm.model.name.IBacterialName;
|
20
|
import eu.etaxonomy.cdm.model.name.ICultivarPlantName;
|
21
|
import eu.etaxonomy.cdm.model.name.IFungusName;
|
22
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
23
|
import eu.etaxonomy.cdm.model.name.IZoologicalName;
|
24
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
25
|
import eu.etaxonomy.cdm.model.name.Rank;
|
26
|
import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
|
27
|
import eu.etaxonomy.cdm.model.term.DefinedTermBase;
|
28
|
import eu.etaxonomy.cdm.model.term.TermType;
|
29
|
import eu.etaxonomy.cdm.strategy.parser.ParserProblem;
|
30
|
import eu.etaxonomy.taxeditor.preference.NameDetailsConfigurator;
|
31
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
32
|
import eu.etaxonomy.taxeditor.store.CdmStore;
|
33
|
import eu.etaxonomy.taxeditor.ui.combo.term.TermComboElement;
|
34
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
35
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
36
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
37
|
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
|
38
|
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
|
39
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
40
|
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
|
41
|
|
42
|
/**
|
43
|
* <p>NameDetailElement class.</p>
|
44
|
*
|
45
|
* @author n.hoffmann
|
46
|
* @created Feb 26, 2010
|
47
|
*/
|
48
|
public class NameDetailElement
|
49
|
extends AbstractIdentifiableEntityDetailElement<INonViralName>
|
50
|
implements ISelectableElement {
|
51
|
|
52
|
private final Logger logger = LogManager.getLogger(NameDetailElement.class);
|
53
|
|
54
|
private SelectionArbitrator selectionArbitrator;
|
55
|
|
56
|
private TermComboElement<Rank> combo_rank;
|
57
|
private TextWithLabelElement text_appendedPhrase;
|
58
|
private TextWithLabelElement text_uninomial;
|
59
|
private TextWithLabelElement text_infragenericEpithet;
|
60
|
private TextWithLabelElement text_specificEpithet;
|
61
|
private TextWithLabelElement text_infraspecificEpithet;
|
62
|
private CheckboxElement checkbox_anamorphic;
|
63
|
private TextWithLabelElement text_cultivarName;
|
64
|
private TextWithLabelElement text_cultivarGroup;
|
65
|
private TextWithLabelElement text_subGenusAuthorship;
|
66
|
private TextWithLabelElement text_breed;
|
67
|
|
68
|
private NameDetailsConfigurator config;
|
69
|
|
70
|
/**
|
71
|
* <p>Constructor for NameDetailElement.</p>
|
72
|
*
|
73
|
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
74
|
* @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
75
|
* @param style a int.
|
76
|
*/
|
77
|
public NameDetailElement(CdmFormFactory cdmFormFactory, ICdmFormElement formElement,
|
78
|
int style) {
|
79
|
super(cdmFormFactory, formElement);
|
80
|
// make this element selectable
|
81
|
}
|
82
|
|
83
|
@Override
|
84
|
protected void createControls(ICdmFormElement formElement, INonViralName nonViralName, int style) {
|
85
|
Comparator<Rank> comparator = null;
|
86
|
config = PreferencesUtil.getPreferredNameDetailsConfiguration();
|
87
|
|
88
|
if(PreferencesUtil.getSortRanksHierarchichally()){
|
89
|
comparator = new Comparator<Rank>(){
|
90
|
@Override
|
91
|
public int compare(Rank o1, Rank o2) {
|
92
|
if (o2 == null){
|
93
|
return -1;
|
94
|
}
|
95
|
return -1*o1.compareTo(o2);
|
96
|
}
|
97
|
};
|
98
|
}
|
99
|
if (nonViralName.getRank() != null && !(nonViralName.getRank().isCultivar() == nonViralName.getNameType().equals(NomenclaturalCode.ICNCP))){
|
100
|
nonViralName.setRank(null);
|
101
|
}
|
102
|
if (config == null){
|
103
|
toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
|
104
|
List<Rank> ranks = getRanks(nonViralName, nonViralName.getNameType());
|
105
|
|
106
|
combo_rank = formFactory.createDefinedTermComboElement(ranks, this, "Rank", nonViralName.getRank(),style, comparator);
|
107
|
|
108
|
createGenusOrUninomialControls(this, nonViralName, style);
|
109
|
createInfragenerericEpithetControls(this, nonViralName, style);
|
110
|
createSpecificEpithetControls(this, nonViralName, style);
|
111
|
createInfraSpecificEpithetControls(this, nonViralName, style);
|
112
|
createSpecificNameParts(this, nonViralName, style);
|
113
|
text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
|
114
|
}else{
|
115
|
if (config.isNameCacheActivated()){
|
116
|
toggleable_cache = formFactory.createToggleableTextField(this, "Name Cache", nonViralName.getNameCache(), nonViralName.isProtectedNameCache(), style);
|
117
|
}
|
118
|
|
119
|
if (config.isRankActivated()){
|
120
|
List<Rank> ranks = getRanks(nonViralName, nonViralName.getNameType());
|
121
|
combo_rank = formFactory.createDefinedTermComboElement(ranks, this, "Rank", nonViralName.getRank(),style, comparator);
|
122
|
}
|
123
|
|
124
|
if (config.isAtomisedEpithetsActivated()){
|
125
|
createGenusOrUninomialControls(this, nonViralName, style);
|
126
|
createInfragenerericEpithetControls(this, nonViralName, style);
|
127
|
createSpecificEpithetControls(this, nonViralName, style);
|
128
|
createInfraSpecificEpithetControls(this, nonViralName, style);
|
129
|
createSpecificNameParts(this, nonViralName, style);
|
130
|
}
|
131
|
if (config.isAppendedPhraseActivated()){
|
132
|
text_appendedPhrase = formFactory.createTextWithLabelElement(formElement, "Appended Phrase", nonViralName.getAppendedPhrase(), style);
|
133
|
}
|
134
|
}
|
135
|
if(this.getFormFactory().getSelectionProvider() != null){
|
136
|
selectionArbitrator = this.getFormFactory().createSelectionArbitrator(this);
|
137
|
}
|
138
|
for (ICdmFormElement element: this.getElements()){
|
139
|
element.setBackground(getPersistentBackground());
|
140
|
}
|
141
|
((NameDetailSection)this.getParentElement()).layout();
|
142
|
//cache relevance
|
143
|
registerCacheRelevance(combo_rank);
|
144
|
//TODO decide if relevant
|
145
|
registerCacheRelevance(text_appendedPhrase);
|
146
|
registerCacheRelevance(text_uninomial);
|
147
|
registerCacheRelevance(text_infragenericEpithet);
|
148
|
registerCacheRelevance(text_specificEpithet);
|
149
|
registerCacheRelevance(text_infraspecificEpithet);
|
150
|
registerCacheRelevance(text_cultivarName);
|
151
|
registerCacheRelevance(text_subGenusAuthorship);
|
152
|
registerCacheRelevance(text_breed);
|
153
|
|
154
|
registerCacheRelevance(toggleable_cache, cacheRelevanceHelper.getDependenciesArray());
|
155
|
}
|
156
|
|
157
|
/**
|
158
|
* clearCheckRankWarnings
|
159
|
*/
|
160
|
protected void clearCheckRankWarnings() {
|
161
|
if(getEntity().hasProblem(ParserProblem.CheckRank)){
|
162
|
getEntity().removeParsingProblem(ParserProblem.CheckRank);
|
163
|
|
164
|
// FIXME this has to be refactored completely. See tickets #1959, #1663, #1957, #1958
|
165
|
// TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
|
166
|
// nameEditor.getSelectedContainer().getNameViewer().clearErrors();
|
167
|
}
|
168
|
}
|
169
|
|
170
|
@Override
|
171
|
public void updateContent() {
|
172
|
if(getEntity() == null){
|
173
|
setEntity(TaxonNameFactory.NewNonViralInstance(null));
|
174
|
}
|
175
|
|
176
|
super.updateContent();
|
177
|
if (toggleable_cache != null){
|
178
|
toggleable_cache.setCacheEnabled(getEntity().isProtectedNameCache());
|
179
|
|
180
|
if (config == null){
|
181
|
updateCacheRelevance();
|
182
|
}
|
183
|
}
|
184
|
}
|
185
|
|
186
|
private void createSpecificNameParts(ICdmFormElement formElement,
|
187
|
INonViralName nonViralName, int style) {
|
188
|
NomenclaturalCode code = nonViralName.getNameType();
|
189
|
if (code != null){
|
190
|
switch(code){
|
191
|
case ICNAFP :
|
192
|
//nothing do add
|
193
|
if (nonViralName.getRank() != null && nonViralName.getRank().isCultivar()){
|
194
|
nonViralName.setRank(null);
|
195
|
}else{
|
196
|
createBotanicalNameParts(formElement, nonViralName, style);
|
197
|
}
|
198
|
break;
|
199
|
case Fungi :
|
200
|
if (config == null){
|
201
|
createFungusNameParts(formElement, nonViralName, style);
|
202
|
}
|
203
|
break;
|
204
|
case ICZN:
|
205
|
createZoologicalNameParts(formElement, nonViralName, style);
|
206
|
break;
|
207
|
case ICVCN:
|
208
|
//TODO implement
|
209
|
logger.warn("ICVCN not yet implemented");
|
210
|
break;
|
211
|
case ICNP:
|
212
|
createBacterialNameParts(formElement, nonViralName, style);
|
213
|
break;
|
214
|
case ICNCP:
|
215
|
if (nonViralName.getRank() != null && !nonViralName.getRank().isCultivar()){
|
216
|
nonViralName.setRank(null);
|
217
|
}
|
218
|
createCultivarNameParts(formElement, nonViralName, style);
|
219
|
break;
|
220
|
case NonViral:
|
221
|
//TODO implement
|
222
|
logger.warn("NonViral not yet implemented");
|
223
|
break;
|
224
|
}
|
225
|
|
226
|
}
|
227
|
|
228
|
}
|
229
|
|
230
|
private void createBacterialNameParts(ICdmFormElement formElement, INonViralName nonViralName, int style) {
|
231
|
IBacterialName bacterialName = (IBacterialName) nonViralName;
|
232
|
text_subGenusAuthorship = formFactory.createTextWithLabelElement(formElement, "Subgenus Authorship", bacterialName.getSubGenusAuthorship(), style);
|
233
|
// text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", bacterialName.getNameApprobation(), style);
|
234
|
|
235
|
}
|
236
|
|
237
|
private void createCultivarNameParts(ICdmFormElement formElement, INonViralName nonViralName, int style) {
|
238
|
ICultivarPlantName cultivarName = (ICultivarPlantName)nonViralName;
|
239
|
|
240
|
List<Rank> cultivarRanks = getRanks(cultivarName, nonViralName.getNameType());
|
241
|
combo_rank.setTerms(cultivarRanks);
|
242
|
combo_rank.setSelection(cultivarName.getRank());
|
243
|
|
244
|
Rank rank = cultivarName.getRank();
|
245
|
if (rank != null && (rank.equals(Rank.CULTIVAR()) || rank.equals(Rank.CULTIVARGROUP()) || rank.equals(Rank.GREX_ICNCP()))){
|
246
|
text_cultivarGroup = formFactory.createTextWithLabelElement(formElement, "Cultivar Group Epi", cultivarName.getCultivarGroupEpithet(), style);
|
247
|
}
|
248
|
if(rank != null && rank.equals(Rank.CULTIVAR())){
|
249
|
text_cultivarName = formFactory.createTextWithLabelElement(formElement, "Cultivar Epithet", cultivarName.getCultivarEpithet(), style);
|
250
|
}
|
251
|
|
252
|
}
|
253
|
|
254
|
private List<Rank> getRanks(INonViralName name, NomenclaturalCode code) {
|
255
|
List<Rank> ranks = new ArrayList<>();
|
256
|
String availableRanks = PreferencesUtil.getStringValue(PreferencePredicate.AvailableRanks.getKey());
|
257
|
List<DefinedTermBase> allRanks = CdmStore.getTermManager().createTermListFromString(availableRanks, TermType.Rank);
|
258
|
for(DefinedTermBase term: allRanks){
|
259
|
Rank rank = (Rank)term;
|
260
|
if (rank.isCultivar() == code.equals(NomenclaturalCode.ICNCP)){
|
261
|
ranks.add(rank);
|
262
|
}
|
263
|
}
|
264
|
return ranks;
|
265
|
}
|
266
|
|
267
|
private void createBotanicalNameParts(ICdmFormElement formElement, INonViralName nonViralName, int style){
|
268
|
//nothing to do
|
269
|
}
|
270
|
|
271
|
private void createFungusNameParts(ICdmFormElement formElement, INonViralName nonViralName, int style){
|
272
|
IFungusName fungusName= (IFungusName)nonViralName;
|
273
|
checkbox_anamorphic = formFactory.createCheckbox(formElement, "Anamorphic", fungusName.isAnamorphic(), style);
|
274
|
}
|
275
|
|
276
|
private void createZoologicalNameParts(ICdmFormElement formElement, INonViralName nonViralName, int style){
|
277
|
IZoologicalName zoologicalName = (IZoologicalName) nonViralName;
|
278
|
|
279
|
if (config == null){
|
280
|
text_breed = formFactory.createTextWithLabelElement(formElement, "Breed", zoologicalName.getBreed(), style);
|
281
|
}
|
282
|
}
|
283
|
|
284
|
private void createGenusOrUninomialControls(ICdmFormElement element, INonViralName nonViralName, int style){
|
285
|
String title = "Genus";
|
286
|
if(nonViralName.isSupraGeneric()){
|
287
|
title = "Uninomial";
|
288
|
}
|
289
|
text_uninomial = formFactory.createTextWithLabelElement(element, title, nonViralName.getGenusOrUninomial(), style);
|
290
|
}
|
291
|
|
292
|
private void createInfragenerericEpithetControls(ICdmFormElement element, INonViralName nonViralName, int style){
|
293
|
boolean isIcznOrNull = nonViralName.getNameType() == null || nonViralName.getNameType().equals(NomenclaturalCode.ICZN);
|
294
|
if (nonViralName.isInfraGeneric() || nonViralName.isSpecies()
|
295
|
|| isIcznOrNull && (nonViralName.isInfraSpecific() || nonViralName.isSpeciesAggregate()) //for iczn all subgeneric names may have infrageneric part, but unclear if speciesAggregates exist at all
|
296
|
){
|
297
|
text_infragenericEpithet = formFactory.createTextWithLabelElement(element, "Infrageneric Epithet", nonViralName.getInfraGenericEpithet(), style);
|
298
|
}
|
299
|
}
|
300
|
|
301
|
private void createSpecificEpithetControls(ICdmFormElement element, INonViralName nonViralName, int style){
|
302
|
if(nonViralName.isSpecies() || nonViralName.isInfraSpecific() || nonViralName.isSpeciesAggregate()){
|
303
|
text_specificEpithet = formFactory.createTextWithLabelElement(element, "Specific Epithet", nonViralName.getSpecificEpithet(), SWT.NULL);
|
304
|
}
|
305
|
}
|
306
|
|
307
|
private void createInfraSpecificEpithetControls(ICdmFormElement element, INonViralName nonViralName, int style){
|
308
|
if(nonViralName.isInfraSpecific()){
|
309
|
text_infraspecificEpithet = formFactory.createTextWithLabelElement(element, "Infraspecific Epithet", nonViralName.getInfraSpecificEpithet(), SWT.NULL);
|
310
|
}
|
311
|
}
|
312
|
|
313
|
@Override
|
314
|
public void handleEvent(Object eventSource){
|
315
|
if (eventSource == toggleable_cache) {
|
316
|
getEntity().setNameCache(toggleable_cache.getText(),
|
317
|
toggleable_cache.getState());
|
318
|
updateCacheRelevance();
|
319
|
}
|
320
|
else if(eventSource == combo_rank){
|
321
|
getEntity().setRank(combo_rank.getSelection());
|
322
|
clearCheckRankWarnings();
|
323
|
updateContent();
|
324
|
|
325
|
// ((NameDetailSection)this.getParentElement()).layout(true, true);
|
326
|
//this is needed for the "new" wizards in order to redraw correctly
|
327
|
|
328
|
}
|
329
|
else if(eventSource == text_appendedPhrase){
|
330
|
getEntity().setAppendedPhrase(text_appendedPhrase.getText());
|
331
|
}
|
332
|
else if(eventSource == text_infragenericEpithet){
|
333
|
getEntity().setInfraGenericEpithet(text_infragenericEpithet.getText());
|
334
|
}
|
335
|
else if(eventSource == text_infraspecificEpithet){
|
336
|
getEntity().setInfraSpecificEpithet(text_infraspecificEpithet.getText());
|
337
|
}
|
338
|
else if(eventSource == text_specificEpithet){
|
339
|
getEntity().setSpecificEpithet(text_specificEpithet.getText());
|
340
|
}
|
341
|
else if(eventSource == text_uninomial){
|
342
|
getEntity().setGenusOrUninomial(text_uninomial.getText());
|
343
|
}
|
344
|
else if(eventSource == checkbox_anamorphic){
|
345
|
((IFungusName)getEntity()).setAnamorphic(checkbox_anamorphic.getSelection());
|
346
|
}else if(eventSource == text_breed){
|
347
|
((IZoologicalName)getEntity()).setBreed(text_breed.getText());
|
348
|
}else if(eventSource == this.text_cultivarName){
|
349
|
((ICultivarPlantName)getEntity()).setCultivarEpithet(text_cultivarName.getText());
|
350
|
}else if(eventSource == this.text_cultivarGroup){
|
351
|
((ICultivarPlantName)getEntity()).setCultivarGroupEpithet(text_cultivarGroup.getText());
|
352
|
}else if(eventSource == this.text_subGenusAuthorship){
|
353
|
((IBacterialName)getEntity()).setSubGenusAuthorship(text_subGenusAuthorship.getText());
|
354
|
}
|
355
|
}
|
356
|
|
357
|
/**
|
358
|
* <p>Getter for the field <code>selectionArbitrator</code>.</p>
|
359
|
*/
|
360
|
@Override
|
361
|
public SelectionArbitrator getSelectionArbitrator() {
|
362
|
return selectionArbitrator;
|
363
|
}
|
364
|
|
365
|
@Override
|
366
|
public void updateToggleableCacheField() {
|
367
|
if (toggleable_cache != null){
|
368
|
if(! getEntity().isProtectedNameCache()){
|
369
|
toggleable_cache.setText(getEntity().getNameCache());
|
370
|
}
|
371
|
}
|
372
|
}
|
373
|
|
374
|
@Override
|
375
|
protected void handleToggleableCacheField() {
|
376
|
getEntity().setTitleCache(toggleable_cache.getText(), toggleable_cache.getState());
|
377
|
updateCacheRelevance();
|
378
|
updateToggleableCacheField();
|
379
|
}
|
380
|
}
|