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