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
.NonViralName
;
19 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
20 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
21 import eu
.etaxonomy
.cdm
.strategy
.parser
.ParserProblem
;
22 import eu
.etaxonomy
.taxeditor
.ui
.combo
.TermComboElement
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.NumberWithLabelElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
34 * <p>NameDetailElement class.</p>
37 * @created Feb 26, 2010
40 public class NameDetailElement
extends AbstractIdentifiableEntityDetailElement
<NonViralName
> implements ISelectableElement
, IEnableableFormElement
{
42 private TermComboElement
<Rank
> combo_rank
;
43 private TextWithLabelElement text_appendedPhrase
;
44 private TextWithLabelElement text_uninomial
;
45 private TextWithLabelElement text_infragenericEpithet
;
46 private TextWithLabelElement text_specificEpithet
;
47 private TextWithLabelElement text_infraspecificEpithet
;
48 private SelectionArbitrator selectionArbitrator
;
49 private CheckboxElement checkbox_anamorphic
;
50 private TextWithLabelElement text_breed
;
51 private NumberWithLabelElement text_publicationYear
;
52 private NumberWithLabelElement text_originalPublicationYear
;
53 private int cursorPosition
;
56 * <p>Constructor for NameDetailElement.</p>
58 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
59 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
62 public NameDetailElement(CdmFormFactory cdmFormFactory
, ICdmFormElement formElement
,
64 super(cdmFormFactory
, formElement
);
65 // register as selection listener
66 if(cdmFormFactory
.getSelectionProvider() != null){
67 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
73 protected void createControls(ICdmFormElement formElement
, NonViralName nonViralName
, int style
) {
75 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
77 combo_rank
= formFactory
.createTermComboElement(Rank
.class, this, "Rank", nonViralName
.getRank(), style
);
79 createGenusOrUninomialControls(this, nonViralName
, style
);
80 createInfragenerericEpithetControls(this, nonViralName
, style
);
81 createSpecificEpithetControls(this, nonViralName
, style
);
82 createInfraSpecificEpithetControls(this, nonViralName
, style
);
84 createSpecificNameParts(this, nonViralName
, style
);
86 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
91 * <p>clearCheckRankWarnings</p>
93 protected void clearCheckRankWarnings() {
94 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
95 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
97 // FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
98 // TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
99 // nameEditor.getSelectedContainer().getNameViewer().clearErrors();
105 protected void updateContent() {
106 if(getEntity() == null){
107 setEntity(NonViralName
.NewInstance(null));
110 super.updateContent();
113 setIrrelevant(isIrrelevant());
115 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
120 private void createSpecificNameParts(ICdmFormElement formElement
,
121 NonViralName nonViralName
, int style
) {
122 switch(nonViralName
.getNomenclaturalCode()){
124 createBotanicalNameParts(formElement
, nonViralName
, style
);
127 createZoologicalNameParts(formElement
, nonViralName
, style
);
132 private void createBotanicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
133 BotanicalName botanicalName
= (BotanicalName
) nonViralName
;
134 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", botanicalName
.isAnamorphic(), style
);
137 private void createZoologicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
138 ZoologicalName zoologicalName
= (ZoologicalName
) nonViralName
;
139 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
140 text_publicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Publication Year", zoologicalName
.getPublicationYear(), style
);
141 text_originalPublicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Orig. Publication Year", zoologicalName
.getOriginalPublicationYear(), style
);
144 private void createGenusOrUninomialControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
145 String title
= "Genus";
146 Rank rank
= nonViralName
.getRank();
147 if(rank
!= null && rank
.isSupraGeneric()){
150 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
153 private void createInfragenerericEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
154 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraGeneric() && !nonViralName
.getRank().isSpeciesAggregate()){
155 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
159 private void createSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
160 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
161 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
165 private void createInfraSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
166 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
167 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
173 public void handleEvent(Object eventSource
){
174 if (eventSource
== toggleable_cache
) {
175 getEntity().setNameCache(toggleable_cache
.getText(),
176 toggleable_cache
.getState());
178 setIrrelevant(toggleable_cache
.getState(),
179 Arrays
.asList(new Object
[] { toggleable_cache
}));
181 else if(eventSource
== combo_rank
){
182 getEntity().setRank(combo_rank
.getSelection());
183 clearCheckRankWarnings();
186 else if(eventSource
== text_appendedPhrase
){
187 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
189 else if(eventSource
== text_infragenericEpithet
){
190 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
192 else if(eventSource
== text_infraspecificEpithet
){
193 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
195 else if(eventSource
== text_specificEpithet
){
196 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
198 else if(eventSource
== text_uninomial
){
199 getEntity().setGenusOrUninomial(text_uninomial
.getText());
201 else if(eventSource
== checkbox_anamorphic
){
202 ((BotanicalName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
208 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
211 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
213 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
215 public SelectionArbitrator
getSelectionArbitrator() {
216 return selectionArbitrator
;
220 public void updateToggleableCacheField() {
221 if(! getEntity().isProtectedNameCache()){
222 toggleable_cache
.setText(getEntity().getNameCache());