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
.section
.name
;
13 import java
.util
.Arrays
;
15 import org
.eclipse
.swt
.SWT
;
16 import org
.eclipse
.swt
.SWTException
;
18 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
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
.editor
.EditorUtil
;
24 import eu
.etaxonomy
.taxeditor
.editor
.Page
;
25 import eu
.etaxonomy
.taxeditor
.editor
.name
.TaxonNameEditor
;
26 import eu
.etaxonomy
.taxeditor
.forms
.CdmFormFactory
;
27 import eu
.etaxonomy
.taxeditor
.forms
.CdmFormFactory
.TermComboType
;
28 import eu
.etaxonomy
.taxeditor
.forms
.CdmPropertyChangeEvent
;
29 import eu
.etaxonomy
.taxeditor
.forms
.CheckboxElement
;
30 import eu
.etaxonomy
.taxeditor
.forms
.ICdmFormElement
;
31 import eu
.etaxonomy
.taxeditor
.forms
.IEnableableFormElement
;
32 import eu
.etaxonomy
.taxeditor
.forms
.ISelectableElement
;
33 import eu
.etaxonomy
.taxeditor
.forms
.NumberWithLabelElement
;
34 import eu
.etaxonomy
.taxeditor
.forms
.SelectionArbitrator
;
35 import eu
.etaxonomy
.taxeditor
.forms
.TextWithLabelElement
;
36 import eu
.etaxonomy
.taxeditor
.forms
.ToggleableTextElement
;
37 import eu
.etaxonomy
.taxeditor
.forms
.term
.AbstractTermComboElement
;
38 import eu
.etaxonomy
.taxeditor
.section
.AbstractCdmDetailElement
;
39 import eu
.etaxonomy
.taxeditor
.section
.AbstractCdmDetailSection
;
42 * <p>NameDetailElement class.</p>
45 * @created Feb 26, 2010
48 public class NameDetailElement
extends AbstractCdmDetailElement
<NonViralName
> implements ISelectableElement
, IEnableableFormElement
{
50 private ToggleableTextElement toggleable_cache
;
51 private AbstractTermComboElement
<Rank
> combo_rank
;
52 private TextWithLabelElement text_appendedPhrase
;
53 private TextWithLabelElement text_uninomial
;
54 private TextWithLabelElement text_infragenericEpithet
;
55 private TextWithLabelElement text_specificEpithet
;
56 private TextWithLabelElement text_infraspecificEpithet
;
57 private SelectionArbitrator selectionArbitrator
;
58 private CheckboxElement checkbox_anamorphic
;
59 private TextWithLabelElement text_breed
;
60 private NumberWithLabelElement text_publicationYear
;
61 private NumberWithLabelElement text_originalPublicationYear
;
62 private int cursorPosition
;
65 * <p>Constructor for NameDetailElement.</p>
67 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
68 * @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
71 public NameDetailElement(CdmFormFactory cdmFormFactory
, ICdmFormElement formElement
,
73 super(cdmFormFactory
, formElement
);
74 // register as selection listener
75 if(cdmFormFactory
.getSelectionProvider() != null){
76 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
82 protected void createControls(ICdmFormElement formElement
, NonViralName nonViralName
, int style
) {
84 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
86 combo_rank
= formFactory
.createTermComboElement(TermComboType
.RANK
, this, "Rank", nonViralName
.getRank(), style
);
88 createGenusOrUninomialControls(this, nonViralName
, style
);
89 createInfragenerericEpithetControls(this, nonViralName
, style
);
90 createSpecificEpithetControls(this, nonViralName
, style
);
91 createInfraSpecificEpithetControls(this, nonViralName
, style
);
93 createSpecificNameParts(this, nonViralName
, style
);
95 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
100 * <p>clearCheckRankWarnings</p>
102 protected void clearCheckRankWarnings() {
103 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
104 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
106 TaxonNameEditor nameEditor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
107 nameEditor
.getSelectedContainer().getNameViewer().clearErrors();
113 // public void setEnabled(boolean enabled){
114 // setEnabled(enabled, null);
119 protected void updateContent() {
120 if(getEntity() == null){
121 setEntity(NonViralName
.NewInstance(null));
124 super.updateContent();
127 setIrrelevant(isIrrelevant());
129 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
134 private void createSpecificNameParts(ICdmFormElement formElement
,
135 NonViralName nonViralName
, int style
) {
136 switch(nonViralName
.getNomenclaturalCode()){
138 createBotanicalNameParts(formElement
, nonViralName
, style
);
141 createZoologicalNameParts(formElement
, nonViralName
, style
);
146 private void createBotanicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
147 BotanicalName botanicalName
= (BotanicalName
) nonViralName
;
148 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", botanicalName
.isAnamorphic(), style
);
151 private void createZoologicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
152 ZoologicalName zoologicalName
= (ZoologicalName
) nonViralName
;
153 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
154 text_publicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Publication Year", zoologicalName
.getPublicationYear(), style
);
155 text_originalPublicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Orig. Publication Year", zoologicalName
.getOriginalPublicationYear(), style
);
158 private void createGenusOrUninomialControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
159 String title
= "Genus";
160 Rank rank
= nonViralName
.getRank();
161 if(rank
!= null && rank
.isSupraGeneric()){
164 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
167 private void createInfragenerericEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
168 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraGeneric() && !nonViralName
.getRank().isSpeciesAggregate()){
169 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
173 private void createSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
174 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
175 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
179 private void createInfraSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
180 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
181 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
187 public void handleEvent(Object eventSource
){
188 if(eventSource
== combo_rank
){
189 getEntity().setRank(combo_rank
.getSelection());
190 clearCheckRankWarnings();
192 else if(eventSource
== text_appendedPhrase
){
193 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
195 else if(eventSource
== toggleable_cache
){
196 getEntity().setNameCache(toggleable_cache
.getText(), toggleable_cache
.getState());
197 //setEnabled(! text_nameCache.getState(), Arrays.asList(new Object[]{text_nameCache, combo_nomenclaturalCode}));
198 if(! isIrrelevant()) setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
200 else if(eventSource
== text_infragenericEpithet
){
201 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
203 else if(eventSource
== text_infraspecificEpithet
){
204 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
206 else if(eventSource
== text_specificEpithet
){
207 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
209 else if(eventSource
== text_uninomial
){
210 getEntity().setGenusOrUninomial(text_uninomial
.getText());
212 else if(eventSource
== checkbox_anamorphic
){
213 ((BotanicalName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
217 if(eventSource
!= toggleable_cache
&& !toggleable_cache
.getLayoutComposite().isDisposed()){
218 toggleable_cache
.setText(getEntity().getNameCache());
221 // we have to notify the parent if this is embedded in the nonviral name section
222 // maybe we can handle this a little bit more elegant
223 if(getParentElement() instanceof AbstractCdmDetailSection
)
224 firePropertyChangeEvent(new CdmPropertyChangeEvent(getParentElement(), null));
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.forms.SelectionArbitrator} object.
236 public SelectionArbitrator
getSelectionArbitrator() {
237 return selectionArbitrator
;