3 * Copyright (C) 2007 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
11 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
13 import java
.util
.Arrays
;
15 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
16 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
17 import eu
.etaxonomy
.cdm
.model
.name
.NonViralName
;
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
) {
71 toggleable_cache
= formFactory
.createToggleableTextField(this,
72 "Authorship Cache", entity
.getAuthorshipCache(),
73 entity
.isProtectedAuthorshipCache(), style
);
75 if(PreferencesUtil
.getPreferenceStore().getBoolean(IPreferenceKeys
.IS_RL
)){
76 toggleable_cache
.setVisible(false);
79 NomenclaturalCode code
= entity
.getNomenclaturalCode();
81 selectionCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
82 getConversationHolder(),
83 formElement
, "Author",
84 entity
.getCombinationAuthorship(),
85 EntitySelectionElement
.ALL
, style
);
86 addElement(selectionCombinationAuthor
);
87 selectionExCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
88 getConversationHolder(),
89 formElement
, "Ex Author",
90 entity
.getExCombinationAuthorship(),
91 EntitySelectionElement
.ALL
, style
);
92 addElement(selectionExCombinationAuthor
);
94 if (code
.equals(NomenclaturalCode
.ICZN
)){
95 text_publicationYear
= formFactory
.createNumberTextWithLabelElement(formElement
, "Publication Year", ((ZoologicalName
)entity
).getPublicationYear(), style
);
99 selectionBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class, getConversationHolder(),
100 formElement
, "Basionym Author", entity
.getBasionymAuthorship(),
101 EntitySelectionElement
.ALL
, style
);
102 addElement(selectionBasionymAuthor
);
103 selectionExBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class, getConversationHolder(),
104 formElement
, "Ex Basionym Author", entity
.getExBasionymAuthorship(),
105 EntitySelectionElement
.ALL
, style
);
107 addElement(selectionExBasionymAuthor
);
109 if (code
.equals(NomenclaturalCode
.ICZN
)){
111 text_originalPublicationYear
= formFactory
.createNumberTextWithLabelElement(formElement
, "Orig. Publication Year", ((ZoologicalName
)entity
).getOriginalPublicationYear(), style
);
122 public void updateContent() {
123 if (getEntity() == null) {
124 setEntity(NonViralName
.NewInstance(null));
127 super.updateContent();
128 if (toggleable_cache
!= null){
129 toggleable_cache
.setEnabled(getEntity().isProtectedAuthorshipCache());
132 if (this.isIrrelevant()) {
133 setIrrelevant(isIrrelevant());
135 setIrrelevant(toggleable_cache
.getState(),
136 Arrays
.asList(new Object
[] { toggleable_cache
}));
143 public void handleEvent(Object eventSource
) {
144 if (eventSource
== toggleable_cache
) {
145 getEntity().setAuthorshipCache(toggleable_cache
.getText(),
146 toggleable_cache
.getState());
147 if (!isIrrelevant()){
148 setIrrelevant(toggleable_cache
.getState(),
149 Arrays
.asList(new Object
[] { toggleable_cache
}));
151 } else if (eventSource
== selectionCombinationAuthor
) {
152 getEntity().setCombinationAuthorship(
153 selectionCombinationAuthor
.getSelection());
154 } else if (eventSource
== selectionExCombinationAuthor
) {
155 getEntity().setExCombinationAuthorship(
156 selectionExCombinationAuthor
.getSelection());
157 } else if (eventSource
== selectionBasionymAuthor
) {
158 getEntity().setBasionymAuthorship(
159 selectionBasionymAuthor
.getSelection());
160 } else if (eventSource
== selectionExBasionymAuthor
) {
161 getEntity().setExBasionymAuthorship(
162 selectionExBasionymAuthor
.getSelection());
163 } else if (eventSource
== text_originalPublicationYear
) {
164 ((ZoologicalName
)getEntity()).setOriginalPublicationYear(text_originalPublicationYear
.getInteger());
165 } else if (eventSource
== text_publicationYear
) {
166 ((ZoologicalName
)getEntity()).setPublicationYear(text_publicationYear
.getInteger());
169 // if (eventSource != toggleable_cache) {
170 // toggleable_cache.setText(getEntity().getAuthorshipCache());
173 // we have to notify the parent if this is embedded in the nonviral name
175 // maybe we can handle this a little bit more elegant
176 // if (getParentElement() instanceof AbstractCdmDetailSection)
177 firePropertyChangeEvent(new CdmPropertyChangeEvent(
178 getParentElement(), null));
182 public void updateToggleableCacheField() {
183 if (toggleable_cache
!= null){
184 if(! getEntity().isProtectedAuthorshipCache()){
185 toggleable_cache
.setText(getEntity().getAuthorshipCache());