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
.SWT
;
15 import org
.eclipse
.swt
.events
.SelectionListener
;
17 import eu
.etaxonomy
.cdm
.model
.name
.TypeDesignationBase
;
18 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
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
.SelectionArbitrator
;
26 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
27 import eu
.etaxonomy
.taxeditor
.ui
.section
.supplemental
.AbstractSourcedEntityBaseElement
;
28 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
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 ICdmFormElement formElement
;
45 * <p>Constructor for AbstractTypeDesignationElement.</p>
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.
52 * @param <T> a T object.
54 public AbstractTypeDesignationElement(CdmFormFactory formFactory
,
55 AbstractFormSection section
, T entity
,
56 SelectionListener removeListener
, int style
) {
57 super(formFactory
, section
, entity
, removeListener
, style
);
62 public void createControls(ICdmFormElement formElement
, int style
) {
63 checkbox_notDesignated
= formFactory
.createCheckbox(formElement
, "Not Designated", false, style
);
64 this.formElement
= formElement
;
68 public void setEntity(T entity
){
69 super.setEntity(entity
);
71 if (this.entity
!= null && this.entity
.isLectoType()){
72 if (selection_reference
== null){
73 selection_reference
= formFactory
74 .createSelectionElement(Reference
.class, formElement
, "Status Reference",
75 entity
.getCitation(), EntitySelectionElement
.ALL
, SWT
.NULL
);
77 text_referenceDetail
= formFactory
.createTextWithLabelElement(
78 formElement
, "Status Reference Detail", entity
.getCitationMicroReference(), SWT
.NULL
);
81 if (selection_reference
!= null){
82 removeReferenceControls();
83 //check if there is still a reference
84 if (this.entity
.getCitation() != null){
85 this.entity
.setCitation(null);
86 this.entity
.setCitationMicroReference(null);
90 StoreUtil
.reflowParentScrolledForm(getLayoutComposite(), true);
95 * Updates all widgets to display the latest data
97 protected void updateContent() {
98 // if (this.getParentElement() instanceof NameDetailSection
103 public void removeReferenceControls(){
104 for (Iterator
<ICdmFormElement
> iterator
= getElements().iterator();iterator
.hasNext();) {
105 ICdmFormElement childElement
= iterator
.next();
107 if (childElement
instanceof EntitySelectionElement
&& ((EntitySelectionElement
)childElement
).equals(selection_reference
)) {
108 childElement
.removeElements();
110 // unregister selection arbitrator
111 if(childElement
instanceof ISelectableElement
){
112 SelectionArbitrator selectionArbitrator
= ((ISelectableElement
) childElement
).getSelectionArbitrator();
113 if(selectionArbitrator
!= null){
114 formFactory
.destroySelectionArbitrator(selectionArbitrator
);
118 // unregister from property changes
119 formFactory
.removePropertyChangeListener(childElement
);
120 selection_reference
= null;
122 if (childElement
instanceof TextWithLabelElement
&& ((TextWithLabelElement
)childElement
).equals(text_referenceDetail
)) {
124 childElement
.removeElements();
126 // unregister selection arbitrator
127 if(childElement
instanceof ISelectableElement
){
128 SelectionArbitrator selectionArbitrator
= ((ISelectableElement
) childElement
).getSelectionArbitrator();
129 if(selectionArbitrator
!= null){
130 formFactory
.destroySelectionArbitrator(selectionArbitrator
);
134 // unregister from property changes
135 formFactory
.removePropertyChangeListener(childElement
);
136 text_referenceDetail
= null;
144 public void handleEvent(Object eventSource
) {
145 if (eventSource
== selection_reference
) {
146 getEntity().setCitation(selection_reference
.getEntity());
149 if (eventSource
== text_referenceDetail
) {
150 getEntity().setCitationMicroReference(text_referenceDetail
.getText());