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