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