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