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 org.eclipse.ui.forms.widgets.ExpandableComposite;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.name.IBacterialName;
|
17
|
import eu.etaxonomy.cdm.model.name.INonViralName;
|
18
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
19
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
20
|
import eu.etaxonomy.taxeditor.l10n.Messages;
|
21
|
import eu.etaxonomy.taxeditor.model.MessagingUtils;
|
22
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
23
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
24
|
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.LsidWithExceptionLabelElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
30
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailSection;
|
31
|
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
|
32
|
|
33
|
/**
|
34
|
* @author n.hoffmann
|
35
|
* @created May 20, 2010
|
36
|
*/
|
37
|
public class NonViralNameDetailElement
|
38
|
extends AbstractIdentifiableEntityDetailElement<TaxonName> {
|
39
|
|
40
|
private NameDetailSection section_name;
|
41
|
private AuthorshipDetailSection section_author;
|
42
|
private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
|
43
|
private HybridDetailSection section_hybrid;
|
44
|
private LsidWithExceptionLabelElement textLsid;
|
45
|
private TextWithLabelElement text_nameApprobation;
|
46
|
|
47
|
|
48
|
public NonViralNameDetailElement(CdmFormFactory formFactory,
|
49
|
ICdmFormElement formElement) {
|
50
|
super(formFactory, formElement);
|
51
|
initIsAdvancedDetailsView();
|
52
|
|
53
|
}
|
54
|
|
55
|
/** {@inheritDoc} */
|
56
|
@Override
|
57
|
protected void createControls(ICdmFormElement formElement, final TaxonName entity, int style) {
|
58
|
|
59
|
|
60
|
if (isAdvancedView){
|
61
|
toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
|
62
|
|
63
|
combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
|
64
|
combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
|
65
|
if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
|
66
|
text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
|
67
|
}
|
68
|
textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
|
69
|
|
70
|
|
71
|
}else{
|
72
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE)){
|
73
|
toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
|
74
|
|
75
|
}
|
76
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NOMENCLATURAL_CODE)){
|
77
|
combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
|
78
|
combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
|
79
|
}
|
80
|
if (entity.getNameType().equals(NomenclaturalCode.ICNB)){
|
81
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_NAME_APPROBATION)){
|
82
|
text_nameApprobation = formFactory.createTextWithLabelElement(formElement, "Name Approbation", entity.getNameApprobation(),style);
|
83
|
}
|
84
|
}
|
85
|
|
86
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID)){
|
87
|
textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
|
88
|
|
89
|
}
|
90
|
|
91
|
|
92
|
}
|
93
|
|
94
|
|
95
|
section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
|
96
|
section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
97
|
addControl(section_name);
|
98
|
addElement(section_name);
|
99
|
if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
|
100
|
section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
|
101
|
section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
102
|
addControl(section_author);
|
103
|
addElement(section_author);
|
104
|
}
|
105
|
//TODO RL
|
106
|
if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID)){
|
107
|
section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
|
108
|
section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
109
|
addControl(section_hybrid);
|
110
|
addElement(section_hybrid);
|
111
|
|
112
|
}
|
113
|
|
114
|
|
115
|
}
|
116
|
|
117
|
/** {@inheritDoc} */
|
118
|
@Override
|
119
|
protected void updateContent() {
|
120
|
super.updateContent();
|
121
|
// disable nomenclatural code, because changing of nom.code is not
|
122
|
// implemented on library side
|
123
|
// if(combo_nomenclaturalCode!=null){
|
124
|
// combo_nomenclaturalCode.setEnabled(false);
|
125
|
// }
|
126
|
|
127
|
if(toggleable_cache!=null){
|
128
|
toggleable_cache.setEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
|
129
|
setIrrelevant(toggleable_cache.getState(),
|
130
|
Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
|
131
|
}
|
132
|
}
|
133
|
|
134
|
/** {@inheritDoc} */
|
135
|
@Override
|
136
|
public void setEntity(TaxonName entity) {
|
137
|
super.setEntity(entity);
|
138
|
if (section_name!=null) {
|
139
|
section_name.setEntity(entity);
|
140
|
}
|
141
|
if (section_author!=null) {
|
142
|
section_author.setEntity(entity);
|
143
|
}
|
144
|
if (section_hybrid!=null) {
|
145
|
section_hybrid.setEntity(entity);
|
146
|
}
|
147
|
}
|
148
|
|
149
|
/** {@inheritDoc} */
|
150
|
@Override
|
151
|
public void removeElements() {
|
152
|
super.removeElements();
|
153
|
if (section_name != null) {
|
154
|
section_name.removeElements();
|
155
|
removeControl(section_name);
|
156
|
section_name.dispose();
|
157
|
section_name = null;
|
158
|
}
|
159
|
if (section_author != null) {
|
160
|
section_author.removeElements();
|
161
|
removeControl(section_author);
|
162
|
section_author.dispose();
|
163
|
section_author = null;
|
164
|
}
|
165
|
}
|
166
|
|
167
|
/** {@inheritDoc} */
|
168
|
@Override
|
169
|
public void handleEvent(Object eventSource) {
|
170
|
if (eventSource == toggleable_cache) {
|
171
|
handleToggleableCacheField();
|
172
|
// we never want the fullTitleCache to be protected since we only
|
173
|
// use it for
|
174
|
// initiating the free text name editor
|
175
|
getEntity().setProtectedFullTitleCache(false);
|
176
|
} else if (eventSource == section_name || eventSource == section_author) {
|
177
|
if (getParentElement() instanceof AbstractCdmDetailSection) {
|
178
|
((AbstractCdmDetailSection) getParentElement()).updateTitle();
|
179
|
}
|
180
|
if (toggleable_cache != null){
|
181
|
if (!toggleable_cache.getState()) {
|
182
|
toggleable_cache.setText(getEntity().getTitleCache());
|
183
|
}
|
184
|
}
|
185
|
} else if (eventSource == section_name) {
|
186
|
section_name.setEntity(getEntity());
|
187
|
getLayoutComposite().layout();
|
188
|
} else if(eventSource==textLsid){
|
189
|
getEntity().setLsid(textLsid.parseText());
|
190
|
} else if (eventSource == combo_nomenclaturalCode){
|
191
|
boolean change = checkForDeletableParts(combo_nomenclaturalCode.getSelection());
|
192
|
if (change){
|
193
|
getEntity().setNameType(combo_nomenclaturalCode.getSelection());
|
194
|
|
195
|
this.updateContent();
|
196
|
section_hybrid.setEntity(getEntity());
|
197
|
section_author.setEntity(getEntity());
|
198
|
section_name.setEntity(getEntity());
|
199
|
}else{
|
200
|
combo_nomenclaturalCode.setSelection(getEntity().getNameType());
|
201
|
}
|
202
|
} else if(eventSource == this.text_nameApprobation){
|
203
|
((IBacterialName)getEntity()).setNameApprobation(text_nameApprobation.getText());
|
204
|
}
|
205
|
}
|
206
|
private boolean checkForDeletableParts(NomenclaturalCode selection) {
|
207
|
NomenclaturalCode actualCode = getEntity().getNameType();
|
208
|
if (selection.equals(actualCode)){
|
209
|
return true;
|
210
|
}
|
211
|
if (actualCode.equals(NomenclaturalCode.ICZN) ){
|
212
|
if(getEntity().getOriginalPublicationYear() != null || getEntity().getPublicationYear() != null || getEntity().getBreed() != null){
|
213
|
if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfZoologicalNameParts, Messages.NonViralNameDetails_descriptionDeleteZoologicalNameParts)){
|
214
|
getEntity().setOriginalPublicationYear(null);
|
215
|
getEntity().setPublicationYear(null);
|
216
|
getEntity().setBreed(null);
|
217
|
return true;
|
218
|
}
|
219
|
}else {
|
220
|
return true;
|
221
|
}
|
222
|
|
223
|
}
|
224
|
if (actualCode.equals(NomenclaturalCode.ICNB)){
|
225
|
if (getEntity().getNameApprobation() != null || getEntity().getSubGenusAuthorship() != null){
|
226
|
if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfBacterialNameParts, Messages.NonViralNameDetails_desciptionDeleteOfBacterialNameParts)){
|
227
|
getEntity().setNameApprobation(null);
|
228
|
getEntity().setSubGenusAuthorship(null);
|
229
|
return true;
|
230
|
}
|
231
|
}else{
|
232
|
return true;
|
233
|
}
|
234
|
|
235
|
}
|
236
|
if (actualCode.equals(NomenclaturalCode.Fungi)){
|
237
|
if (getEntity().isAnamorphic() ){
|
238
|
if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfFungiNameParts, Messages.NonViralNameDetails_descriptionDeleteOfFungiNameParts)){
|
239
|
getEntity().setAnamorphic(false);
|
240
|
return true;
|
241
|
}
|
242
|
}else{
|
243
|
return true;
|
244
|
}
|
245
|
}
|
246
|
if (actualCode.equals(NomenclaturalCode.ICNCP)){
|
247
|
if (getEntity().getCultivarName() != null){
|
248
|
if (MessagingUtils.confirmDialog(Messages.NonViralNameDetails_confirmDeleteOfCultivarNameParts, Messages.NonViralNameDetails_descriptionDeleteOfCultivarNameParts)){
|
249
|
getEntity().setCultivarName(null);
|
250
|
return true;
|
251
|
}
|
252
|
}else{
|
253
|
return true;
|
254
|
}
|
255
|
|
256
|
}
|
257
|
if (actualCode.equals(NomenclaturalCode.ICNAFP)){
|
258
|
return true;
|
259
|
}
|
260
|
return false;
|
261
|
}
|
262
|
|
263
|
@Override
|
264
|
protected void handleToggleableCacheField() {
|
265
|
boolean pushedState = toggleable_cache.getState();
|
266
|
|
267
|
getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
|
268
|
setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid, text_nameApprobation }));
|
269
|
updateToggleableCacheField();
|
270
|
}
|
271
|
|
272
|
|
273
|
|
274
|
|
275
|
// @Override
|
276
|
// public void toggleAdvancedMediaView(){
|
277
|
// mediaDetailElement.toggleAdvancedMediaView();
|
278
|
// }
|
279
|
}
|