3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
13 import java
.util
.Arrays
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.swt
.SWT
;
18 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
19 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
21 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
22 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
23 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
24 import eu
.etaxonomy
.cdm
.strategy
.parser
.ParserProblem
;
25 import eu
.etaxonomy
.taxeditor
.ui
.combo
.TermComboElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.NumberWithLabelElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
37 * <p>NameDetailElement class.</p>
40 * @created Feb 26, 2010
43 public class NameDetailElement
extends AbstractIdentifiableEntityDetailElement
<NonViralName
> implements ISelectableElement
, IEnableableFormElement
{
45 private final Logger logger
= Logger
.getLogger(NameDetailElement
.class);
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
;
61 * <p>Constructor for NameDetailElement.</p>
63 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
64 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
67 public NameDetailElement(CdmFormFactory cdmFormFactory
, ICdmFormElement formElement
,
69 super(cdmFormFactory
, formElement
);
70 // register as selection listener
71 if(cdmFormFactory
.getSelectionProvider() != null){
72 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
78 protected void createControls(ICdmFormElement formElement
, NonViralName nonViralName
, int style
) {
80 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
82 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
);
84 createGenusOrUninomialControls(this, nonViralName
, style
);
85 createInfragenerericEpithetControls(this, nonViralName
, style
);
86 createSpecificEpithetControls(this, nonViralName
, style
);
87 createInfraSpecificEpithetControls(this, nonViralName
, style
);
89 createSpecificNameParts(this, nonViralName
, style
);
91 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
96 * <p>clearCheckRankWarnings</p>
98 protected void clearCheckRankWarnings() {
99 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
100 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
102 // FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
103 // TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
104 // nameEditor.getSelectedContainer().getNameViewer().clearErrors();
110 protected void updateContent() {
111 if(getEntity() == null){
112 setEntity(NonViralName
.NewInstance(null));
115 super.updateContent();
118 setIrrelevant(isIrrelevant());
120 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
125 private void createSpecificNameParts(ICdmFormElement formElement
,
126 NonViralName nonViralName
, int style
) {
127 NomenclaturalCode code
= nonViralName
.getNomenclaturalCode();
129 switch(nonViralName
.getNomenclaturalCode()){
131 createBotanicalNameParts(formElement
, nonViralName
, style
);
134 createZoologicalNameParts(formElement
, nonViralName
, style
);
138 logger
.warn("ICVCN not yet implemented");
142 logger
.warn("ICNB not yet implemented");
146 logger
.warn("ICNCP not yet implemented");
152 private void createBotanicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
153 BotanicalName botanicalName
= (BotanicalName
) nonViralName
;
154 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", botanicalName
.isAnamorphic(), style
);
157 private void createZoologicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
158 ZoologicalName zoologicalName
= (ZoologicalName
) nonViralName
;
159 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
160 text_publicationYear
= formFactory
.createNumberTextWithLabelElement(formElement
, "Publication Year", zoologicalName
.getPublicationYear(), style
);
161 text_originalPublicationYear
= formFactory
.createNumberTextWithLabelElement(formElement
, "Orig. Publication Year", zoologicalName
.getOriginalPublicationYear(), style
);
164 private void createGenusOrUninomialControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
165 String title
= "Genus";
166 Rank rank
= nonViralName
.getRank();
167 if(rank
!= null && rank
.isSupraGeneric()){
170 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
173 private void createInfragenerericEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
174 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraGeneric() && !nonViralName
.getRank().isSpeciesAggregate()){
175 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
179 private void createSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
180 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
181 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
185 private void createInfraSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
186 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
187 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
193 public void handleEvent(Object eventSource
){
194 if (eventSource
== toggleable_cache
) {
195 getEntity().setNameCache(toggleable_cache
.getText(),
196 toggleable_cache
.getState());
197 if (!isIrrelevant()) {
198 setIrrelevant(toggleable_cache
.getState(),
199 Arrays
.asList(new Object
[] { toggleable_cache
}));
202 else if(eventSource
== combo_rank
){
203 getEntity().setRank(combo_rank
.getSelection());
204 clearCheckRankWarnings();
207 else if(eventSource
== text_appendedPhrase
){
208 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
210 else if(eventSource
== text_infragenericEpithet
){
211 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
213 else if(eventSource
== text_infraspecificEpithet
){
214 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
216 else if(eventSource
== text_specificEpithet
){
217 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
219 else if(eventSource
== text_uninomial
){
220 getEntity().setGenusOrUninomial(text_uninomial
.getText());
222 else if(eventSource
== checkbox_anamorphic
){
223 ((BotanicalName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
229 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
232 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
234 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
237 public SelectionArbitrator
getSelectionArbitrator() {
238 return selectionArbitrator
;
242 public void updateToggleableCacheField() {
243 if(! getEntity().isProtectedNameCache()){
244 toggleable_cache
.setText(getEntity().getNameCache());