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
.LabelElement
;
34 import eu
.etaxonomy
.taxeditor
.forms
.NumberWithLabelElement
;
35 import eu
.etaxonomy
.taxeditor
.forms
.SelectionArbitrator
;
36 import eu
.etaxonomy
.taxeditor
.forms
.TextWithLabelElement
;
37 import eu
.etaxonomy
.taxeditor
.forms
.ToggleableTextElement
;
38 import eu
.etaxonomy
.taxeditor
.forms
.term
.AbstractTermComboElement
;
39 import eu
.etaxonomy
.taxeditor
.section
.AbstractCdmDetailElement
;
40 import eu
.etaxonomy
.taxeditor
.section
.AbstractCdmDetailSection
;
43 * <p>NameDetailElement class.</p>
46 * @created Feb 26, 2010
49 public class NameDetailElement
extends AbstractCdmDetailElement
<NonViralName
> implements ISelectableElement
, IEnableableFormElement
{
51 private ToggleableTextElement toggleable_cache
;
52 private AbstractTermComboElement
<Rank
> combo_rank
;
53 private TextWithLabelElement text_appendedPhrase
;
54 private TextWithLabelElement text_uninomial
;
55 private TextWithLabelElement text_infragenericEpithet
;
56 private TextWithLabelElement text_specificEpithet
;
57 private TextWithLabelElement text_infraspecificEpithet
;
58 private SelectionArbitrator selectionArbitrator
;
59 private CheckboxElement checkbox_anamorphic
;
60 private TextWithLabelElement text_breed
;
61 private NumberWithLabelElement text_publicationYear
;
62 private NumberWithLabelElement text_originalPublicationYear
;
63 private int cursorPosition
;
66 * <p>Constructor for NameDetailElement.</p>
68 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.forms.CdmFormFactory} object.
69 * @param formElement a {@link eu.etaxonomy.taxeditor.forms.ICdmFormElement} object.
72 public NameDetailElement(CdmFormFactory cdmFormFactory
, ICdmFormElement formElement
,
74 super(cdmFormFactory
, formElement
);
75 // register as selection listener
76 if(cdmFormFactory
.getSelectionProvider() != null){
77 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
83 protected void createControls(ICdmFormElement formElement
, NonViralName nonViralName
, int style
) {
85 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
87 combo_rank
= formFactory
.createTermComboElement(TermComboType
.RANK
, this, "Rank", nonViralName
.getRank(), style
);
89 createGenusOrUninomialControls(this, nonViralName
, style
);
90 createInfragenerericEpithetControls(this, nonViralName
, style
);
91 createSpecificEpithetControls(this, nonViralName
, style
);
92 createInfraSpecificEpithetControls(this, nonViralName
, style
);
94 createSpecificNameParts(this, nonViralName
, style
);
96 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
101 * <p>clearCheckRankWarnings</p>
103 protected void clearCheckRankWarnings() {
104 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
105 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
107 TaxonNameEditor nameEditor
= (TaxonNameEditor
) EditorUtil
.getActiveEditorPage(Page
.NAME
);
108 nameEditor
.getSelectedObject().getNameViewer().clearErrors();
114 // public void setEnabled(boolean enabled){
115 // setEnabled(enabled, null);
120 protected void updateContent() {
121 if(getEntity() == null){
122 setEntity(NonViralName
.NewInstance(null));
125 super.updateContent();
128 setIrrelevant(isIrrelevant());
130 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
135 private void createSpecificNameParts(ICdmFormElement formElement
,
136 NonViralName nonViralName
, int style
) {
137 switch(nonViralName
.getNomenclaturalCode()){
139 createBotanicalNameParts(formElement
, nonViralName
, style
);
142 createZoologicalNameParts(formElement
, nonViralName
, style
);
147 private void createBotanicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
148 BotanicalName botanicalName
= (BotanicalName
) nonViralName
;
149 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", botanicalName
.isAnamorphic(), style
);
152 private void createZoologicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
153 ZoologicalName zoologicalName
= (ZoologicalName
) nonViralName
;
154 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
155 text_publicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Publication Year", zoologicalName
.getPublicationYear(), style
);
156 text_originalPublicationYear
= formFactory
.createIntegerTextWithLabelElement(formElement
, "Orig. Publication Year", zoologicalName
.getOriginalPublicationYear(), style
);
159 private void createGenusOrUninomialControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
160 String title
= "Genus";
161 Rank rank
= nonViralName
.getRank();
162 if(rank
!= null && rank
.isSupraGeneric()){
165 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
168 private void createInfragenerericEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
169 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraGeneric() && !nonViralName
.getRank().isSpeciesAggregate()){
170 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
174 private void createSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
175 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
176 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
180 private void createInfraSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
181 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
182 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
188 public void handleEvent(Object eventSource
){
189 if(eventSource
== combo_rank
){
190 getEntity().setRank(combo_rank
.getSelection());
191 clearCheckRankWarnings();
193 // logger.warn("Refreshing the details view at this stage may lead to 'Widget is disposed' errors. They can be ignored.");
195 EditorUtil
.refreshDetailsViewer();
196 getParentElement().getParentElement().getParentElement().refresh();
197 }catch(SWTException e
){
201 else if(eventSource
== text_appendedPhrase
){
202 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
204 else if(eventSource
== toggleable_cache
){
205 getEntity().setNameCache(toggleable_cache
.getText(), toggleable_cache
.getState());
206 //setEnabled(! text_nameCache.getState(), Arrays.asList(new Object[]{text_nameCache, combo_nomenclaturalCode}));
207 if(! isIrrelevant()) setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
209 else if(eventSource
== text_infragenericEpithet
){
210 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
212 else if(eventSource
== text_infraspecificEpithet
){
213 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
215 else if(eventSource
== text_specificEpithet
){
216 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
218 else if(eventSource
== text_uninomial
){
219 getEntity().setGenusOrUninomial(text_uninomial
.getText());
221 else if(eventSource
== checkbox_anamorphic
){
222 ((BotanicalName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
226 if(eventSource
!= toggleable_cache
&& !toggleable_cache
.getLayoutComposite().isDisposed()){
227 toggleable_cache
.setText(getEntity().getNameCache());
230 // we have to notify the parent if this is embedded in the nonviral name section
231 // maybe we can handle this a little bit more elegant
232 if(getParentElement() instanceof AbstractCdmDetailSection
)
233 firePropertyChangeEvent(new CdmPropertyChangeEvent(getParentElement(), null));
238 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
241 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
243 * @return a {@link eu.etaxonomy.taxeditor.forms.SelectionArbitrator} object.
245 public SelectionArbitrator
getSelectionArbitrator() {
246 return selectionArbitrator
;