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.Iterator;
|
13
|
|
14
|
import org.eclipse.swt.events.SelectionListener;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
17
|
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
|
18
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
19
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
20
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
|
26
|
import eu.etaxonomy.taxeditor.ui.section.reference.OriginalSourceElement;
|
27
|
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractSourcedEntityBaseElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.section.supplemental.SourceSection;
|
29
|
|
30
|
/**
|
31
|
* <p>Abstract AbstractTypeDesignationElement class.</p>
|
32
|
*
|
33
|
* @author n.hoffmann
|
34
|
* @created May 17, 2010
|
35
|
* @version 1.0
|
36
|
*/
|
37
|
public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBase> extends AbstractSourcedEntityBaseElement<T> {
|
38
|
|
39
|
protected CheckboxElement checkbox_notDesignated;
|
40
|
// protected EntitySelectionElement<Reference> selection_reference;
|
41
|
// protected TextWithLabelElement text_referenceDetail;
|
42
|
protected OriginalSourceElement singleSourceElement;
|
43
|
protected SourceSection sourceSection;
|
44
|
protected ICdmFormElement formElement;
|
45
|
protected int style;
|
46
|
|
47
|
/**
|
48
|
* <p>Constructor for AbstractTypeDesignationElement.</p>
|
49
|
*
|
50
|
* @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
51
|
* @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
|
52
|
* @param entity a T object.
|
53
|
* @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
|
54
|
* @param style a int.
|
55
|
* @param <T> a T object.
|
56
|
*/
|
57
|
public AbstractTypeDesignationElement(CdmFormFactory formFactory,
|
58
|
AbstractFormSection section, T entity,
|
59
|
SelectionListener removeListener, int style) {
|
60
|
super(formFactory, section, entity, removeListener, style);
|
61
|
}
|
62
|
|
63
|
/** {@inheritDoc} */
|
64
|
@Override
|
65
|
public void createControls(ICdmFormElement formElement, int style) {
|
66
|
checkbox_notDesignated = formFactory.createCheckbox(formElement, "Not Designated", false, style);
|
67
|
|
68
|
sourceSection = formFactory.createSourceSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(SourceSection.class, IdentifiableSource.class.getCanonicalName()));
|
69
|
sourceSection.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
70
|
this.formElement = formElement;
|
71
|
this.style = style;
|
72
|
}
|
73
|
|
74
|
@Override
|
75
|
public void setEntity(T entity){
|
76
|
super.setEntity(entity);
|
77
|
removeSourcesControls();
|
78
|
|
79
|
if (this.entity != null && this.entity.hasDesignationSource()){
|
80
|
if (singleSourceElement == null){
|
81
|
removeNotDesignatedControls();
|
82
|
singleSourceElement = formFactory.createOriginalSourceElement(formElement, entity, "Status Reference");
|
83
|
// selection_reference = formFactory
|
84
|
// .createSelectionElement(Reference.class, formElement, "Status Reference",
|
85
|
// entity.getCitation(), EntitySelectionElement.ALL, style);
|
86
|
//
|
87
|
// text_referenceDetail = formFactory.createTextWithLabelElement(
|
88
|
// formElement, "Reference Detail", entity.getCitationMicroReference(), style);
|
89
|
checkbox_notDesignated = formFactory.createCheckbox(formElement, "Not Designated", entity.isNotDesignated(), style);
|
90
|
}
|
91
|
}else{
|
92
|
if (singleSourceElement != null){
|
93
|
removeReferenceControls();
|
94
|
//check if there is still a reference
|
95
|
if (this.entity.getCitation() != null){
|
96
|
this.entity.setCitation(null);
|
97
|
this.entity.setCitationMicroReference(null);
|
98
|
}
|
99
|
}
|
100
|
}
|
101
|
if (entity.hasDesignationSource()){
|
102
|
singleSourceElement.setEntity(entity.getDesignationSource(true));
|
103
|
}
|
104
|
sourceSection = formFactory.createSourceSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(SourceSection.class, IdentifiableSource.class.getCanonicalName()));
|
105
|
sourceSection.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
|
106
|
sourceSection.setEntity(entity);
|
107
|
StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
|
108
|
|
109
|
}
|
110
|
|
111
|
/**
|
112
|
* Updates all widgets to display the latest data
|
113
|
*/
|
114
|
protected void updateContent() {
|
115
|
// if (this.getParentElement() instanceof NameDetailSection
|
116
|
|
117
|
}
|
118
|
|
119
|
|
120
|
public void removeReferenceControls(){
|
121
|
for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
|
122
|
ICdmFormElement childElement = iterator.next();
|
123
|
// recursion
|
124
|
// if (childElement instanceof EntitySelectionElement && ((EntitySelectionElement)childElement).equals(selection_reference)) {
|
125
|
// childElement.removeElements();
|
126
|
//
|
127
|
// // unregister selection arbitrator
|
128
|
// if(childElement instanceof ISelectableElement){
|
129
|
// SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
|
130
|
// if(selectionArbitrator != null){
|
131
|
// formFactory.destroySelectionArbitrator(selectionArbitrator);
|
132
|
// }
|
133
|
// }
|
134
|
//
|
135
|
// // unregister from property changes
|
136
|
// formFactory.removePropertyChangeListener(childElement);
|
137
|
// singleSourceElement = null;
|
138
|
// }
|
139
|
if (childElement instanceof OriginalSourceElement && ((OriginalSourceElement)childElement).equals(singleSourceElement)) {
|
140
|
|
141
|
childElement.removeElements();
|
142
|
|
143
|
// unregister selection arbitrator
|
144
|
if(childElement instanceof ISelectableElement){
|
145
|
SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
|
146
|
if(selectionArbitrator != null){
|
147
|
formFactory.destroySelectionArbitrator(selectionArbitrator);
|
148
|
}
|
149
|
}
|
150
|
|
151
|
// unregister from property changes
|
152
|
formFactory.removePropertyChangeListener(childElement);
|
153
|
singleSourceElement = null;
|
154
|
}
|
155
|
}
|
156
|
|
157
|
}
|
158
|
|
159
|
public void removeNotDesignatedControls(){
|
160
|
for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
|
161
|
ICdmFormElement childElement = iterator.next();
|
162
|
// recursion
|
163
|
if (childElement instanceof CheckboxElement && ((CheckboxElement)childElement).equals(this.checkbox_notDesignated)) {
|
164
|
childElement.removeElements();
|
165
|
|
166
|
// unregister selection arbitrator
|
167
|
if(childElement instanceof ISelectableElement){
|
168
|
SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
|
169
|
if(selectionArbitrator != null){
|
170
|
formFactory.destroySelectionArbitrator(selectionArbitrator);
|
171
|
}
|
172
|
}
|
173
|
|
174
|
// unregister from property changes
|
175
|
formFactory.removePropertyChangeListener(childElement);
|
176
|
checkbox_notDesignated = null;
|
177
|
break;
|
178
|
}
|
179
|
|
180
|
}
|
181
|
|
182
|
}
|
183
|
|
184
|
public void removeSourcesControls(){
|
185
|
for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
|
186
|
ICdmFormElement childElement = iterator.next();
|
187
|
// recursion
|
188
|
if (childElement instanceof SourceSection) {
|
189
|
childElement.removeElements();
|
190
|
|
191
|
getElements().remove(childElement);
|
192
|
|
193
|
// unregister selection arbitrator
|
194
|
if(childElement instanceof ISelectableElement){
|
195
|
SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
|
196
|
if(selectionArbitrator != null){
|
197
|
formFactory.destroySelectionArbitrator(selectionArbitrator);
|
198
|
}
|
199
|
}
|
200
|
|
201
|
// unregister from property changes
|
202
|
formFactory.removePropertyChangeListener(childElement);
|
203
|
((SourceSection)childElement).dispose();
|
204
|
sourceSection = null;
|
205
|
break;
|
206
|
}
|
207
|
|
208
|
}
|
209
|
|
210
|
}
|
211
|
@Override
|
212
|
public void handleEvent(Object eventSource) {
|
213
|
// if (eventSource == selection_reference) {
|
214
|
// getEntity().setCitation(selection_reference.getEntity());
|
215
|
// setEntity(entity);
|
216
|
// }
|
217
|
// if (eventSource == text_referenceDetail) {
|
218
|
// getEntity().setCitationMicroReference(text_referenceDetail.getText());
|
219
|
// setEntity(entity);
|
220
|
// }
|
221
|
if (eventSource == checkbox_notDesignated) {
|
222
|
getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
|
223
|
}
|
224
|
}
|
225
|
|
226
|
}
|