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
;
14 import java
.util
.Comparator
;
16 import org
.apache
.log4j
.Logger
;
17 import org
.eclipse
.swt
.SWT
;
19 import eu
.etaxonomy
.cdm
.model
.common
.TermType
;
20 import eu
.etaxonomy
.cdm
.model
.name
.IFungusName
;
21 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
22 import eu
.etaxonomy
.cdm
.model
.name
.IZoologicalName
;
23 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
24 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
25 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
26 import eu
.etaxonomy
.cdm
.strategy
.parser
.ParserProblem
;
27 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
28 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
29 import eu
.etaxonomy
.taxeditor
.ui
.combo
.TermComboElement
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
40 * <p>NameDetailElement class.</p>
43 * @created Feb 26, 2010
45 public class NameDetailElement
extends AbstractIdentifiableEntityDetailElement
<INonViralName
> 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
, INonViralName nonViralName
, int style
) {
81 Comparator
<Rank
> comparator
= null;
82 if(PreferencesUtil
.getSortRanksHierarchichally()){
83 comparator
= new Comparator
<Rank
>(){
86 public int compare(Rank o1
, Rank o2
) {
87 return o2
.compareTo(o1
);
93 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
95 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
, comparator
);
96 createGenusOrUninomialControls(this, nonViralName
, style
);
97 createInfragenerericEpithetControls(this, nonViralName
, style
);
98 createSpecificEpithetControls(this, nonViralName
, style
);
99 createInfraSpecificEpithetControls(this, nonViralName
, style
);
100 createSpecificNameParts(this, nonViralName
, style
);
101 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
103 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_NAMECACHE
)){
104 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
107 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_RANK
)){
108 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
, comparator
);
111 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_ATOMISED_EPITHETS
)){
112 createGenusOrUninomialControls(this, nonViralName
, style
);
113 createInfragenerericEpithetControls(this, nonViralName
, style
);
114 createSpecificEpithetControls(this, nonViralName
, style
);
115 createInfraSpecificEpithetControls(this, nonViralName
, style
);
116 createSpecificNameParts(this, nonViralName
, style
);
118 if (PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_APPENDED_PHRASE
)){
119 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
126 * <p>clearCheckRankWarnings</p>
128 protected void clearCheckRankWarnings() {
129 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
130 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
132 // FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
133 // TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
134 // nameEditor.getSelectedContainer().getNameViewer().clearErrors();
140 public void updateContent() {
141 if(getEntity() == null){
142 setEntity(TaxonNameFactory
.NewNonViralInstance(null));
145 super.updateContent();
146 if (toggleable_cache
!= null){
147 toggleable_cache
.setEnabled(getEntity().isProtectedNameCache());
151 setIrrelevant(isIrrelevant());
153 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
160 private void createSpecificNameParts(ICdmFormElement formElement
,
161 INonViralName nonViralName
, int style
) {
162 NomenclaturalCode code
= nonViralName
.getNomenclaturalCode();
164 switch(nonViralName
.getNomenclaturalCode()){
167 createBotanicalNameParts(formElement
, nonViralName
, style
);
171 createFungusNameParts(formElement
, nonViralName
, style
);
175 createZoologicalNameParts(formElement
, nonViralName
, style
);
179 logger
.warn("ICVCN not yet implemented");
183 logger
.warn("ICNB not yet implemented");
187 logger
.warn("ICNCP not yet implemented");
191 logger
.warn("NonViral not yet implemented");
198 private void createBotanicalNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
){
202 private void createFungusNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
){
203 IFungusName fungusName
= (IFungusName
)nonViralName
;
204 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", fungusName
.isAnamorphic(), style
);
207 private void createZoologicalNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
){
208 IZoologicalName zoologicalName
= (IZoologicalName
) nonViralName
;
211 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
215 private void createGenusOrUninomialControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
216 String title
= "Genus";
217 Rank rank
= nonViralName
.getRank();
218 if(rank
!= null && rank
.isSupraGeneric()){
221 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
224 private void createInfragenerericEpithetControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
225 if (nonViralName
.getNomenclaturalCode() == null || nonViralName
.getNomenclaturalCode().equals(NomenclaturalCode
.ICZN
)){
226 if(nonViralName
.getRank() != null && nonViralName
.getRank().isLower(Rank
.GENUS()) ){
227 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
230 if((nonViralName
.getRank() != null && nonViralName
.getRank().isLower(Rank
.GENUS())) && !nonViralName
.getRank().isLower(Rank
.SPECIES()) && !nonViralName
.getRank().isSpeciesAggregate()){
231 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
236 private void createSpecificEpithetControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
237 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
238 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
242 private void createInfraSpecificEpithetControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
243 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
244 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
250 public void handleEvent(Object eventSource
){
251 if (eventSource
== toggleable_cache
) {
252 getEntity().setNameCache(toggleable_cache
.getText(),
253 toggleable_cache
.getState());
254 //if (!isIrrelevant()) {
255 setIrrelevant(toggleable_cache
.getState(),
256 Arrays
.asList(new Object
[] { toggleable_cache
}));
259 else if(eventSource
== combo_rank
){
260 getEntity().setRank(combo_rank
.getSelection());
261 clearCheckRankWarnings();
264 else if(eventSource
== text_appendedPhrase
){
265 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
267 else if(eventSource
== text_infragenericEpithet
){
268 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
270 else if(eventSource
== text_infraspecificEpithet
){
271 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
273 else if(eventSource
== text_specificEpithet
){
274 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
276 else if(eventSource
== text_uninomial
){
277 getEntity().setGenusOrUninomial(text_uninomial
.getText());
279 else if(eventSource
== checkbox_anamorphic
){
280 ((IFungusName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
281 }else if(eventSource
== text_breed
){
282 ((IZoologicalName
)getEntity()).setBreed(text_breed
.getText());
289 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
292 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
294 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
297 public SelectionArbitrator
getSelectionArbitrator() {
298 return selectionArbitrator
;
302 public void updateToggleableCacheField() {
303 if (toggleable_cache
!= null){
304 if(! getEntity().isProtectedNameCache()){
305 toggleable_cache
.setText(getEntity().getNameCache());
311 protected void handleToggleableCacheField() {
312 boolean pushedState
= toggleable_cache
.getState();
314 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
315 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, text_appendedPhrase
, checkbox_anamorphic
}));
316 updateToggleableCacheField();
320 public void setIrrelevant(boolean irrelevant
, Collection
<Object
> except
){
321 if (toggleable_cache
!= null){
322 if (toggleable_cache
.getState() == irrelevant
){
323 super.setIrrelevant(irrelevant
, except
);
325 if (except
== null || except
.isEmpty()){
326 toggleable_cache
.setIrrelevant(irrelevant
);