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
.IFungusName
;
20 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
21 import eu
.etaxonomy
.cdm
.model
.name
.IZoologicalName
;
22 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
23 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
24 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
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
44 public class NameDetailElement
extends AbstractIdentifiableEntityDetailElement
<INonViralName
> implements ISelectableElement
, IEnableableFormElement
{
46 private final Logger logger
= Logger
.getLogger(NameDetailElement
.class);
48 private TermComboElement
<Rank
> combo_rank
;
49 private TextWithLabelElement text_appendedPhrase
;
50 private TextWithLabelElement text_uninomial
;
51 private TextWithLabelElement text_infragenericEpithet
;
52 private TextWithLabelElement text_specificEpithet
;
53 private TextWithLabelElement text_infraspecificEpithet
;
54 private SelectionArbitrator selectionArbitrator
;
55 private CheckboxElement checkbox_anamorphic
;
56 private TextWithLabelElement text_breed
;
57 //private NumberWithLabelElement text_publicationYear;
58 //private NumberWithLabelElement text_originalPublicationYear;
59 private int cursorPosition
;
62 * <p>Constructor for NameDetailElement.</p>
64 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
65 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
68 public NameDetailElement(CdmFormFactory cdmFormFactory
, ICdmFormElement formElement
,
70 super(cdmFormFactory
, formElement
);
71 // make this element selectable
72 if(cdmFormFactory
.getSelectionProvider() != null){
73 selectionArbitrator
= cdmFormFactory
.createSelectionArbitrator(this);
79 protected void createControls(ICdmFormElement formElement
, INonViralName nonViralName
, int style
) {
82 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
83 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
);
84 createGenusOrUninomialControls(this, nonViralName
, style
);
85 createInfragenerericEpithetControls(this, nonViralName
, style
);
86 createSpecificEpithetControls(this, nonViralName
, style
);
87 createInfraSpecificEpithetControls(this, nonViralName
, style
);
88 createSpecificNameParts(this, nonViralName
, style
);
89 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
91 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_NAMECACHE
)){
92 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
95 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_RANK
)){
96 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
);
99 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS
)){
100 createGenusOrUninomialControls(this, nonViralName
, style
);
101 createInfragenerericEpithetControls(this, nonViralName
, style
);
102 createSpecificEpithetControls(this, nonViralName
, style
);
103 createInfraSpecificEpithetControls(this, nonViralName
, style
);
104 createSpecificNameParts(this, nonViralName
, style
);
106 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE
)){
107 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
114 * <p>clearCheckRankWarnings</p>
116 protected void clearCheckRankWarnings() {
117 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
118 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
120 // FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
121 // TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
122 // nameEditor.getSelectedContainer().getNameViewer().clearErrors();
128 protected void updateContent() {
129 if(getEntity() == null){
130 setEntity(TaxonNameFactory
.NewNonViralInstance(null));
133 super.updateContent();
134 if (toggleable_cache
!= null){
135 toggleable_cache
.setEnabled(getEntity().isProtectedNameCache());
139 setIrrelevant(isIrrelevant());
141 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
148 private void createSpecificNameParts(ICdmFormElement formElement
,
149 INonViralName nonViralName
, int style
) {
150 NomenclaturalCode code
= nonViralName
.getNomenclaturalCode();
152 switch(nonViralName
.getNomenclaturalCode()){
155 createBotanicalNameParts(formElement
, nonViralName
, style
);
159 createFungusNameParts(formElement
, nonViralName
, style
);
163 createZoologicalNameParts(formElement
, nonViralName
, style
);
167 logger
.warn("ICVCN not yet implemented");
171 logger
.warn("ICNB not yet implemented");
175 logger
.warn("ICNCP not yet implemented");
179 logger
.warn("NonViral not yet implemented");
186 private void createBotanicalNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
){
190 private void createFungusNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
){
191 IFungusName fungusName
= (IFungusName
)nonViralName
;
192 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", fungusName
.isAnamorphic(), style
);
195 private void createZoologicalNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
){
196 IZoologicalName zoologicalName
= (IZoologicalName
) nonViralName
;
199 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
203 private void createGenusOrUninomialControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
204 String title
= "Genus";
205 Rank rank
= nonViralName
.getRank();
206 if(rank
!= null && rank
.isSupraGeneric()){
209 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
212 private void createInfragenerericEpithetControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
213 if (nonViralName
.getNomenclaturalCode() == null || nonViralName
.getNomenclaturalCode().equals(NomenclaturalCode
.ICZN
)){
214 if(nonViralName
.getRank() != null && nonViralName
.getRank().isLower(Rank
.GENUS()) ){
215 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
218 if((nonViralName
.getRank() != null && nonViralName
.getRank().isLower(Rank
.GENUS())) && !nonViralName
.getRank().isLower(Rank
.SPECIES()) && !nonViralName
.getRank().isSpeciesAggregate()){
219 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
224 private void createSpecificEpithetControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
225 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
226 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
230 private void createInfraSpecificEpithetControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
231 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
232 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
238 public void handleEvent(Object eventSource
){
239 if (eventSource
== toggleable_cache
) {
240 getEntity().setNameCache(toggleable_cache
.getText(),
241 toggleable_cache
.getState());
242 //if (!isIrrelevant()) {
243 setIrrelevant(toggleable_cache
.getState(),
244 Arrays
.asList(new Object
[] { toggleable_cache
}));
247 else if(eventSource
== combo_rank
){
248 getEntity().setRank(combo_rank
.getSelection());
249 clearCheckRankWarnings();
252 else if(eventSource
== text_appendedPhrase
){
253 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
255 else if(eventSource
== text_infragenericEpithet
){
256 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
258 else if(eventSource
== text_infraspecificEpithet
){
259 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
261 else if(eventSource
== text_specificEpithet
){
262 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
264 else if(eventSource
== text_uninomial
){
265 getEntity().setGenusOrUninomial(text_uninomial
.getText());
267 else if(eventSource
== checkbox_anamorphic
){
268 ((IFungusName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
269 }else if(eventSource
== text_breed
){
270 ((IZoologicalName
)getEntity()).setBreed(text_breed
.getText());
277 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
280 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
282 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
285 public SelectionArbitrator
getSelectionArbitrator() {
286 return selectionArbitrator
;
290 public void updateToggleableCacheField() {
291 if (toggleable_cache
!= null){
292 if(! getEntity().isProtectedNameCache()){
293 toggleable_cache
.setText(getEntity().getNameCache());
299 protected void handleToggleableCacheField() {
300 boolean pushedState
= toggleable_cache
.getState();
302 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
303 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, text_appendedPhrase
, checkbox_anamorphic
}));
304 updateToggleableCacheField();
308 public void setIrrelevant(boolean irrelevant
, Collection
<Object
> except
){
309 if (toggleable_cache
!= null){
310 if (toggleable_cache
.getState() == irrelevant
){
311 super.setIrrelevant(irrelevant
, except
);
313 if (except
== null || except
.isEmpty()){
314 toggleable_cache
.setIrrelevant(irrelevant
);