Merge branch 'release/5.19.0'
[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
46 private NumberWithLabelElement text_publicationYear;
47 private NumberWithLabelElement text_originalPublicationYear;
48
49 /**
50 * Constructor for AuthorshipDetailElement.
51 */
52 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory,
53 ICdmFormElement formElement, int style) {
54 super(cdmFormFactory, formElement);
55 }
56
57 @Override
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);
66 }
67 NomenclaturalCode code = entity.getNameType();
68
69 if (config == null || config.isAuthorshipSectionActivated()){
70 selectionCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
71 getConversationHolder(),
72 formElement, "Author",
73 entity.getCombinationAuthorship(),
74 EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
75 addElement(selectionCombinationAuthor);
76 selectionExCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
77 getConversationHolder(),
78 formElement, "Ex Author",
79 entity.getExCombinationAuthorship(),
80 EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
81 addElement(selectionExCombinationAuthor);
82 if (code != null){
83 if (code.equals(NomenclaturalCode.ICZN)){
84 text_publicationYear = formFactory.createFloatTextWithLabelElement(formElement, "Publication Year", ((IZoologicalName)entity).getPublicationYear(), style);
85 }
86 }
87 selectionBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
88 formElement, "Basionym Author", entity.getBasionymAuthorship(),
89 EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
90 addElement(selectionBasionymAuthor);
91 selectionExBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
92 formElement, "Ex Basionym Author",entity.getExBasionymAuthorship(),
93 EntitySelectionElement.DELETABLE | EntitySelectionElement.SELECTABLE | EntitySelectionElement.EDITABLE, style);
94
95 addElement(selectionExBasionymAuthor);
96 if (code != null && code.equals(NomenclaturalCode.ICZN)){
97 text_originalPublicationYear = formFactory.createFloatTextWithLabelElement(formElement, "Orig. Publication Year", ((IZoologicalName)entity).getOriginalPublicationYear(), style);
98 }
99 }
100
101 //put to Cache
102 registerCacheRelevance(selectionCombinationAuthor);
103 registerCacheRelevance(selectionBasionymAuthor);
104 registerCacheRelevance(selectionExCombinationAuthor);
105 registerCacheRelevance(selectionExBasionymAuthor);
106 registerCacheRelevance(text_publicationYear);
107 registerCacheRelevance(text_originalPublicationYear);
108
109 registerCacheRelevance(toggleable_cache, cacheRelevanceHelper.getDependenciesArray());
110
111 }
112
113 @Override
114 public void addDependsOnCache(ToggleableTextElement toggleElement) {
115 super.addDependsOnCache(toggleElement);
116 //register my cache on higher cache (if not null yet)
117 registerCacheRelevance(toggleable_cache, toggleElement);
118 }
119
120 @Override
121 public void updateContent() {
122 if (getEntity() == null) {
123 setEntity(TaxonNameFactory.NewNonViralInstance(null));
124 }
125
126 super.updateContent();
127 if (toggleable_cache != null){
128 toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
129 updateCacheRelevance();
130 }
131 }
132
133 @Override
134 public void handleEvent(Object eventSource) {
135 if (eventSource == toggleable_cache) {
136 getEntity().setAuthorshipCache(toggleable_cache.getText(),
137 toggleable_cache.getState());
138 updateCacheRelevance();
139 } else if (eventSource == selectionCombinationAuthor) {
140 getEntity().setCombinationAuthorship(
141 selectionCombinationAuthor.getSelection());
142 } else if (eventSource == selectionExCombinationAuthor) {
143 getEntity().setExCombinationAuthorship(
144 selectionExCombinationAuthor.getSelection());
145 } else if (eventSource == selectionBasionymAuthor) {
146 getEntity().setBasionymAuthorship(
147 selectionBasionymAuthor.getSelection());
148 } else if (eventSource == selectionExBasionymAuthor) {
149 getEntity().setExBasionymAuthorship(
150 selectionExBasionymAuthor.getSelection());
151 } else if (eventSource == text_originalPublicationYear) {
152 ((IZoologicalName)getEntity()).setOriginalPublicationYear(text_originalPublicationYear.getInteger());
153 } else if (eventSource == text_publicationYear) {
154 ((IZoologicalName)getEntity()).setPublicationYear(text_publicationYear.getInteger());
155 }
156
157 // if (eventSource != toggleable_cache) {
158 // toggleable_cache.setText(getEntity().getAuthorshipCache());
159 // }
160
161 // we have to notify the parent if this is embedded in the nonviral name
162 // section
163 // maybe we can handle this a little bit more elegant
164 // if (getParentElement() instanceof AbstractCdmDetailSection)
165 firePropertyChangeEvent(new CdmPropertyChangeEvent(
166 getParentElement(), null));
167 EventUtility.postEvent(WorkbenchEventConstants.REFRESH_NAME_EDITOR, this.getEntity());
168 }
169
170 @Override
171 public void updateToggleableCacheField() {
172 if (toggleable_cache != null){
173 if(! getEntity().isProtectedAuthorshipCache()){
174 toggleable_cache.setText(getEntity().getAuthorshipCache());
175 }
176 }
177 }
178 }