ref #10138: after parsing send event to update the details view
[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 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);
80 if (code != null){
81 if (code.equals(NomenclaturalCode.ICZN)){
82 text_publicationYear = formFactory.createFloatTextWithLabelElement(formElement, "Publication Year", ((IZoologicalName)entity).getPublicationYear(), style);
83 }
84 }
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);
92
93 addElement(selectionExBasionymAuthor);
94 if (code != null && code.equals(NomenclaturalCode.ICZN)){
95 text_originalPublicationYear = formFactory.createFloatTextWithLabelElement(formElement, "Orig. Publication Year", ((IZoologicalName)entity).getOriginalPublicationYear(), style);
96 }
97 }
98
99 //put to Cache
100 registerCacheRelevance(selectionCombinationAuthor);
101 registerCacheRelevance(selectionBasionymAuthor);
102 registerCacheRelevance(selectionExCombinationAuthor);
103 registerCacheRelevance(selectionExBasionymAuthor);
104 registerCacheRelevance(text_publicationYear);
105 registerCacheRelevance(text_originalPublicationYear);
106
107 registerCacheRelevance(toggleable_cache, cacheRelevanceHelper.getDependenciesArray());
108
109 }
110
111 @Override
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);
116 }
117
118 @Override
119 public void updateContent() {
120 if (getEntity() == null) {
121 setEntity(TaxonNameFactory.NewNonViralInstance(null));
122 }
123
124 super.updateContent();
125 if (toggleable_cache != null){
126 toggleable_cache.setCacheEnabled(getEntity().isProtectedAuthorshipCache());
127 updateCacheRelevance();
128 }
129 }
130
131 @Override
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());
153 }
154
155 // if (eventSource != toggleable_cache) {
156 // toggleable_cache.setText(getEntity().getAuthorshipCache());
157 // }
158
159 // we have to notify the parent if this is embedded in the nonviral name
160 // section
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());
166 }
167
168 @Override
169 public void updateToggleableCacheField() {
170 if (toggleable_cache != null){
171 if(! getEntity().isProtectedAuthorshipCache()){
172 toggleable_cache.setText(getEntity().getAuthorshipCache());
173 }
174 }
175 }
176
177 @Override
178 public void fillFields() {
179 /*
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) {
187
188 }
189 if (text_publicationYear != null) {
190 text_publicationYear.setNumber(((IZoologicalName)getEntity()).getPublicationYear());
191 text_originalPublicationYear.setNumber(((IZoologicalName)getEntity()).getOriginalPublicationYear());
192 }
193
194 */
195
196
197 }
198 }