-// $Id$
/**
* Copyright (C) 2007 EDIT
-* European Distributed Institute of Taxonomy
+* European Distributed Institute of Taxonomy
* http://www.e-taxonomy.eu
-*
+*
* The contents of this file are subject to the Mozilla Public License Version 1.1
* See LICENSE.TXT at the top of this package for the full license terms.
*/
package eu.etaxonomy.taxeditor.ui.section.name;
+import java.util.Iterator;
+
import org.eclipse.swt.events.SelectionListener;
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
-import eu.etaxonomy.taxeditor.ui.campanula.compatibility.ICdmFormElement;
+import eu.etaxonomy.cdm.model.reference.Reference;
+import eu.etaxonomy.taxeditor.store.StoreUtil;
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
-import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractReferencedEntityElement;
+import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
+import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
+import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
+import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
+import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractSourcedEntityBaseElement;
+import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
/**
* <p>Abstract AbstractTypeDesignationElement class.</p>
* @created May 17, 2010
* @version 1.0
*/
-public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBase> extends AbstractReferencedEntityElement<T> {
+public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBase> extends AbstractSourcedEntityBaseElement<T> {
protected CheckboxElement checkbox_notDesignated;
-
+ protected EntitySelectionElement<Reference> selection_reference;
+ protected TextWithLabelElement text_referenceDetail;
+ protected ICdmFormElement formElement;
+ protected int style;
/**
* <p>Constructor for AbstractTypeDesignationElement.</p>
SelectionListener removeListener, int style) {
super(formFactory, section, entity, removeListener, style);
}
-
+
/** {@inheritDoc} */
@Override
public void createControls(ICdmFormElement formElement, int style) {
checkbox_notDesignated = formFactory.createCheckbox(formElement, "Not Designated", false, style);
- super.createControls(formElement, style);
+ this.formElement = formElement;
+ this.style = style;
+ }
+
+ @Override
+ public void setEntity(T entity){
+ super.setEntity(entity);
+
+ if (this.entity != null && this.entity.isLectoType()){
+ if (selection_reference == null){
+ removeNotDesignatedControls();
+ selection_reference = formFactory
+ .createSelectionElement(Reference.class, formElement, "Status Reference",
+ entity.getCitation(), EntitySelectionElement.ALL, style);
+
+ text_referenceDetail = formFactory.createTextWithLabelElement(
+ formElement, "Reference Detail", entity.getCitationMicroReference(), style);
+ checkbox_notDesignated = formFactory.createCheckbox(formElement, "Not Designated", entity.isNotDesignated(), style);
+ }
+ }else{
+ if (selection_reference != null){
+ removeReferenceControls();
+ //check if there is still a reference
+ if (this.entity.getCitation() != null){
+ this.entity.setCitation(null);
+ this.entity.setCitationMicroReference(null);
+ }
+ }
+ }
+ StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
+
}
-
+
+ /**
+ * Updates all widgets to display the latest data
+ */
+ protected void updateContent() {
+ // if (this.getParentElement() instanceof NameDetailSection
+
+ }
+
+
+ public void removeReferenceControls(){
+ for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
+ ICdmFormElement childElement = iterator.next();
+ // recursion
+ if (childElement instanceof EntitySelectionElement && ((EntitySelectionElement)childElement).equals(selection_reference)) {
+ childElement.removeElements();
+
+ // unregister selection arbitrator
+ if(childElement instanceof ISelectableElement){
+ SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
+ if(selectionArbitrator != null){
+ formFactory.destroySelectionArbitrator(selectionArbitrator);
+ }
+ }
+
+ // unregister from property changes
+ formFactory.removePropertyChangeListener(childElement);
+ selection_reference = null;
+ }
+ if (childElement instanceof TextWithLabelElement && ((TextWithLabelElement)childElement).equals(text_referenceDetail)) {
+
+ childElement.removeElements();
+
+ // unregister selection arbitrator
+ if(childElement instanceof ISelectableElement){
+ SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
+ if(selectionArbitrator != null){
+ formFactory.destroySelectionArbitrator(selectionArbitrator);
+ }
+ }
+
+ // unregister from property changes
+ formFactory.removePropertyChangeListener(childElement);
+ text_referenceDetail = null;
+
+
+ }
+ }
+
+ }
+
+ public void removeNotDesignatedControls(){
+ for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
+ ICdmFormElement childElement = iterator.next();
+ // recursion
+ if (childElement instanceof CheckboxElement && ((CheckboxElement)childElement).equals(this.checkbox_notDesignated)) {
+ childElement.removeElements();
+
+ // unregister selection arbitrator
+ if(childElement instanceof ISelectableElement){
+ SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
+ if(selectionArbitrator != null){
+ formFactory.destroySelectionArbitrator(selectionArbitrator);
+ }
+ }
+
+ // unregister from property changes
+ formFactory.removePropertyChangeListener(childElement);
+ checkbox_notDesignated = null;
+ }
+
+ }
+
+ }
+ @Override
+ public void handleEvent(Object eventSource) {
+ if (eventSource == selection_reference) {
+ getEntity().setCitation(selection_reference.getEntity());
+ setEntity(entity);
+ }
+ if (eventSource == text_referenceDetail) {
+ getEntity().setCitationMicroReference(text_referenceDetail.getText());
+ setEntity(entity);
+ }
+ if (eventSource == checkbox_notDesignated) {
+ getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
+ }
+ }
+
}