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
.name
.IBacterialName
;
20 import eu
.etaxonomy
.cdm
.model
.name
.ICultivarPlantName
;
21 import eu
.etaxonomy
.cdm
.model
.name
.IFungusName
;
22 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
23 import eu
.etaxonomy
.cdm
.model
.name
.IZoologicalName
;
24 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
25 import eu
.etaxonomy
.cdm
.model
.name
.Rank
;
26 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
27 import eu
.etaxonomy
.cdm
.model
.term
.TermType
;
28 import eu
.etaxonomy
.cdm
.strategy
.parser
.ParserProblem
;
29 import eu
.etaxonomy
.taxeditor
.preference
.NameDetailsConfigurator
;
30 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
31 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
32 import eu
.etaxonomy
.taxeditor
.ui
.combo
.term
.TermComboElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.element
.IEnableableFormElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
38 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
39 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
40 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
43 * <p>NameDetailElement class.</p>
46 * @created Feb 26, 2010
48 public class NameDetailElement
extends AbstractIdentifiableEntityDetailElement
<INonViralName
> implements ISelectableElement
, IEnableableFormElement
{
50 private final Logger logger
= Logger
.getLogger(NameDetailElement
.class);
52 private TermComboElement
<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_cultivarName
;
61 private TextWithLabelElement text_subGenusAuthorship
;
63 private TextWithLabelElement text_breed
;
64 //private NumberWithLabelElement text_publicationYear;
65 //private NumberWithLabelElement text_originalPublicationYear;
66 private int cursorPosition
;
68 NameDetailsConfigurator config
;
71 * <p>Constructor for NameDetailElement.</p>
73 * @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
74 * @param formElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
77 public NameDetailElement(CdmFormFactory cdmFormFactory
, ICdmFormElement formElement
,
79 super(cdmFormFactory
, formElement
);
80 // make this element selectable
87 protected void createControls(ICdmFormElement formElement
, INonViralName nonViralName
, int style
) {
88 Comparator
<Rank
> comparator
= null;
89 config
= PreferencesUtil
.getPreferredNameDetailsConfiguration();
91 if(PreferencesUtil
.getSortRanksHierarchichally()){
92 comparator
= new Comparator
<Rank
>(){
95 public int compare(Rank o1
, Rank o2
) {
96 return o2
.compareTo(o1
);
102 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
104 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
, comparator
);
105 createGenusOrUninomialControls(this, nonViralName
, style
);
106 createInfragenerericEpithetControls(this, nonViralName
, style
);
107 createSpecificEpithetControls(this, nonViralName
, style
);
108 createInfraSpecificEpithetControls(this, nonViralName
, style
);
109 createSpecificNameParts(this, nonViralName
, style
);
110 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
112 if (config
.isNameCacheActivated()){
113 toggleable_cache
= formFactory
.createToggleableTextField(this, "Name Cache", nonViralName
.getNameCache(), nonViralName
.isProtectedNameCache(), style
);
116 if (config
.isRankActivated()){
117 combo_rank
= formFactory
.createDefinedTermComboElement(TermType
.Rank
, this, "Rank", nonViralName
.getRank(), style
, comparator
);
120 if (config
.isAtomisedEpithetsActivated()){
121 createGenusOrUninomialControls(this, nonViralName
, style
);
122 createInfragenerericEpithetControls(this, nonViralName
, style
);
123 createSpecificEpithetControls(this, nonViralName
, style
);
124 createInfraSpecificEpithetControls(this, nonViralName
, style
);
125 createSpecificNameParts(this, nonViralName
, style
);
127 if (config
.isAppendedPhraseActivated()){
128 text_appendedPhrase
= formFactory
.createTextWithLabelElement(formElement
, "Appended Phrase", nonViralName
.getAppendedPhrase(), style
);
131 if(this.getFormFactory().getSelectionProvider() != null){
132 selectionArbitrator
= this.getFormFactory().createSelectionArbitrator(this);
134 for (ICdmFormElement element
: this.getElements()){
135 element
.setBackground(getPersistentBackground());
141 * <p>clearCheckRankWarnings</p>
143 protected void clearCheckRankWarnings() {
144 if(getEntity().hasProblem(ParserProblem
.CheckRank
)){
145 getEntity().removeParsingProblem(ParserProblem
.CheckRank
);
147 // FIXME this has to be reafctored completely. See tickets #1959, #1663, #1957, #1958
148 // TaxonNameEditor nameEditor = (TaxonNameEditor) EditorUtil.getActiveEditorPage(Page.NAME);
149 // nameEditor.getSelectedContainer().getNameViewer().clearErrors();
155 public void updateContent() {
156 if(getEntity() == null){
157 setEntity(TaxonNameFactory
.NewNonViralInstance(null));
160 super.updateContent();
161 if (toggleable_cache
!= null){
162 toggleable_cache
.setEnabled(getEntity().isProtectedNameCache());
166 setIrrelevant(isIrrelevant());
168 setIrrelevant(toggleable_cache
.getState(), Arrays
.asList(new Object
[]{toggleable_cache
}));
175 private void createSpecificNameParts(ICdmFormElement formElement
,
176 INonViralName nonViralName
, int style
) {
177 NomenclaturalCode code
= nonViralName
.getNameType();
182 createBotanicalNameParts(formElement
, nonViralName
, style
);
186 createFungusNameParts(formElement
, nonViralName
, style
);
190 createZoologicalNameParts(formElement
, nonViralName
, style
);
194 logger
.warn("ICVCN not yet implemented");
197 createBacterialNameParts(formElement
, nonViralName
, style
);
200 createCultivarNameParts(formElement
, nonViralName
, style
);
204 logger
.warn("NonViral not yet implemented");
211 private void createBacterialNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
) {
212 IBacterialName bacterialName
= (IBacterialName
) nonViralName
;
213 text_subGenusAuthorship
= formFactory
.createTextWithLabelElement(formElement
, "Subgenus Authorship", bacterialName
.getSubGenusAuthorship(), style
);
214 // text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", bacterialName.getNameApprobation(), style);
218 private void createCultivarNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
) {
219 ICultivarPlantName cultivarName
= (ICultivarPlantName
)nonViralName
;
220 text_cultivarName
= formFactory
.createTextWithLabelElement(formElement
, "Cultivar Name", cultivarName
.getCultivarName(), style
);
224 private void createBotanicalNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
){
228 private void createFungusNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
){
229 IFungusName fungusName
= (IFungusName
)nonViralName
;
230 checkbox_anamorphic
= formFactory
.createCheckbox(formElement
, "Anamorphic", fungusName
.isAnamorphic(), style
);
233 private void createZoologicalNameParts(ICdmFormElement formElement
, INonViralName nonViralName
, int style
){
234 IZoologicalName zoologicalName
= (IZoologicalName
) nonViralName
;
237 text_breed
= formFactory
.createTextWithLabelElement(formElement
, "Breed", zoologicalName
.getBreed(), style
);
241 private void createGenusOrUninomialControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
242 String title
= "Genus";
243 Rank rank
= nonViralName
.getRank();
244 if(rank
!= null && rank
.isSupraGeneric()){
247 text_uninomial
= formFactory
.createTextWithLabelElement(element
, title
, nonViralName
.getGenusOrUninomial(), style
);
250 private void createInfragenerericEpithetControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
251 if (nonViralName
.getNameType() == null || nonViralName
.getNameType().equals(NomenclaturalCode
.ICZN
)){
252 if(nonViralName
.getRank() != null && nonViralName
.getRank().isLower(Rank
.GENUS()) ){
253 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
256 if((nonViralName
.getRank() != null && nonViralName
.getRank().isLower(Rank
.GENUS())) && !nonViralName
.getRank().isLower(Rank
.SPECIES()) && !nonViralName
.getRank().isSpeciesAggregate()){
257 text_infragenericEpithet
= formFactory
.createTextWithLabelElement(element
, "Infrageneric Epithet", nonViralName
.getInfraGenericEpithet(), style
);
262 private void createSpecificEpithetControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
263 if(nonViralName
.getRank() != null && (nonViralName
.getRank().isSpecies() || nonViralName
.getRank().isInfraSpecific() || nonViralName
.getRank().isSpeciesAggregate())){
264 text_specificEpithet
= formFactory
.createTextWithLabelElement(element
, "Specific Epithet", nonViralName
.getSpecificEpithet(), SWT
.NULL
);
268 private void createInfraSpecificEpithetControls(ICdmFormElement element
, INonViralName nonViralName
, int style
){
269 if(nonViralName
.getRank() != null && nonViralName
.getRank().isInfraSpecific()){
270 text_infraspecificEpithet
= formFactory
.createTextWithLabelElement(element
, "Infraspecific Epithet", nonViralName
.getInfraSpecificEpithet(), SWT
.NULL
);
276 public void handleEvent(Object eventSource
){
277 if (eventSource
== toggleable_cache
) {
278 getEntity().setNameCache(toggleable_cache
.getText(),
279 toggleable_cache
.getState());
280 //if (!isIrrelevant()) {
281 setIrrelevant(toggleable_cache
.getState(),
282 Arrays
.asList(new Object
[] { toggleable_cache
}));
285 else if(eventSource
== combo_rank
){
286 getEntity().setRank(combo_rank
.getSelection());
287 clearCheckRankWarnings();
289 //this is needed for the "new" wizards in order to redraw correctly
290 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
292 else if(eventSource
== text_appendedPhrase
){
293 getEntity().setAppendedPhrase(text_appendedPhrase
.getText());
295 else if(eventSource
== text_infragenericEpithet
){
296 getEntity().setInfraGenericEpithet(text_infragenericEpithet
.getText());
298 else if(eventSource
== text_infraspecificEpithet
){
299 getEntity().setInfraSpecificEpithet(text_infraspecificEpithet
.getText());
301 else if(eventSource
== text_specificEpithet
){
302 getEntity().setSpecificEpithet(text_specificEpithet
.getText());
304 else if(eventSource
== text_uninomial
){
305 getEntity().setGenusOrUninomial(text_uninomial
.getText());
307 else if(eventSource
== checkbox_anamorphic
){
308 ((IFungusName
)getEntity()).setAnamorphic(checkbox_anamorphic
.getSelection());
309 }else if(eventSource
== text_breed
){
310 ((IZoologicalName
)getEntity()).setBreed(text_breed
.getText());
311 }else if(eventSource
== this.text_cultivarName
){
312 ((ICultivarPlantName
)getEntity()).setCultivarName(text_cultivarName
.getText());
313 }else if(eventSource
== this.text_subGenusAuthorship
){
314 ((IBacterialName
)getEntity()).setSubGenusAuthorship(text_subGenusAuthorship
.getText());
321 * @see eu.etaxonomy.taxeditor.forms.section.cdmdetail.ISelectableElement#getSelectionArbitrator()
324 * <p>Getter for the field <code>selectionArbitrator</code>.</p>
326 * @return a {@link eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator} object.
329 public SelectionArbitrator
getSelectionArbitrator() {
330 return selectionArbitrator
;
334 public void updateToggleableCacheField() {
335 if (toggleable_cache
!= null){
336 if(! getEntity().isProtectedNameCache()){
337 toggleable_cache
.setText(getEntity().getNameCache());
343 protected void handleToggleableCacheField() {
344 boolean pushedState
= toggleable_cache
.getState();
346 getEntity().setTitleCache(toggleable_cache
.getText(), pushedState
);
347 setIrrelevant(pushedState
, Arrays
.asList(new Object
[] { toggleable_cache
, text_appendedPhrase
, checkbox_anamorphic
}));
348 updateToggleableCacheField();
352 public void setIrrelevant(boolean irrelevant
, Collection
<Object
> except
){
353 if (toggleable_cache
!= null){
354 if (toggleable_cache
.getState() == irrelevant
){
355 super.setIrrelevant(irrelevant
, except
);
357 if (except
== null || except
.isEmpty()){
358 toggleable_cache
.setIrrelevant(irrelevant
);