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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
11 import eu
.etaxonomy
.cdm
.model
.agent
.TeamOrPersonBase
;
12 import eu
.etaxonomy
.cdm
.model
.name
.INonViralName
;
13 import eu
.etaxonomy
.cdm
.model
.name
.IZoologicalName
;
14 import eu
.etaxonomy
.cdm
.model
.name
.NomenclaturalCode
;
15 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameFactory
;
16 import eu
.etaxonomy
.taxeditor
.event
.EventUtility
;
17 import eu
.etaxonomy
.taxeditor
.event
.WorkbenchEventConstants
;
18 import eu
.etaxonomy
.taxeditor
.preference
.NameDetailsConfigurator
;
19 import eu
.etaxonomy
.taxeditor
.preference
.PreferencesUtil
;
20 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
21 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmPropertyChangeEvent
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.NumberWithLabelElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.ToggleableTextElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractIdentifiableEntityDetailElement
;
26 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
29 * AuthorshipDetailElement class.
32 * @created Mar 4, 2010
34 public class AuthorshipDetailElement
35 extends AbstractIdentifiableEntityDetailElement
<INonViralName
> {
37 @SuppressWarnings("rawtypes")
38 private EntitySelectionElement
<TeamOrPersonBase
> selectionExBasionymAuthor
;
39 @SuppressWarnings("rawtypes")
40 private EntitySelectionElement
<TeamOrPersonBase
> selectionBasionymAuthor
;
41 @SuppressWarnings("rawtypes")
42 private EntitySelectionElement
<TeamOrPersonBase
> selectionExCombinationAuthor
;
43 @SuppressWarnings("rawtypes")
44 private EntitySelectionElement
<TeamOrPersonBase
> selectionCombinationAuthor
;
45 @SuppressWarnings("rawtypes")
46 private EntitySelectionElement
<TeamOrPersonBase
> selectionInCombinationAuthor
;
47 @SuppressWarnings("rawtypes")
48 private EntitySelectionElement
<TeamOrPersonBase
> selectionInBasionymAuthor
;
50 private NumberWithLabelElement text_publicationYear
;
51 private NumberWithLabelElement text_originalPublicationYear
;
54 * Constructor for AuthorshipDetailElement.
56 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory
,
57 ICdmFormElement formElement
, int style
) {
58 super(cdmFormFactory
, formElement
);
62 protected void createControls(ICdmFormElement formElement
,
63 INonViralName entity
, int style
) {
64 NameDetailsConfigurator config
= PreferencesUtil
.getPreferredNameDetailsConfiguration();
65 if (config
== null || config
.isAuthorCacheActivated()){
66 toggleable_cache
= formFactory
.createToggleableTextField(this,
67 "Authorship Cache", entity
.getAuthorshipCache(),
68 entity
.isProtectedAuthorshipCache(), style
);
69 addElement(toggleable_cache
);
71 NomenclaturalCode code
= entity
.getNameType();
73 if (config
== null || config
.isAuthorshipSectionActivated()){
74 selectionCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
75 formElement
, "Author",
76 entity
.getCombinationAuthorship(),
77 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
78 addElement(selectionCombinationAuthor
);
79 selectionExCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
80 formElement
, "Ex Author",
81 entity
.getExCombinationAuthorship(),
82 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
83 addElement(selectionExCombinationAuthor
);
84 if ((config
== null || config
.isInAuthorshipActivated())&& (getEntity().getNameType().isFungus() || getEntity().getNameType().isZoological())) {
85 selectionInCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
86 formElement
, "In Author",
87 entity
.getInCombinationAuthorship(),
88 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
89 addElement(selectionInCombinationAuthor
);
92 if (code
.equals(NomenclaturalCode
.ICZN
)){
93 text_publicationYear
= formFactory
.createFloatTextWithLabelElement(formElement
, "Publication Year", ((IZoologicalName
)entity
).getPublicationYear(), style
);
96 selectionBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
97 formElement
, "Basionym Author", entity
.getBasionymAuthorship(),
98 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
99 addElement(selectionBasionymAuthor
);
100 selectionExBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
101 formElement
, "Ex Basionym Author",entity
.getExBasionymAuthorship(),
102 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
104 addElement(selectionExBasionymAuthor
);
105 if ((config
== null || config
.isInAuthorshipActivated()) && (getEntity().getNameType().isFungus() || getEntity().getNameType().isZoological())) {
106 selectionInBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
107 formElement
, "In Basionym Author",
108 entity
.getInBasionymAuthorship(),
109 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
110 addElement(selectionInBasionymAuthor
);
112 if (code
!= null && code
.equals(NomenclaturalCode
.ICZN
)){
113 text_originalPublicationYear
= formFactory
.createFloatTextWithLabelElement(formElement
, "Orig. Publication Year", ((IZoologicalName
)entity
).getOriginalPublicationYear(), style
);
118 registerCacheRelevance(selectionCombinationAuthor
);
119 registerCacheRelevance(selectionBasionymAuthor
);
120 registerCacheRelevance(selectionExCombinationAuthor
);
121 registerCacheRelevance(selectionExBasionymAuthor
);
122 registerCacheRelevance(text_publicationYear
);
123 registerCacheRelevance(text_originalPublicationYear
);
125 registerCacheRelevance(toggleable_cache
, cacheRelevanceHelper
.getDependenciesArray());
130 public void addDependsOnCache(ToggleableTextElement toggleElement
) {
131 super.addDependsOnCache(toggleElement
);
132 //register my cache on higher cache (if not null yet)
133 registerCacheRelevance(toggleable_cache
, toggleElement
);
137 public void updateContent() {
138 if (getEntity() == null) {
139 setEntity(TaxonNameFactory
.NewNonViralInstance(null));
142 super.updateContent();
143 if (toggleable_cache
!= null){
144 toggleable_cache
.setCacheEnabled(getEntity().isProtectedAuthorshipCache());
145 updateCacheRelevance();
150 public void handleEvent(Object eventSource
) {
151 if (eventSource
== toggleable_cache
) {
152 getEntity().setAuthorshipCache(toggleable_cache
.getText(),
153 toggleable_cache
.getState());
154 updateCacheRelevance();
155 } else if (eventSource
== selectionCombinationAuthor
) {
156 getEntity().setCombinationAuthorship(
157 selectionCombinationAuthor
.getSelection());
158 } else if (eventSource
== selectionExCombinationAuthor
) {
159 getEntity().setExCombinationAuthorship(
160 selectionExCombinationAuthor
.getSelection());
161 } else if (eventSource
== selectionBasionymAuthor
) {
162 getEntity().setBasionymAuthorship(
163 selectionBasionymAuthor
.getSelection());
164 } else if (eventSource
== selectionExBasionymAuthor
) {
165 getEntity().setExBasionymAuthorship(
166 selectionExBasionymAuthor
.getSelection());
167 } else if (eventSource
== text_originalPublicationYear
) {
168 ((IZoologicalName
)getEntity()).setOriginalPublicationYear(text_originalPublicationYear
.getInteger());
169 } else if (eventSource
== text_publicationYear
) {
170 ((IZoologicalName
)getEntity()).setPublicationYear(text_publicationYear
.getInteger());
171 }else if (eventSource
== selectionInCombinationAuthor
) {
172 (getEntity()).setInCombinationAuthorship(selectionInCombinationAuthor
.getEntity());
173 }else if (eventSource
== selectionInBasionymAuthor
) {
174 getEntity().setInBasionymAuthorship(selectionInBasionymAuthor
.getEntity());
177 // if (eventSource != toggleable_cache) {
178 // toggleable_cache.setText(getEntity().getAuthorshipCache());
181 // we have to notify the parent if this is embedded in the nonviral name
183 // maybe we can handle this a little bit more elegant
184 // if (getParentElement() instanceof AbstractCdmDetailSection)
185 firePropertyChangeEvent(new CdmPropertyChangeEvent(
186 getParentElement(), null));
187 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_NAME_EDITOR
, this.getEntity());
191 public void updateToggleableCacheField() {
192 if (toggleable_cache
!= null){
193 if(! getEntity().isProtectedAuthorshipCache()){
194 toggleable_cache
.setText(getEntity().getAuthorshipCache());
200 public void fillFields() {
202 toggleable_cache.setText(getEntity().getAuthorshipCache());
203 toggleable_cache.setSelected(getEntity().isProtectedAuthorshipCache());
204 selectionExBasionymAuthor.setEntity(getEntity().getExBasionymAuthorship());
205 selectionBasionymAuthor.setEntity(getEntity().getBasionymAuthorship());
206 selectionExCombinationAuthor.setEntity(getEntity().getExCombinationAuthorship());
207 selectionCombinationAuthor.setEntity(getEntity().getCombinationAuthorship());
208 if (text_originalPublicationYear != null) {
211 if (text_publicationYear != null) {
212 text_publicationYear.setNumber(((IZoologicalName)getEntity()).getPublicationYear());
213 text_originalPublicationYear.setNumber(((IZoologicalName)getEntity()).getOriginalPublicationYear());