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 eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
15 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
16 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
17 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
18 import eu
.etaxonomy
.cdm
.model
.name
.ZoologicalName
;
19 import eu
.etaxonomy
.taxeditor
.preference
.IPreferenceKeys
;
20 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
21 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.NumberWithLabelElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
30 * AuthorshipDetailElement class.
34 * @created Mar 4, 2010
37 public class AuthorshipDetailElement
extends
38 AbstractIdentifiableEntityDetailElement
<NonViralName
> {
40 private EntitySelectionElement
<TeamOrPersonBase
> selectionExBasionymAuthor
;
41 private EntitySelectionElement
<TeamOrPersonBase
> selectionBasionymAuthor
;
42 private EntitySelectionElement
<TeamOrPersonBase
> selectionExCombinationAuthor
;
43 private EntitySelectionElement
<TeamOrPersonBase
> selectionCombinationAuthor
;
45 private NumberWithLabelElement text_publicationYear
;
46 private NumberWithLabelElement text_originalPublicationYear
;
49 * Constructor for AuthorshipDetailElement.
52 * @param cdmFormFactory
53 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
56 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
61 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory
,
62 ICdmFormElement formElement
, int style
) {
63 super(cdmFormFactory
, formElement
);
68 protected void createControls(ICdmFormElement formElement
,
69 NonViralName entity
, int style
) {
70 if (isAdvancedView
|| PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE
)){
71 toggleable_cache
= formFactory
.createToggleableTextField(this,
72 "Authorship Cache", entity
.getAuthorshipCache(),
73 entity
.isProtectedAuthorshipCache(), style
);
74 addElement(toggleable_cache
);
76 NomenclaturalCode code
= entity
.getNomenclaturalCode();
78 if (isAdvancedView
|| PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP
)){
79 selectionCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
80 getConversationHolder(),
81 formElement
, "Author",
82 entity
.getCombinationAuthorship(),
83 EntitySelectionElement
.ALL
, style
);
84 addElement(selectionCombinationAuthor
);
85 selectionExCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
86 getConversationHolder(),
87 formElement
, "Ex Author",
88 entity
.getExCombinationAuthorship(),
89 EntitySelectionElement
.ALL
, style
);
90 addElement(selectionExCombinationAuthor
);
92 if (code
.equals(NomenclaturalCode
.ICZN
)){
93 text_publicationYear
= formFactory
.createNumberTextWithLabelElement(formElement
, "Publication Year", ((ZoologicalName
)entity
).getPublicationYear(), style
);
97 selectionBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class, getConversationHolder(),
98 formElement
, "Basionym Author", entity
.getBasionymAuthorship(),
99 EntitySelectionElement
.ALL
, style
);
100 addElement(selectionBasionymAuthor
);
101 selectionExBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class, getConversationHolder(),
102 formElement
, "Ex Basionym Author",entity
.getExBasionymAuthorship(),
103 EntitySelectionElement
.ALL
, style
);
105 addElement(selectionExBasionymAuthor
);
107 if (code
.equals(NomenclaturalCode
.ICZN
)){
109 text_originalPublicationYear
= formFactory
.createNumberTextWithLabelElement(formElement
, "Orig. Publication Year", ((ZoologicalName
)entity
).getOriginalPublicationYear(), style
);
120 public void updateContent() {
121 if (getEntity() == null) {
122 setEntity(TaxonNameFactory
.NewNonViralInstance(null));
125 super.updateContent();
126 if (toggleable_cache
!= null){
127 toggleable_cache
.setEnabled(getEntity().isProtectedAuthorshipCache());
130 if (this.isIrrelevant()) {
131 setIrrelevant(isIrrelevant());
133 setIrrelevant(toggleable_cache
.getState(),
134 Arrays
.asList(new Object
[] { toggleable_cache
}));
141 public void handleEvent(Object eventSource
) {
142 if (eventSource
== toggleable_cache
) {
143 getEntity().setAuthorshipCache(toggleable_cache
.getText(),
144 toggleable_cache
.getState());
145 if (!isIrrelevant()){
146 setIrrelevant(toggleable_cache
.getState(),
147 Arrays
.asList(new Object
[] { toggleable_cache
}));
149 } else if (eventSource
== selectionCombinationAuthor
) {
150 getEntity().setCombinationAuthorship(
151 selectionCombinationAuthor
.getSelection());
152 } else if (eventSource
== selectionExCombinationAuthor
) {
153 getEntity().setExCombinationAuthorship(
154 selectionExCombinationAuthor
.getSelection());
155 } else if (eventSource
== selectionBasionymAuthor
) {
156 getEntity().setBasionymAuthorship(
157 selectionBasionymAuthor
.getSelection());
158 } else if (eventSource
== selectionExBasionymAuthor
) {
159 getEntity().setExBasionymAuthorship(
160 selectionExBasionymAuthor
.getSelection());
161 } else if (eventSource
== text_originalPublicationYear
) {
162 ((ZoologicalName
)getEntity()).setOriginalPublicationYear(text_originalPublicationYear
.getInteger());
163 } else if (eventSource
== text_publicationYear
) {
164 ((ZoologicalName
)getEntity()).setPublicationYear(text_publicationYear
.getInteger());
167 // if (eventSource != toggleable_cache) {
168 // toggleable_cache.setText(getEntity().getAuthorshipCache());
171 // we have to notify the parent if this is embedded in the nonviral name
173 // maybe we can handle this a little bit more elegant
174 // if (getParentElement() instanceof AbstractCdmDetailSection)
175 firePropertyChangeEvent(new CdmPropertyChangeEvent(
176 getParentElement(), null));
180 public void updateToggleableCacheField() {
181 if (toggleable_cache
!= null){
182 if(! getEntity().isProtectedAuthorshipCache()){
183 toggleable_cache
.setText(getEntity().getAuthorshipCache());