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
.eclipse
.swt
.SWT
;
17 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
18 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
19 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
20 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
21 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
22 import eu
.etaxonomy
.cdm
.strategy
.parser
.ParserProblem
;
23 import eu
.etaxonomy
.taxeditor
.ui
.combo
.TermComboElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.NumberWithLabelElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
35 * <p>NameDetailElement class.</p>
38 * @created Feb 26, 2010
41 public class NameDetailElement
extends AbstractIdentifiableEntityDetailElement
<NonViralName
> implements ISelectableElement
, IEnableableFormElement
{
43 private TermComboElement
<Rank
> combo_rank
;
44 private TextWithLabelElement text_appendedPhrase
;
45 private TextWithLabelElement text_uninomial
;
46 private TextWithLabelElement text_infragenericEpithet
;
47 private TextWithLabelElement text_specificEpithet
;
48 private TextWithLabelElement text_infraspecificEpithet
;
49 private SelectionArbitrator selectionArbitrator
;
50 private CheckboxElement checkbox_anamorphic
;
51 private TextWithLabelElement text_breed
;
52 private NumberWithLabelElement text_publicationYear
;
53 private NumberWithLabelElement text_originalPublicationYear
;
54 private int cursorPosition
;
57 * <p>Constructor for NameDetailElement.</p>
59 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
60 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
63 public NameDetailElement(CdmFormFactory cdmFormFactory
, ICdmFormElement formElement
,
65 super(cdmFormFactory
, formElement
);
66 // register as selection listener
67 if(cdmFormFactory
.getSelectionProvider() != null){
68 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
74 protected void createControls(ICdmFormElement formElement
, NonViralName nonViralName
, int style
) {
76 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
78 combo_rank
= formFactory
.createTermComboElement(Rank
.class, this, "Rank", nonViralName
.getRank(), style
);
80 createGenusOrUninomialControls(this, nonViralName
, style
);
81 createInfragenerericEpithetControls(this, nonViralName
, style
);
82 createSpecificEpithetControls(this, nonViralName
, style
);
83 createInfraSpecificEpithetControls(this, nonViralName
, style
);
85 createSpecificNameParts(this, nonViralName
, style
);
87 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
92 * <p>clearCheckRankWarnings</p>
94 protected void clearCheckRankWarnings() {
95 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
96 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
98 // FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
99 // TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
100 // nameEditor.getSelectedContainer().getNameViewer().clearErrors();
106 protected void updateContent() {
107 if(getEntity() == null){
108 setEntity(NonViralName
.NewInstance(null));
111 super.updateContent();
114 setIrrelevant(isIrrelevant());
116 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
121 private void createSpecificNameParts(ICdmFormElement formElement
,
122 NonViralName nonViralName
, int style
) {
123 NomenclaturalCode code
= nonViralName
.getNomenclaturalCode();
125 switch(nonViralName
.getNomenclaturalCode()){
127 createBotanicalNameParts(formElement
, nonViralName
, style
);
130 createZoologicalNameParts(formElement
, nonViralName
, style
);
136 private void createBotanicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
137 BotanicalName botanicalName
= (BotanicalName
) nonViralName
;
138 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", botanicalName
.isAnamorphic(), style
);
141 private void createZoologicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
142 ZoologicalName zoologicalName
= (ZoologicalName
) nonViralName
;
143 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
144 text_publicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Publication Year", zoologicalName
.getPublicationYear(), style
);
145 text_originalPublicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Orig. Publication Year", zoologicalName
.getOriginalPublicationYear(), style
);
148 private void createGenusOrUninomialControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
149 String title
= "Genus";
150 Rank rank
= nonViralName
.getRank();
151 if(rank
!= null && rank
.isSupraGeneric()){
154 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
157 private void createInfragenerericEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
158 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraGeneric() && !nonViralName
.getRank().isSpeciesAggregate()){
159 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
163 private void createSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
164 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
165 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
169 private void createInfraSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
170 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
171 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
177 public void handleEvent(Object eventSource
){
178 if (eventSource
== toggleable_cache
) {
179 getEntity().setNameCache(toggleable_cache
.getText(),
180 toggleable_cache
.getState());
182 setIrrelevant(toggleable_cache
.getState(),
183 Arrays
.asList(new Object
[] { toggleable_cache
}));
185 else if(eventSource
== combo_rank
){
186 getEntity().setRank(combo_rank
.getSelection());
187 clearCheckRankWarnings();
190 else if(eventSource
== text_appendedPhrase
){
191 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
193 else if(eventSource
== text_infragenericEpithet
){
194 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
196 else if(eventSource
== text_infraspecificEpithet
){
197 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
199 else if(eventSource
== text_specificEpithet
){
200 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
202 else if(eventSource
== text_uninomial
){
203 getEntity().setGenusOrUninomial(text_uninomial
.getText());
205 else if(eventSource
== checkbox_anamorphic
){
206 ((BotanicalName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
212 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
215 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
217 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
219 public SelectionArbitrator
getSelectionArbitrator() {
220 return selectionArbitrator
;
224 public void updateToggleableCacheField() {
225 if(! getEntity().isProtectedNameCache()){
226 toggleable_cache
.setText(getEntity().getNameCache());