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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.name
;
11 import java
.util
.Iterator
;
13 import org
.apache
.logging
.log4j
.LogManager
;
14 import org
.apache
.logging
.log4j
.Logger
;
15 import org
.eclipse
.swt
.events
.SelectionListener
;
17 import eu
.etaxonomy
.cdm
.model
.common
.IdentifiableSource
;
18 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
19 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
20 import eu
.etaxonomy
.taxeditor
.ui
.element
.AbstractFormSection
;
21 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
22 import eu
.etaxonomy
.taxeditor
.ui
.element
.CheckboxElement
;
23 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
24 import eu
.etaxonomy
.taxeditor
.ui
.element
.ISelectableElement
;
25 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.SelectionArbitrator
;
27 import eu
.etaxonomy
.taxeditor
.ui
.section
.reference
.OriginalSourceElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.section
.supplemental
.AbstractSourcedEntityBaseElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.section
.supplemental
.SourceSection
;
33 * @created May 17, 2010
35 public abstract class AbstractTypeDesignationElement
<T
extends TypeDesignationBase
>
36 extends AbstractSourcedEntityBaseElement
<T
> {
38 @SuppressWarnings("unused")
39 private static final Logger logger
= LogManager
.getLogger(AbstractTypeDesignationElement
.class);
41 protected CheckboxElement checkbox_notDesignated
;
42 // protected EntitySelectionElement<Reference> selection_reference;
43 // protected TextWithLabelElement text_referenceDetail;
44 protected OriginalSourceElement singleSourceElement
;
45 protected SourceSection sourceSection
;
46 protected ICdmFormElement formElement
;
50 public AbstractTypeDesignationElement(CdmFormFactory formFactory
,
51 AbstractFormSection section
, T entity
,
52 SelectionListener removeListener
, int style
) {
53 super(formFactory
, section
, entity
, removeListener
, style
);
57 public void createControls(ICdmFormElement formElement
, int style
) {
58 // checkbox_notDesignated = formFactory.createCheckbox(formElement, "Not Designated", false, style);
59 this.formElement
= formElement
;
65 public void setEntity(T entity
){
66 super.setEntity(entity
);
67 if (this.getElements() == null || this.getElements().isEmpty()){
70 removeSourcesControls();
71 removeNotDesignatedControls();
72 if (this.entity
!= null && this.entity
.hasDesignationSource()){
73 if (singleSourceElement
== null){
74 singleSourceElement
= formFactory
.createOriginalSourceElement(formElement
, entity
, "Status Reference");
76 singleSourceElement
.setEntity(entity
.getDesignationSource(true));
78 if (singleSourceElement
!= null){
79 removeReferenceControls();
80 //check if there is still a reference
81 if (this.entity
.getCitation() != null){
82 this.entity
.setCitation(null);
83 this.entity
.setCitationMicroReference(null);
87 checkbox_notDesignated
= formFactory
.createCheckbox(formElement
, "Not Designated", entity
.isNotDesignated(), style
);
88 sourceSection
= formFactory
.createSourceSection(formElement
, StoreUtil
.getSectionStyle(SourceSection
.class, IdentifiableSource
.class.getCanonicalName()));
89 sourceSection
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 1));
90 sourceSection
.setEntity(entity
);
91 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
95 * Updates all widgets to display the latest data
97 protected void updateContent() {
98 // if (this.getParentElement() instanceof NameDetailSection
101 public void removeReferenceControls(){
102 for (Iterator
<ICdmFormElement
> iterator
= getElements().iterator();iterator
.hasNext();) {
103 ICdmFormElement childElement
= iterator
.next();
105 // if (childElement instanceof EntitySelectionElement && ((EntitySelectionElement)childElement).equals(selection_reference)) {
106 // childElement.removeElements();
108 // // unregister selection arbitrator
109 // if(childElement instanceof ISelectableElement){
110 // SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
111 // if(selectionArbitrator != null){
112 // formFactory.destroySelectionArbitrator(selectionArbitrator);
116 // // unregister from property changes
117 // formFactory.removePropertyChangeListener(childElement);
118 // singleSourceElement = null;
120 if (childElement
instanceof OriginalSourceElement
&& ((OriginalSourceElement
)childElement
).equals(singleSourceElement
)) {
122 childElement
.removeElements();
124 // unregister selection arbitrator
125 if(childElement
instanceof ISelectableElement
){
126 SelectionArbitrator selectionArbitrator
= ((ISelectableElement
) childElement
).getSelectionArbitrator();
127 if(selectionArbitrator
!= null){
128 formFactory
.destroySelectionArbitrator(selectionArbitrator
);
132 // unregister from property changes
133 formFactory
.removePropertyChangeListener(childElement
);
134 singleSourceElement
= null;
139 public void removeNotDesignatedControls(){
140 for (Iterator
<ICdmFormElement
> iterator
= getElements().iterator();iterator
.hasNext();) {
141 ICdmFormElement childElement
= iterator
.next();
143 if (childElement
instanceof CheckboxElement
&& ((CheckboxElement
)childElement
).equals(this.checkbox_notDesignated
)) {
144 childElement
.removeElements();
146 // unregister selection arbitrator
147 if(childElement
instanceof ISelectableElement
){
148 SelectionArbitrator selectionArbitrator
= ((ISelectableElement
) childElement
).getSelectionArbitrator();
149 if(selectionArbitrator
!= null){
150 formFactory
.destroySelectionArbitrator(selectionArbitrator
);
154 // unregister from property changes
155 formFactory
.removePropertyChangeListener(childElement
);
156 checkbox_notDesignated
= null;
162 public void removeSourcesControls(){
163 for (Iterator
<ICdmFormElement
> iterator
= getElements().iterator();iterator
.hasNext();) {
164 ICdmFormElement childElement
= iterator
.next();
166 if (childElement
instanceof SourceSection
) {
167 childElement
.removeElements();
169 getElements().remove(childElement
);
171 // unregister selection arbitrator
172 if(childElement
instanceof ISelectableElement
){
173 SelectionArbitrator selectionArbitrator
= ((ISelectableElement
) childElement
).getSelectionArbitrator();
174 if(selectionArbitrator
!= null){
175 formFactory
.destroySelectionArbitrator(selectionArbitrator
);
179 // unregister from property changes
180 formFactory
.removePropertyChangeListener(childElement
);
181 ((SourceSection
)childElement
).dispose();
182 sourceSection
= null;
189 public void handleEvent(Object eventSource
) {
190 // if (eventSource == selection_reference) {
191 // getEntity().setCitation(selection_reference.getEntity());
192 // setEntity(entity);
194 // if (eventSource == text_referenceDetail) {
195 // getEntity().setCitationMicroReference(text_referenceDetail.getText());
196 // setEntity(entity);
198 if (eventSource
== checkbox_notDesignated
) {
199 getEntity().setNotDesignated(checkbox_notDesignated
.getSelection());