1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
|
11
|
package eu.etaxonomy.taxeditor.ui.section.name;
|
12
|
|
13
|
import java.util.Arrays;
|
14
|
|
15
|
import org.eclipse.ui.forms.widgets.ExpandableComposite;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.name.NomenclaturalCode;
|
18
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
19
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
20
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
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.section.AbstractCdmDetailSection;
|
26
|
import eu.etaxonomy.taxeditor.ui.section.AbstractIdentifiableEntityDetailElement;
|
27
|
|
28
|
/**
|
29
|
* @author n.hoffmann
|
30
|
* @created May 20, 2010
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public class NonViralNameDetailElement extends
|
34
|
AbstractIdentifiableEntityDetailElement<NonViralName> {
|
35
|
|
36
|
private NameDetailSection section_name;
|
37
|
private AuthorshipDetailSection section_author;
|
38
|
private EnumComboElement<NomenclaturalCode> combo_nomenclaturalCode;
|
39
|
private HybridDetailSection section_hybrid;
|
40
|
|
41
|
public NonViralNameDetailElement(CdmFormFactory formFactory,
|
42
|
ICdmFormElement formElement) {
|
43
|
super(formFactory, formElement);
|
44
|
}
|
45
|
|
46
|
/** {@inheritDoc} */
|
47
|
@Override
|
48
|
protected void createControls(ICdmFormElement formElement, final NonViralName entity, int style) {
|
49
|
//name can be null in rare cases. Temporary solution for #4221. May be obsolete when
|
50
|
//#4393 (Make changing name of a taxon possible in details view) is implemented.
|
51
|
if(entity==null){
|
52
|
formFactory.createEmptyElement(formElement, "No name associated with this taxon.");
|
53
|
}
|
54
|
else {
|
55
|
toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
|
56
|
|
57
|
combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
|
58
|
combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
|
59
|
|
60
|
//TODO RL
|
61
|
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
|
62
|
toggleable_cache.setVisible(false);
|
63
|
combo_nomenclaturalCode.setVisible(false);
|
64
|
}
|
65
|
|
66
|
section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
|
67
|
section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
68
|
addControl(section_name);
|
69
|
addElement(section_name);
|
70
|
section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
|
71
|
section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
72
|
addControl(section_author);
|
73
|
addElement(section_author);
|
74
|
|
75
|
//TODO RL
|
76
|
if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
|
77
|
section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
|
78
|
section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
79
|
addControl(section_hybrid);
|
80
|
addElement(section_hybrid);
|
81
|
}
|
82
|
}
|
83
|
}
|
84
|
|
85
|
/** {@inheritDoc} */
|
86
|
@Override
|
87
|
protected void updateContent() {
|
88
|
super.updateContent();
|
89
|
|
90
|
// disable nomenclatural code, because changing of nom.code is not
|
91
|
// implemented on library side
|
92
|
if(combo_nomenclaturalCode!=null){
|
93
|
combo_nomenclaturalCode.setEnabled(false);
|
94
|
}
|
95
|
|
96
|
if(toggleable_cache!=null){
|
97
|
setIrrelevant(toggleable_cache.getState(),
|
98
|
Arrays.asList(new Object[] { toggleable_cache }));
|
99
|
}
|
100
|
}
|
101
|
|
102
|
/** {@inheritDoc} */
|
103
|
@Override
|
104
|
public void setEntity(NonViralName entity) {
|
105
|
super.setEntity(entity);
|
106
|
if (section_name!=null) {
|
107
|
section_name.setEntity(entity);
|
108
|
}
|
109
|
if (section_author!=null) {
|
110
|
section_author.setEntity(entity);
|
111
|
}
|
112
|
if (section_hybrid!=null) {
|
113
|
section_hybrid.setEntity(entity);
|
114
|
}
|
115
|
}
|
116
|
|
117
|
/** {@inheritDoc} */
|
118
|
@Override
|
119
|
public void removeElements() {
|
120
|
super.removeElements();
|
121
|
if (section_name != null) {
|
122
|
section_name.removeElements();
|
123
|
removeControl(section_name);
|
124
|
section_name.dispose();
|
125
|
section_name = null;
|
126
|
}
|
127
|
if (section_author != null) {
|
128
|
section_author.removeElements();
|
129
|
removeControl(section_author);
|
130
|
section_author.dispose();
|
131
|
section_author = null;
|
132
|
}
|
133
|
}
|
134
|
|
135
|
/** {@inheritDoc} */
|
136
|
@Override
|
137
|
public void handleEvent(Object eventSource) {
|
138
|
if (eventSource == toggleable_cache) {
|
139
|
handleToggleableCacheField();
|
140
|
// we never want the fullTitleCache to be protected since we only
|
141
|
// use it for
|
142
|
// initiating the free text name editor
|
143
|
getEntity().setProtectedFullTitleCache(false);
|
144
|
} else if (eventSource == section_name || eventSource == section_author) {
|
145
|
if (getParentElement() instanceof AbstractCdmDetailSection) {
|
146
|
((AbstractCdmDetailSection) getParentElement()).updateTitle();
|
147
|
}
|
148
|
if (!toggleable_cache.getState()) {
|
149
|
toggleable_cache.setText(getEntity().getTitleCache());
|
150
|
}
|
151
|
}
|
152
|
if (eventSource == section_name) {
|
153
|
section_name.setEntity(getEntity());
|
154
|
getLayoutComposite().layout();
|
155
|
}
|
156
|
}
|
157
|
}
|