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
;
13 import java
.util
.Collection
;
15 import org
.apache
.log4j
.Logger
;
16 import org
.eclipse
.swt
.SWT
;
18 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
19 import eu
.etaxonomy
.cdm
.model
.name
.BotanicalName
;
20 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
21 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
22 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
23 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
24 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
25 import eu
.etaxonomy
.cdm
.strategy
.parser
.ParserProblem
;
26 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
27 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
28 import eu
.etaxonomy
.taxeditor
.ui
.combo
.TermComboElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
39 * <p>NameDetailElement class.</p>
42 * @created Feb 26, 2010
45 public class NameDetailElement
extends AbstractIdentifiableEntityDetailElement
<NonViralName
> implements ISelectableElement
, IEnableableFormElement
{
47 private final Logger logger
= Logger
.getLogger(NameDetailElement
.class);
49 private TermComboElement
<Rank
> combo_rank
;
50 private TextWithLabelElement text_appendedPhrase
;
51 private TextWithLabelElement text_uninomial
;
52 private TextWithLabelElement text_infragenericEpithet
;
53 private TextWithLabelElement text_specificEpithet
;
54 private TextWithLabelElement text_infraspecificEpithet
;
55 private SelectionArbitrator selectionArbitrator
;
56 private CheckboxElement checkbox_anamorphic
;
57 private TextWithLabelElement text_breed
;
58 //private NumberWithLabelElement text_publicationYear;
59 //private NumberWithLabelElement text_originalPublicationYear;
60 private int cursorPosition
;
63 * <p>Constructor for NameDetailElement.</p>
65 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
66 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
69 public NameDetailElement(CdmFormFactory cdmFormFactory
, ICdmFormElement formElement
,
71 super(cdmFormFactory
, formElement
);
72 // make this element selectable
73 if(cdmFormFactory
.getSelectionProvider() != null){
74 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
80 protected void createControls(ICdmFormElement formElement
, NonViralName nonViralName
, int style
) {
83 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
84 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
);
85 createGenusOrUninomialControls(this, nonViralName
, style
);
86 createInfragenerericEpithetControls(this, nonViralName
, style
);
87 createSpecificEpithetControls(this, nonViralName
, style
);
88 createInfraSpecificEpithetControls(this, nonViralName
, style
);
89 createSpecificNameParts(this, nonViralName
, style
);
90 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
92 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_NAMECACHE
)){
93 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
96 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_RANK
)){
97 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
);
100 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS
)){
101 createGenusOrUninomialControls(this, nonViralName
, style
);
102 createInfragenerericEpithetControls(this, nonViralName
, style
);
103 createSpecificEpithetControls(this, nonViralName
, style
);
104 createInfraSpecificEpithetControls(this, nonViralName
, style
);
105 createSpecificNameParts(this, nonViralName
, style
);
107 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE
)){
108 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
115 * <p>clearCheckRankWarnings</p>
117 protected void clearCheckRankWarnings() {
118 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
119 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
121 // FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
122 // TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
123 // nameEditor.getSelectedContainer().getNameViewer().clearErrors();
129 protected void updateContent() {
130 if(getEntity() == null){
131 setEntity(TaxonNameFactory
.NewNonViralInstance(null));
134 super.updateContent();
135 if (toggleable_cache
!= null){
136 toggleable_cache
.setEnabled(getEntity().isProtectedNameCache());
140 setIrrelevant(isIrrelevant());
142 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
149 private void createSpecificNameParts(ICdmFormElement formElement
,
150 NonViralName nonViralName
, int style
) {
151 NomenclaturalCode code
= nonViralName
.getNomenclaturalCode();
153 switch(nonViralName
.getNomenclaturalCode()){
158 createBotanicalNameParts(formElement
, nonViralName
, style
);
162 createZoologicalNameParts(formElement
, nonViralName
, style
);
166 logger
.warn("ICVCN not yet implemented");
170 logger
.warn("ICNB not yet implemented");
174 logger
.warn("ICNCP not yet implemented");
180 private void createBotanicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
181 BotanicalName botanicalName
= (BotanicalName
) nonViralName
;
182 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", botanicalName
.isAnamorphic(), style
);
185 private void createZoologicalNameParts(ICdmFormElement formElement
, NonViralName nonViralName
, int style
){
186 ZoologicalName zoologicalName
= (ZoologicalName
) nonViralName
;
189 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
193 private void createGenusOrUninomialControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
194 String title
= "Genus";
195 Rank rank
= nonViralName
.getRank();
196 if(rank
!= null && rank
.isSupraGeneric()){
199 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
202 private void createInfragenerericEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
203 if (nonViralName
.getNomenclaturalCode() == null || nonViralName
.getNomenclaturalCode().equals(NomenclaturalCode
.ICZN
)){
204 if(nonViralName
.getRank() != null && nonViralName
.getRank().isLower(Rank
.GENUS()) ){
205 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
208 if((nonViralName
.getRank() != null && nonViralName
.getRank().isLower(Rank
.GENUS())) && !nonViralName
.getRank().isLower(Rank
.SPECIES()) && !nonViralName
.getRank().isSpeciesAggregate()){
209 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
214 private void createSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
215 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
216 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
220 private void createInfraSpecificEpithetControls(ICdmFormElement element
, NonViralName nonViralName
, int style
){
221 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
222 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
228 public void handleEvent(Object eventSource
){
229 if (eventSource
== toggleable_cache
) {
230 getEntity().setNameCache(toggleable_cache
.getText(),
231 toggleable_cache
.getState());
232 //if (!isIrrelevant()) {
233 setIrrelevant(toggleable_cache
.getState(),
234 Arrays
.asList(new Object
[] { toggleable_cache
}));
237 else if(eventSource
== combo_rank
){
238 getEntity().setRank(combo_rank
.getSelection());
239 clearCheckRankWarnings();
242 else if(eventSource
== text_appendedPhrase
){
243 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
245 else if(eventSource
== text_infragenericEpithet
){
246 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
248 else if(eventSource
== text_infraspecificEpithet
){
249 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
251 else if(eventSource
== text_specificEpithet
){
252 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
254 else if(eventSource
== text_uninomial
){
255 getEntity().setGenusOrUninomial(text_uninomial
.getText());
257 else if(eventSource
== checkbox_anamorphic
){
258 ((BotanicalName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
259 }else if(eventSource
== text_breed
){
260 ((ZoologicalName
)getEntity()).setBreed(text_breed
.getText());
267 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
270 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
272 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
275 public SelectionArbitrator
getSelectionArbitrator() {
276 return selectionArbitrator
;
280 public void updateToggleableCacheField() {
281 if (toggleable_cache
!= null){
282 if(! getEntity().isProtectedNameCache()){
283 toggleable_cache
.setText(getEntity().getNameCache());
289 protected void handleToggleableCacheField() {
290 boolean pushedState
= toggleable_cache
.getState();
292 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
293 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, text_appendedPhrase
, checkbox_anamorphic
}));
294 updateToggleableCacheField();
298 public void setIrrelevant(boolean irrelevant
, Collection
<Object
> except
){
299 if (toggleable_cache
!= null){
300 if (toggleable_cache
.getState() == irrelevant
){
301 super.setIrrelevant(irrelevant
, except
);
303 if (except
== null || except
.isEmpty()){
304 toggleable_cache
.setIrrelevant(irrelevant
);