Merge branch 'release/4.6.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
10 package eu.etaxonomy.taxeditor.ui.section.name;
11
12 import java.util.Arrays;
13
14 import eu.etaxonomy.cdm.model.agent.TeamOrPersonBase;
15 import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
16 import eu.etaxonomy.cdm.model.name.NonViralName;
17 import eu.etaxonomy.cdm.model.name.TaxonNameFactory;
18 import eu.etaxonomy.cdm.model.name.ZoologicalName;
19 import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
20 import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
21 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22 import eu.etaxonomy.taxeditor.ui.element.CdmPropertyChangeEvent;
23 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
24 import eu.etaxonomy.taxeditor.ui.element.NumberWithLabelElement;
25 import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
26 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
27
28 /**
29 * <p>
30 * AuthorshipDetailElement class.
31 * </p>
32 *
33 * @author n.hoffmann
34 * @created Mar 4, 2010
35 * @version 1.0
36 */
37 public class AuthorshipDetailElement extends
38 AbstractIdentifiableEntityDetailElement<NonViralName> {
39
40 private EntitySelectionElement<TeamOrPersonBase> selectionExBasionymAuthor;
41 private EntitySelectionElement<TeamOrPersonBase> selectionBasionymAuthor;
42 private EntitySelectionElement<TeamOrPersonBase> selectionExCombinationAuthor;
43 private EntitySelectionElement<TeamOrPersonBase> selectionCombinationAuthor;
44
45 private NumberWithLabelElement text_publicationYear;
46 private NumberWithLabelElement text_originalPublicationYear;
47 /**
48 * <p>
49 * Constructor for AuthorshipDetailElement.
50 * </p>
51 *
52 * @param cdmFormFactory
53 * a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
54 * object.
55 * @param formElement
56 * a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement}
57 * object.
58 * @param style
59 * a int.
60 */
61 public AuthorshipDetailElement(CdmFormFactory cdmFormFactory,
62 ICdmFormElement formElement, int style) {
63 super(cdmFormFactory, formElement);
64 }
65
66 /** {@inheritDoc} */
67 @Override
68 protected void createControls(ICdmFormElement formElement,
69 NonViralName entity, int style) {
70 if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP_CACHE)){
71 toggleable_cache = formFactory.createToggleableTextField(this,
72 "Authorship Cache", entity.getAuthorshipCache(),
73 entity.isProtectedAuthorshipCache(), style);
74 addElement(toggleable_cache);
75 }
76 NomenclaturalCode code = entity.getNomenclaturalCode();
77
78 if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
79 selectionCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
80 getConversationHolder(),
81 formElement, "Author",
82 entity.getCombinationAuthorship(),
83 EntitySelectionElement.ALL, style);
84 addElement(selectionCombinationAuthor);
85 selectionExCombinationAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class,
86 getConversationHolder(),
87 formElement, "Ex Author",
88 entity.getExCombinationAuthorship(),
89 EntitySelectionElement.ALL, style);
90 addElement(selectionExCombinationAuthor);
91 if (code != null){
92 if (code.equals(NomenclaturalCode.ICZN)){
93 text_publicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Publication Year", ((ZoologicalName)entity).getPublicationYear(), style);
94
95 }
96 }
97 selectionBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
98 formElement, "Basionym Author", entity.getBasionymAuthorship(),
99 EntitySelectionElement.ALL, style);
100 addElement(selectionBasionymAuthor);
101 selectionExBasionymAuthor = formFactory.createSelectionElementWithAbbreviatedTitle(TeamOrPersonBase.class, getConversationHolder(),
102 formElement, "Ex Basionym Author",entity.getExBasionymAuthorship(),
103 EntitySelectionElement.ALL, style);
104
105 addElement(selectionExBasionymAuthor);
106 if (code != null){
107 if (code.equals(NomenclaturalCode.ICZN)){
108
109 text_originalPublicationYear = formFactory.createNumberTextWithLabelElement(formElement, "Orig. Publication Year", ((ZoologicalName)entity).getOriginalPublicationYear(), style);
110
111 }
112 }
113
114 }
115
116 }
117
118 /** {@inheritDoc} */
119 @Override
120 public void updateContent() {
121 if (getEntity() == null) {
122 setEntity(TaxonNameFactory.NewNonViralInstance(null));
123 }
124
125 super.updateContent();
126 if (toggleable_cache != null){
127 toggleable_cache.setEnabled(getEntity().isProtectedAuthorshipCache());
128
129
130 if (this.isIrrelevant()) {
131 setIrrelevant(isIrrelevant());
132 } else {
133 setIrrelevant(toggleable_cache.getState(),
134 Arrays.asList(new Object[] { toggleable_cache }));
135 }
136 }
137 }
138
139 /** {@inheritDoc} */
140 @Override
141 public void handleEvent(Object eventSource) {
142 if (eventSource == toggleable_cache) {
143 getEntity().setAuthorshipCache(toggleable_cache.getText(),
144 toggleable_cache.getState());
145 if (!isIrrelevant()){
146 setIrrelevant(toggleable_cache.getState(),
147 Arrays.asList(new Object[] { toggleable_cache }));
148 }
149 } else if (eventSource == selectionCombinationAuthor) {
150 getEntity().setCombinationAuthorship(
151 selectionCombinationAuthor.getSelection());
152 } else if (eventSource == selectionExCombinationAuthor) {
153 getEntity().setExCombinationAuthorship(
154 selectionExCombinationAuthor.getSelection());
155 } else if (eventSource == selectionBasionymAuthor) {
156 getEntity().setBasionymAuthorship(
157 selectionBasionymAuthor.getSelection());
158 } else if (eventSource == selectionExBasionymAuthor) {
159 getEntity().setExBasionymAuthorship(
160 selectionExBasionymAuthor.getSelection());
161 } else if (eventSource == text_originalPublicationYear) {
162 ((ZoologicalName)getEntity()).setOriginalPublicationYear(text_originalPublicationYear.getInteger());
163 } else if (eventSource == text_publicationYear) {
164 ((ZoologicalName)getEntity()).setPublicationYear(text_publicationYear.getInteger());
165 }
166
167 // if (eventSource != toggleable_cache) {
168 // toggleable_cache.setText(getEntity().getAuthorshipCache());
169 // }
170
171 // we have to notify the parent if this is embedded in the nonviral name
172 // section
173 // maybe we can handle this a little bit more elegant
174 // if (getParentElement() instanceof AbstractCdmDetailSection)
175 firePropertyChangeEvent(new CdmPropertyChangeEvent(
176 getParentElement(), null));
177 }
178
179 @Override
180 public void updateToggleableCacheField() {
181 if (toggleable_cache != null){
182 if(! getEntity().isProtectedAuthorshipCache()){
183 toggleable_cache.setText(getEntity().getAuthorshipCache());
184 }
185 }
186 }
187 }