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