2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
12 import java
.util
.Iterator
;
14 import org
.eclipse
.swt
.events
.SelectionListener
;
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
;
31 * <p>Abstract AbstractTypeDesignationElement class.</p>
34 * @created May 17, 2010
37 public abstract class AbstractTypeDesignationElement
<T
extends TypeDesignationBase
> extends AbstractSourcedEntityBaseElement
<T
> {
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
;
48 * <p>Constructor for AbstractTypeDesignationElement.</p>
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.
55 * @param <T> a T object.
57 public AbstractTypeDesignationElement(CdmFormFactory formFactory
,
58 AbstractFormSection section
, T entity
,
59 SelectionListener removeListener
, int style
) {
60 super(formFactory
, section
, entity
, removeListener
, style
);
65 public void createControls(ICdmFormElement formElement
, int style
) {
66 checkbox_notDesignated
= formFactory
.createCheckbox(formElement
, "Not Designated", false, style
);
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
;
75 public void setEntity(T entity
){
76 super.setEntity(entity
);
77 removeSourcesControls();
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);
87 // text_referenceDetail = formFactory.createTextWithLabelElement(
88 // formElement, "Reference Detail", entity.getCitationMicroReference(), style);
89 checkbox_notDesignated
= formFactory
.createCheckbox(formElement
, "Not Designated", entity
.isNotDesignated(), style
);
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);
101 if (entity
.hasDesignationSource()){
102 singleSourceElement
.setEntity(entity
.getSource());
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);
112 * Updates all widgets to display the latest data
114 protected void updateContent() {
115 // if (this.getParentElement() instanceof NameDetailSection
120 public void removeReferenceControls(){
121 for (Iterator
<ICdmFormElement
> iterator
= getElements().iterator();iterator
.hasNext();) {
122 ICdmFormElement childElement
= iterator
.next();
124 // if (childElement instanceof EntitySelectionElement && ((EntitySelectionElement)childElement).equals(selection_reference)) {
125 // childElement.removeElements();
127 // // unregister selection arbitrator
128 // if(childElement instanceof ISelectableElement){
129 // SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
130 // if(selectionArbitrator != null){
131 // formFactory.destroySelectionArbitrator(selectionArbitrator);
135 // // unregister from property changes
136 // formFactory.removePropertyChangeListener(childElement);
137 // singleSourceElement = null;
139 if (childElement
instanceof OriginalSourceElement
&& ((OriginalSourceElement
)childElement
).equals(singleSourceElement
)) {
141 childElement
.removeElements();
143 // unregister selection arbitrator
144 if(childElement
instanceof ISelectableElement
){
145 SelectionArbitrator selectionArbitrator
= ((ISelectableElement
) childElement
).getSelectionArbitrator();
146 if(selectionArbitrator
!= null){
147 formFactory
.destroySelectionArbitrator(selectionArbitrator
);
151 // unregister from property changes
152 formFactory
.removePropertyChangeListener(childElement
);
153 singleSourceElement
= null;
159 public void removeNotDesignatedControls(){
160 for (Iterator
<ICdmFormElement
> iterator
= getElements().iterator();iterator
.hasNext();) {
161 ICdmFormElement childElement
= iterator
.next();
163 if (childElement
instanceof CheckboxElement
&& ((CheckboxElement
)childElement
).equals(this.checkbox_notDesignated
)) {
164 childElement
.removeElements();
166 // unregister selection arbitrator
167 if(childElement
instanceof ISelectableElement
){
168 SelectionArbitrator selectionArbitrator
= ((ISelectableElement
) childElement
).getSelectionArbitrator();
169 if(selectionArbitrator
!= null){
170 formFactory
.destroySelectionArbitrator(selectionArbitrator
);
174 // unregister from property changes
175 formFactory
.removePropertyChangeListener(childElement
);
176 checkbox_notDesignated
= null;
184 public void removeSourcesControls(){
185 for (Iterator
<ICdmFormElement
> iterator
= getElements().iterator();iterator
.hasNext();) {
186 ICdmFormElement childElement
= iterator
.next();
188 if (childElement
instanceof SourceSection
) {
189 childElement
.removeElements();
191 getElements().remove(childElement
);
193 // unregister selection arbitrator
194 if(childElement
instanceof ISelectableElement
){
195 SelectionArbitrator selectionArbitrator
= ((ISelectableElement
) childElement
).getSelectionArbitrator();
196 if(selectionArbitrator
!= null){
197 formFactory
.destroySelectionArbitrator(selectionArbitrator
);
201 // unregister from property changes
202 formFactory
.removePropertyChangeListener(childElement
);
203 ((SourceSection
)childElement
).dispose();
204 sourceSection
= null;
212 public void handleEvent(Object eventSource
) {
213 // if (eventSource == selection_reference) {
214 // getEntity().setCitation(selection_reference.getEntity());
215 // setEntity(entity);
217 // if (eventSource == text_referenceDetail) {
218 // getEntity().setCitationMicroReference(text_referenceDetail.getText());
219 // setEntity(entity);
221 if (eventSource
== checkbox_notDesignated
) {
222 getEntity().setNotDesignated(checkbox_notDesignated
.getSelection());