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