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.NomenclaturalCode;
|
17
|
import eu.etaxonomy.cdm.model.name.NonViralName;
|
18
|
import eu.etaxonomy.taxeditor.preference.IPreferenceKeys;
|
19
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
20
|
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.LsidWithExceptionLabelElement;
|
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
|
private LsidWithExceptionLabelElement textLsid;
|
41
|
|
42
|
|
43
|
public NonViralNameDetailElement(CdmFormFactory formFactory,
|
44
|
ICdmFormElement formElement) {
|
45
|
super(formFactory, formElement);
|
46
|
initIsAdvancedDetailsView();
|
47
|
|
48
|
}
|
49
|
|
50
|
/** {@inheritDoc} */
|
51
|
@Override
|
52
|
protected void createControls(ICdmFormElement formElement, final NonViralName entity, int style) {
|
53
|
|
54
|
|
55
|
if (isAdvancedView){
|
56
|
toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
|
57
|
|
58
|
combo_nomenclaturalCode = formFactory.createEnumComboElement(NomenclaturalCode.class, formElement, style);
|
59
|
combo_nomenclaturalCode.setSelection(entity.getNomenclaturalCode());
|
60
|
textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
|
61
|
//TODO RL
|
62
|
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
|
63
|
toggleable_cache.setVisible(false);
|
64
|
combo_nomenclaturalCode.setVisible(false);
|
65
|
}
|
66
|
}else{
|
67
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_CACHE)){
|
68
|
toggleable_cache = formFactory.createToggleableTextField(formElement, "Cache", entity.getTitleCache(), entity.isProtectedTitleCache() || entity.isProtectedFullTitleCache(), style);
|
69
|
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
|
70
|
toggleable_cache.setVisible(false);
|
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
|
if(PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
|
77
|
combo_nomenclaturalCode.setVisible(false);
|
78
|
}
|
79
|
}
|
80
|
if (PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_LSID)){
|
81
|
textLsid = formFactory.createLsidWithExceptionLabelElement(formElement, "Lsid", entity.getLsid(), style);
|
82
|
|
83
|
}
|
84
|
|
85
|
|
86
|
}
|
87
|
|
88
|
|
89
|
section_name = formFactory.createNameDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
|
90
|
section_name.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
91
|
addControl(section_name);
|
92
|
addElement(section_name);
|
93
|
if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_AUTHORSHIP)){
|
94
|
section_author = formFactory.createAuthorshipDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE | ExpandableComposite.EXPANDED);
|
95
|
section_author.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
96
|
addControl(section_author);
|
97
|
addElement(section_author);
|
98
|
}
|
99
|
//TODO RL
|
100
|
if (isAdvancedView || PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.SHOW_NAME_DETAILS_SECTION_HYBRID)){
|
101
|
if(!PreferencesUtil.getPreferenceStore().getBoolean(IPreferenceKeys.IS_RL)){
|
102
|
section_hybrid = formFactory.createHybridDetailSection(getConversationHolder(), formElement, null, ExpandableComposite.TWISTIE);
|
103
|
section_hybrid.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
104
|
addControl(section_hybrid);
|
105
|
addElement(section_hybrid);
|
106
|
}
|
107
|
}
|
108
|
|
109
|
|
110
|
}
|
111
|
|
112
|
/** {@inheritDoc} */
|
113
|
@Override
|
114
|
protected void updateContent() {
|
115
|
super.updateContent();
|
116
|
// disable nomenclatural code, because changing of nom.code is not
|
117
|
// implemented on library side
|
118
|
if(combo_nomenclaturalCode!=null){
|
119
|
combo_nomenclaturalCode.setEnabled(false);
|
120
|
}
|
121
|
toggleable_cache.setEnabled(getEntity().isProtectedTitleCache() || getEntity().isProtectedFullTitleCache());
|
122
|
if(toggleable_cache!=null){
|
123
|
setIrrelevant(toggleable_cache.getState(),
|
124
|
Arrays.asList(new Object[] { toggleable_cache, textLsid }));
|
125
|
}
|
126
|
}
|
127
|
|
128
|
/** {@inheritDoc} */
|
129
|
@Override
|
130
|
public void setEntity(NonViralName entity) {
|
131
|
super.setEntity(entity);
|
132
|
if (section_name!=null) {
|
133
|
section_name.setEntity(entity);
|
134
|
}
|
135
|
if (section_author!=null) {
|
136
|
section_author.setEntity(entity);
|
137
|
}
|
138
|
if (section_hybrid!=null) {
|
139
|
section_hybrid.setEntity(entity);
|
140
|
}
|
141
|
}
|
142
|
|
143
|
/** {@inheritDoc} */
|
144
|
@Override
|
145
|
public void removeElements() {
|
146
|
super.removeElements();
|
147
|
if (section_name != null) {
|
148
|
section_name.removeElements();
|
149
|
removeControl(section_name);
|
150
|
section_name.dispose();
|
151
|
section_name = null;
|
152
|
}
|
153
|
if (section_author != null) {
|
154
|
section_author.removeElements();
|
155
|
removeControl(section_author);
|
156
|
section_author.dispose();
|
157
|
section_author = null;
|
158
|
}
|
159
|
}
|
160
|
|
161
|
/** {@inheritDoc} */
|
162
|
@Override
|
163
|
public void handleEvent(Object eventSource) {
|
164
|
if (eventSource == toggleable_cache) {
|
165
|
handleToggleableCacheField();
|
166
|
// we never want the fullTitleCache to be protected since we only
|
167
|
// use it for
|
168
|
// initiating the free text name editor
|
169
|
getEntity().setProtectedFullTitleCache(false);
|
170
|
} else if (eventSource == section_name || eventSource == section_author) {
|
171
|
if (getParentElement() instanceof AbstractCdmDetailSection) {
|
172
|
((AbstractCdmDetailSection) getParentElement()).updateTitle();
|
173
|
}
|
174
|
if (toggleable_cache != null){
|
175
|
if (!toggleable_cache.getState()) {
|
176
|
toggleable_cache.setText(getEntity().getTitleCache());
|
177
|
}
|
178
|
}
|
179
|
}
|
180
|
if (eventSource == section_name) {
|
181
|
section_name.setEntity(getEntity());
|
182
|
getLayoutComposite().layout();
|
183
|
}
|
184
|
else if(eventSource==textLsid){
|
185
|
getEntity().setLsid(textLsid.parseText());
|
186
|
}
|
187
|
}
|
188
|
@Override
|
189
|
protected void handleToggleableCacheField() {
|
190
|
boolean pushedState = toggleable_cache.getState();
|
191
|
|
192
|
getEntity().setTitleCache(toggleable_cache.getText(), pushedState);
|
193
|
setIrrelevant(pushedState, Arrays.asList(new Object[] { toggleable_cache, textLsid }));
|
194
|
updateToggleableCacheField();
|
195
|
}
|
196
|
|
197
|
|
198
|
|
199
|
|
200
|
// @Override
|
201
|
// public void toggleAdvancedMediaView(){
|
202
|
// mediaDetailElement.toggleAdvancedMediaView();
|
203
|
// }
|
204
|
}
|