ref #7413: handle BasionymInAuthor correctly
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / name / AuthorshipDetailElement.java
1 /**
2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
5 *
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.
8 */
9 package eu.etaxonomy.taxeditor.ui.section.name;
10
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;
27
28 /**
29 * AuthorshipDetailElement class.
30 *
31 * @author n.hoffmann
32 * @created Mar 4, 2010
33 */
34 public class AuthorshipDetailElement
35 extends AbstractIdentifiableEntityDetailElement<INonViralName> {
36
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;
49
50 private NumberWithLabelElement text_publicationYear;
51 private NumberWithLabelElement text_originalPublicationYear;
52
53 /**
54 * Constructor for AuthorshipDetailElement.
55 */
56 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory,
57 ICdmFormElement formElement, int style) {
58 super(cdmFormFactory, formElement);
59 }
60
61 @Override
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);
70 }
71 NomenclaturalCode code = entity.getNameType();
72
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);
90 }
91 if (code != null){
92 if (code.equals(NomenclaturalCode.ICZN)){
93 text_publicationYear = formFactory.createFloatTextWithLabelElement(formElement, "Publication Year", ((IZoologicalName)entity).getPublicationYear(), style);
94 }
95 }
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);
103
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);
111 }
112 if (code != null && code.equals(NomenclaturalCode.ICZN)){
113 text_originalPublicationYear = formFactory.createFloatTextWithLabelElement(formElement, "Orig. Publication Year", ((IZoologicalName)entity).getOriginalPublicationYear(), style);
114 }
115 }
116
117 //put to Cache
118 registerCacheRelevance(selectionCombinationAuthor);
119 registerCacheRelevance(selectionBasionymAuthor);
120 registerCacheRelevance(selectionExCombinationAuthor);
121 registerCacheRelevance(selectionExBasionymAuthor);
122 registerCacheRelevance(text_publicationYear);
123 registerCacheRelevance(text_originalPublicationYear);
124
125 registerCacheRelevance(toggleable_cache, cacheRelevanceHelper.getDependenciesArray());
126
127 }
128
129 @Override
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);
134 }
135
136 @Override
137 public void updateContent() {
138 if (getEntity() == null) {
139 setEntity(TaxonNameFactory.NewNonViralInstance(null));
140 }
141
142 super.updateContent();
143 if (toggleable_cache != null){
144 toggleable_cache.setCacheEnabled(getEntity().isProtectedAuthorshipCache());
145 updateCacheRelevance();
146 }
147 }
148
149 @Override
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());
175 }
176
177 // if (eventSource != toggleable_cache) {
178 // toggleable_cache.setText(getEntity().getAuthorshipCache());
179 // }
180
181 // we have to notify the parent if this is embedded in the nonviral name
182 // section
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());
188 }
189
190 @Override
191 public void updateToggleableCacheField() {
192 if (toggleable_cache != null){
193 if(! getEntity().isProtectedAuthorshipCache()){
194 toggleable_cache.setText(getEntity().getAuthorshipCache());
195 }
196 }
197 }
198
199 @Override
200 public void fillFields() {
201 /*
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) {
209
210 }
211 if (text_publicationYear != null) {
212 text_publicationYear.setNumber(((IZoologicalName)getEntity()).getPublicationYear());
213 text_originalPublicationYear.setNumber(((IZoologicalName)getEntity()).getOriginalPublicationYear());
214 }
215
216 */
217
218
219 }
220 }