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
;
46 private NumberWithLabelElement text_publicationYear
;
47 private NumberWithLabelElement text_originalPublicationYear
;
50 * Constructor for AuthorshipDetailElement.
52 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory
,
53 ICdmFormElement formElement
, int style
) {
54 super(cdmFormFactory
, formElement
);
58 protected void createControls(ICdmFormElement formElement
,
59 INonViralName entity
, int style
) {
60 NameDetailsConfigurator config
= PreferencesUtil
.getPreferredNameDetailsConfiguration();
61 if (config
== null || config
.isAuthorCacheActivated()){
62 toggleable_cache
= formFactory
.createToggleableTextField(this,
63 "Authorship Cache", entity
.getAuthorshipCache(),
64 entity
.isProtectedAuthorshipCache(), style
);
65 addElement(toggleable_cache
);
67 NomenclaturalCode code
= entity
.getNameType();
69 if (config
== null || config
.isAuthorshipSectionActivated()){
70 selectionCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
71 formElement
, "Author",
72 entity
.getCombinationAuthorship(),
73 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
74 addElement(selectionCombinationAuthor
);
75 selectionExCombinationAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
76 formElement
, "Ex Author",
77 entity
.getExCombinationAuthorship(),
78 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
79 addElement(selectionExCombinationAuthor
);
81 if (code
.equals(NomenclaturalCode
.ICZN
)){
82 text_publicationYear
= formFactory
.createFloatTextWithLabelElement(formElement
, "Publication Year", ((IZoologicalName
)entity
).getPublicationYear(), style
);
85 selectionBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
86 formElement
, "Basionym Author", entity
.getBasionymAuthorship(),
87 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
88 addElement(selectionBasionymAuthor
);
89 selectionExBasionymAuthor
= formFactory
.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase
.class,
90 formElement
, "Ex Basionym Author",entity
.getExBasionymAuthorship(),
91 EntitySelectionElement
.DELETABLE
| EntitySelectionElement
.SELECTABLE
| EntitySelectionElement
.EDITABLE
, style
);
93 addElement(selectionExBasionymAuthor
);
94 if (code
!= null && code
.equals(NomenclaturalCode
.ICZN
)){
95 text_originalPublicationYear
= formFactory
.createFloatTextWithLabelElement(formElement
, "Orig. Publication Year", ((IZoologicalName
)entity
).getOriginalPublicationYear(), style
);
100 registerCacheRelevance(selectionCombinationAuthor
);
101 registerCacheRelevance(selectionBasionymAuthor
);
102 registerCacheRelevance(selectionExCombinationAuthor
);
103 registerCacheRelevance(selectionExBasionymAuthor
);
104 registerCacheRelevance(text_publicationYear
);
105 registerCacheRelevance(text_originalPublicationYear
);
107 registerCacheRelevance(toggleable_cache
, cacheRelevanceHelper
.getDependenciesArray());
112 public void addDependsOnCache(ToggleableTextElement toggleElement
) {
113 super.addDependsOnCache(toggleElement
);
114 //register my cache on higher cache (if not null yet)
115 registerCacheRelevance(toggleable_cache
, toggleElement
);
119 public void updateContent() {
120 if (getEntity() == null) {
121 setEntity(TaxonNameFactory
.NewNonViralInstance(null));
124 super.updateContent();
125 if (toggleable_cache
!= null){
126 toggleable_cache
.setCacheEnabled(getEntity().isProtectedAuthorshipCache());
127 updateCacheRelevance();
132 public void handleEvent(Object eventSource
) {
133 if (eventSource
== toggleable_cache
) {
134 getEntity().setAuthorshipCache(toggleable_cache
.getText(),
135 toggleable_cache
.getState());
136 updateCacheRelevance();
137 } else if (eventSource
== selectionCombinationAuthor
) {
138 getEntity().setCombinationAuthorship(
139 selectionCombinationAuthor
.getSelection());
140 } else if (eventSource
== selectionExCombinationAuthor
) {
141 getEntity().setExCombinationAuthorship(
142 selectionExCombinationAuthor
.getSelection());
143 } else if (eventSource
== selectionBasionymAuthor
) {
144 getEntity().setBasionymAuthorship(
145 selectionBasionymAuthor
.getSelection());
146 } else if (eventSource
== selectionExBasionymAuthor
) {
147 getEntity().setExBasionymAuthorship(
148 selectionExBasionymAuthor
.getSelection());
149 } else if (eventSource
== text_originalPublicationYear
) {
150 ((IZoologicalName
)getEntity()).setOriginalPublicationYear(text_originalPublicationYear
.getInteger());
151 } else if (eventSource
== text_publicationYear
) {
152 ((IZoologicalName
)getEntity()).setPublicationYear(text_publicationYear
.getInteger());
155 // if (eventSource != toggleable_cache) {
156 // toggleable_cache.setText(getEntity().getAuthorshipCache());
159 // we have to notify the parent if this is embedded in the nonviral name
161 // maybe we can handle this a little bit more elegant
162 // if (getParentElement() instanceof AbstractCdmDetailSection)
163 firePropertyChangeEvent(new CdmPropertyChangeEvent(
164 getParentElement(), null));
165 EventUtility
.postEvent(WorkbenchEventConstants
.REFRESH_NAME_EDITOR
, this.getEntity());
169 public void updateToggleableCacheField() {
170 if (toggleable_cache
!= null){
171 if(! getEntity().isProtectedAuthorshipCache()){
172 toggleable_cache
.setText(getEntity().getAuthorshipCache());
178 public void fillFields() {
180 toggleable_cache.setText(getEntity().getAuthorshipCache());
181 toggleable_cache.setSelected(getEntity().isProtectedAuthorshipCache());
182 selectionExBasionymAuthor.setEntity(getEntity().getExBasionymAuthorship());
183 selectionBasionymAuthor.setEntity(getEntity().getBasionymAuthorship());
184 selectionExCombinationAuthor.setEntity(getEntity().getExCombinationAuthorship());
185 selectionCombinationAuthor.setEntity(getEntity().getCombinationAuthorship());
186 if (text_originalPublicationYear != null) {
189 if (text_publicationYear != null) {
190 text_publicationYear.setNumber(((IZoologicalName)getEntity()).getPublicationYear());
191 text_originalPublicationYear.setNumber(((IZoologicalName)getEntity()).getOriginalPublicationYear());