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