2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
6 * The contents of this file are subject to the Mozilla Public License Version 1.1
7 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
12 import java
.util
.Arrays
;
14 import org
.apache
.log4j
.Logger
;
15 import org
.eclipse
.swt
.SWT
;
17 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
18 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
19 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
21 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
22 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
23 import eu
.etaxonomy
.cdm
.strategy
.parser
.ParserProblem
;
24 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
25 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
26 import eu
.etaxonomy
.taxeditor
.ui
.combo
.TermComboElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
37 * <p>NameDetailElement class.</p>
40 * @created Feb 26, 2010
43 public class NameDetailElement
extends AbstractIdentifiableEntityDetailElement
<NonViralName
> implements ISelectableElement
, IEnableableFormElement
{
45 private final Logger logger
= Logger
.getLogger(NameDetailElement
.class);
47 private TermComboElement
<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.element.CdmFormFactory} object.
64 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
67 public NameDetailElement(CdmFormFactory cdmFormFactory
, ICdmFormElement formElement
,
69 super(cdmFormFactory
, formElement
);
70 // make this element selectable
71 if(cdmFormFactory
.getSelectionProvider() != null){
72 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
78 protected void createControls(ICdmFormElement formElement
, NonViralName nonViralName
, int style
) {
81 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
82 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
);
83 createGenusOrUninomialControls(this, nonViralName
, style
);
84 createInfragenerericEpithetControls(this, nonViralName
, style
);
85 createSpecificEpithetControls(this, nonViralName
, style
);
86 createInfraSpecificEpithetControls(this, nonViralName
, style
);
87 createSpecificNameParts(this, nonViralName
, style
);
88 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
90 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_NAMECACHE
)){
91 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
94 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_RANK
)){
95 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
);
98 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS
)){
99 createGenusOrUninomialControls(this, nonViralName
, style
);
100 createInfragenerericEpithetControls(this, nonViralName
, style
);
101 createSpecificEpithetControls(this, nonViralName
, style
);
102 createInfraSpecificEpithetControls(this, nonViralName
, style
);
103 createSpecificNameParts(this, nonViralName
, style
);
105 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE
)){
106 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
112 * <p>clearCheckRankWarnings</p>
114 protected void clearCheckRankWarnings() {
115 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
116 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
118 // FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
119 // TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
120 // nameEditor.getSelectedContainer().getNameViewer().clearErrors();
126 protected void updateContent() {
127 if(getEntity() == null){
128 setEntity(NonViralName
.NewInstance(null));
131 super.updateContent();
134 setIrrelevant(isIrrelevant());
136 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
142 private void createSpecificNameParts(ICdmFormElement formElement
,
143 NonViralName nonViralName
, int style
) {
144 NomenclaturalCode code
= nonViralName
.getNomenclaturalCode();
146 switch(nonViralName
.getNomenclaturalCode()){
149 if(!PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
) && isAdvancedView
)
151 createBotanicalNameParts(formElement
, nonViralName
, style
);
155 createZoologicalNameParts(formElement
, nonViralName
, style
);
159 logger
.warn("ICVCN not yet implemented");
163 logger
.warn("ICNB not yet implemented");
167 logger
.warn("ICNCP not yet implemented");
173 private void createBotanicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
174 BotanicalName botanicalName
= (BotanicalName
) nonViralName
;
175 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", botanicalName
.isAnamorphic(), style
);
178 private void createZoologicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
179 ZoologicalName zoologicalName
= (ZoologicalName
) nonViralName
;
182 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
186 private void createGenusOrUninomialControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
187 String title
= "Genus";
188 Rank rank
= nonViralName
.getRank();
189 if(rank
!= null && rank
.isSupraGeneric()){
192 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
195 private void createInfragenerericEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
196 if (nonViralName
.getNomenclaturalCode() == null || nonViralName
.getNomenclaturalCode().equals(NomenclaturalCode
.ICZN
)){
197 if(nonViralName
.getRank() != null && nonViralName
.getRank().isLower(Rank
.GENUS()) ){
198 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
201 if((nonViralName
.getRank() != null && nonViralName
.getRank().isLower(Rank
.GENUS())) && !nonViralName
.getRank().isLower(Rank
.SPECIES()) && !nonViralName
.getRank().isSpeciesAggregate()){
202 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
207 private void createSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
208 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
209 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
213 private void createInfraSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
214 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
215 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
221 public void handleEvent(Object eventSource
){
222 if (eventSource
== toggleable_cache
) {
223 getEntity().setNameCache(toggleable_cache
.getText(),
224 toggleable_cache
.getState());
225 if (!isIrrelevant()) {
226 setIrrelevant(toggleable_cache
.getState(),
227 Arrays
.asList(new Object
[] { toggleable_cache
}));
230 else if(eventSource
== combo_rank
){
231 getEntity().setRank(combo_rank
.getSelection());
232 clearCheckRankWarnings();
235 else if(eventSource
== text_appendedPhrase
){
236 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
238 else if(eventSource
== text_infragenericEpithet
){
239 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
241 else if(eventSource
== text_infraspecificEpithet
){
242 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
244 else if(eventSource
== text_specificEpithet
){
245 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
247 else if(eventSource
== text_uninomial
){
248 getEntity().setGenusOrUninomial(text_uninomial
.getText());
250 else if(eventSource
== checkbox_anamorphic
){
251 ((BotanicalName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
252 }else if(eventSource
== text_breed
){
253 ((ZoologicalName
)getEntity()).setBreed(text_breed
.getText());
260 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
263 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
265 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
268 public SelectionArbitrator
getSelectionArbitrator() {
269 return selectionArbitrator
;
273 public void updateToggleableCacheField() {
274 if (toggleable_cache
!= null){
275 if(! getEntity().isProtectedNameCache()){
276 toggleable_cache
.setText(getEntity().getNameCache());
282 protected void handleToggleableCacheField() {
283 boolean pushedState
= toggleable_cache
.getState();
285 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
286 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, text_appendedPhrase
, checkbox_anamorphic
}));
287 updateToggleableCacheField();