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
.forms
.CdmFormFactory
;
23 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmPropertyChangeEvent
;
24 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CheckboxElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ICdmFormElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.forms
.IEnableableFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ISelectableElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.forms
.NumberWithLabelElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.forms
.SelectionArbitrator
;
30 import eu
.etaxonomy
.taxeditor
.ui
.forms
.TextWithLabelElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ToggleableTextElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmFormFactory
.TermComboType
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
35 import eu
.etaxonomy
.taxeditor
.ui
.term
.AbstractTermComboElement
;
38 * <p>NameDetailElement class.</p>
41 * @created Feb 26, 2010
44 public class NameDetailElement
extends AbstractCdmDetailElement
<NonViralName
> implements ISelectableElement
, IEnableableFormElement
{
46 private ToggleableTextElement toggleable_cache
;
47 private AbstractTermComboElement
<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.forms.CdmFormFactory} object.
64 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.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
.createTermComboElement(TermComboType
.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 switch(nonViralName
.getNomenclaturalCode()){
129 createBotanicalNameParts(formElement
, nonViralName
, style
);
132 createZoologicalNameParts(formElement
, nonViralName
, style
);
137 private void createBotanicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
138 BotanicalName botanicalName
= (BotanicalName
) nonViralName
;
139 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", botanicalName
.isAnamorphic(), style
);
142 private void createZoologicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
143 ZoologicalName zoologicalName
= (ZoologicalName
) nonViralName
;
144 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
145 text_publicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Publication Year", zoologicalName
.getPublicationYear(), style
);
146 text_originalPublicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Orig. Publication Year", zoologicalName
.getOriginalPublicationYear(), style
);
149 private void createGenusOrUninomialControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
150 String title
= "Genus";
151 Rank rank
= nonViralName
.getRank();
152 if(rank
!= null && rank
.isSupraGeneric()){
155 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
158 private void createInfragenerericEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
159 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraGeneric() && !nonViralName
.getRank().isSpeciesAggregate()){
160 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
164 private void createSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
165 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
166 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
170 private void createInfraSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
171 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
172 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
178 public void handleEvent(Object eventSource
){
179 if(eventSource
== combo_rank
){
180 getEntity().setRank(combo_rank
.getSelection());
181 clearCheckRankWarnings();
183 else if(eventSource
== text_appendedPhrase
){
184 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
186 else if(eventSource
== toggleable_cache
){
187 getEntity().setNameCache(toggleable_cache
.getText(), toggleable_cache
.getState());
188 //setEnabled(! text_nameCache.getState(), Arrays.asList(new Object[]{text_nameCache, combo_nomenclaturalCode}));
189 if(! isIrrelevant()) setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
191 else if(eventSource
== text_infragenericEpithet
){
192 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
194 else if(eventSource
== text_infraspecificEpithet
){
195 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
197 else if(eventSource
== text_specificEpithet
){
198 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
200 else if(eventSource
== text_uninomial
){
201 getEntity().setGenusOrUninomial(text_uninomial
.getText());
203 else if(eventSource
== checkbox_anamorphic
){
204 ((BotanicalName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
208 if(eventSource
!= toggleable_cache
&& !toggleable_cache
.getLayoutComposite().isDisposed()){
209 toggleable_cache
.setText(getEntity().getNameCache());
212 // we have to notify the parent if this is embedded in the nonviral name section
213 // maybe we can handle this a little bit more elegant
214 if(getParentElement() instanceof AbstractCdmDetailSection
)
215 firePropertyChangeEvent(new CdmPropertyChangeEvent(getParentElement(), null));
220 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
223 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
225 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator} object.
227 public SelectionArbitrator
getSelectionArbitrator() {
228 return selectionArbitrator
;