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
.CdmFormFactory
.TermComboType
;
24 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CdmPropertyChangeEvent
;
25 import eu
.etaxonomy
.taxeditor
.ui
.forms
.CheckboxElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ICdmFormElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.forms
.IEnableableFormElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.forms
.ISelectableElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.forms
.NumberWithLabelElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.forms
.SelectionArbitrator
;
31 import eu
.etaxonomy
.taxeditor
.ui
.forms
.TextWithLabelElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailSection
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.term
.AbstractTermComboElement
;
37 * <p>NameDetailElement class.</p>
40 * @created Feb 26, 2010
43 public class NameDetailElement
extends AbstractIdentifiableEntityDetailElement
<NonViralName
> implements ISelectableElement
, IEnableableFormElement
{
45 private AbstractTermComboElement
<Rank
> combo_rank
;
46 private TextWithLabelElement text_appendedPhrase
;
47 private TextWithLabelElement text_uninomial
;
48 private TextWithLabelElement text_infragenericEpithet
;
49 private TextWithLabelElement text_specificEpithet
;
50 private TextWithLabelElement text_infraspecificEpithet
;
51 private SelectionArbitrator selectionArbitrator
;
52 private CheckboxElement checkbox_anamorphic
;
53 private TextWithLabelElement text_breed
;
54 private NumberWithLabelElement text_publicationYear
;
55 private NumberWithLabelElement text_originalPublicationYear
;
56 private int cursorPosition
;
59 * <p>Constructor for NameDetailElement.</p>
61 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.forms.CdmFormFactory} object.
62 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.forms.ICdmFormElement} object.
65 public NameDetailElement(CdmFormFactory cdmFormFactory
, ICdmFormElement formElement
,
67 super(cdmFormFactory
, formElement
);
68 // register as selection listener
69 if(cdmFormFactory
.getSelectionProvider() != null){
70 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
76 protected void createControls(ICdmFormElement formElement
, NonViralName nonViralName
, int style
) {
78 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
80 combo_rank
= formFactory
.createTermComboElement(TermComboType
.RANK
, this, "Rank", nonViralName
.getRank(), style
);
82 createGenusOrUninomialControls(this, nonViralName
, style
);
83 createInfragenerericEpithetControls(this, nonViralName
, style
);
84 createSpecificEpithetControls(this, nonViralName
, style
);
85 createInfraSpecificEpithetControls(this, nonViralName
, style
);
87 createSpecificNameParts(this, nonViralName
, style
);
89 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
94 * <p>clearCheckRankWarnings</p>
96 protected void clearCheckRankWarnings() {
97 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
98 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
100 // FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
101 // TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
102 // nameEditor.getSelectedContainer().getNameViewer().clearErrors();
108 protected void updateContent() {
109 if(getEntity() == null){
110 setEntity(NonViralName
.NewInstance(null));
113 super.updateContent();
116 setIrrelevant(isIrrelevant());
118 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
123 private void createSpecificNameParts(ICdmFormElement formElement
,
124 NonViralName nonViralName
, int style
) {
125 switch(nonViralName
.getNomenclaturalCode()){
127 createBotanicalNameParts(formElement
, nonViralName
, style
);
130 createZoologicalNameParts(formElement
, nonViralName
, style
);
135 private void createBotanicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
136 BotanicalName botanicalName
= (BotanicalName
) nonViralName
;
137 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", botanicalName
.isAnamorphic(), style
);
140 private void createZoologicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
141 ZoologicalName zoologicalName
= (ZoologicalName
) nonViralName
;
142 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
143 text_publicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Publication Year", zoologicalName
.getPublicationYear(), style
);
144 text_originalPublicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Orig. Publication Year", zoologicalName
.getOriginalPublicationYear(), style
);
147 private void createGenusOrUninomialControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
148 String title
= "Genus";
149 Rank rank
= nonViralName
.getRank();
150 if(rank
!= null && rank
.isSupraGeneric()){
153 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
156 private void createInfragenerericEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
157 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraGeneric() && !nonViralName
.getRank().isSpeciesAggregate()){
158 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
162 private void createSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
163 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
164 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
168 private void createInfraSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
169 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
170 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
176 public void handleEvent(Object eventSource
){
177 if(eventSource
== combo_rank
){
178 getEntity().setRank(combo_rank
.getSelection());
179 clearCheckRankWarnings();
181 else if(eventSource
== text_appendedPhrase
){
182 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
184 else if(eventSource
== toggleable_cache
){
185 handleToggleableCacheField();
187 else if(eventSource
== text_infragenericEpithet
){
188 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
190 else if(eventSource
== text_infraspecificEpithet
){
191 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
193 else if(eventSource
== text_specificEpithet
){
194 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
196 else if(eventSource
== text_uninomial
){
197 getEntity().setGenusOrUninomial(text_uninomial
.getText());
199 else if(eventSource
== checkbox_anamorphic
){
200 ((BotanicalName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
204 if(eventSource
!= toggleable_cache
&& !toggleable_cache
.getLayoutComposite().isDisposed()){
205 toggleable_cache
.setText(getEntity().getNameCache());
208 // // we have to notify the parent if this is embedded in the nonviral name section
209 // // maybe we can handle this a little bit more elegant
210 // if(getParentElement() instanceof AbstractCdmDetailSection)
211 // firePropertyChangeEvent(new CdmPropertyChangeEvent(getParentElement(), null));
216 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
219 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
221 * @return a {@link eu.etaxonomy.taxeditor.ui.forms.SelectionArbitrator} object.
223 public SelectionArbitrator
getSelectionArbitrator() {
224 return selectionArbitrator
;
228 public void updateToggleableCacheField() {
229 if(! getEntity().isProtectedNameCache()){
230 toggleable_cache
.setText(getEntity().getNameCache());