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