Project

General

Profile

Download (5.57 KB) Statistics
| Branch: | Tag: | Revision:
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.SWT;
15
import org.eclipse.swt.events.SelectionListener;
16

    
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;
29

    
30
/**
31
 * <p>Abstract AbstractTypeDesignationElement class.</p>
32
 *
33
 * @author n.hoffmann
34
 * @created May 17, 2010
35
 * @version 1.0
36
 */
37
public abstract class AbstractTypeDesignationElement<T extends TypeDesignationBase> extends AbstractSourcedEntityBaseElement<T> {
38

    
39
	protected CheckboxElement checkbox_notDesignated;
40
	protected EntitySelectionElement<Reference> selection_reference;
41
    protected TextWithLabelElement text_referenceDetail;
42
    protected ICdmFormElement formElement;
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
	}
66

    
67
	@Override
68
	public void setEntity(T entity){
69
	    super.setEntity(entity);
70

    
71
	    if (this.entity != null && this.entity.isLectoType()){
72
	        if (selection_reference == null){
73
    	        selection_reference = formFactory
74
                        .createSelectionElement(Reference.class, formElement, "Reference",
75
                                entity.getCitation(), EntitySelectionElement.ALL, SWT.NULL);
76

    
77
                text_referenceDetail = formFactory.createTextWithLabelElement(
78
                    formElement, "Reference Detail", null, SWT.NULL);
79
	        }
80
        }else{
81
            if (selection_reference != null){
82
                removeReferenceControls();
83
            }
84
        }
85
        StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
86

    
87
	}
88

    
89
	/**
90
     * Updates all widgets to display the latest data
91
     */
92
    protected void updateContent() {
93
      // if (this.getParentElement() instanceof NameDetailSection
94

    
95
    }
96

    
97

    
98
    public void removeReferenceControls(){
99
        for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
100
            ICdmFormElement childElement = iterator.next();
101
            // recursion
102
           if (childElement instanceof EntitySelectionElement && ((EntitySelectionElement)childElement).equals(selection_reference)) {
103
                childElement.removeElements();
104

    
105
                // unregister selection arbitrator
106
                if(childElement instanceof ISelectableElement){
107
                    SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
108
                    if(selectionArbitrator != null){
109
                        formFactory.destroySelectionArbitrator(selectionArbitrator);
110
                    }
111
                }
112

    
113
                // unregister from property changes
114
                formFactory.removePropertyChangeListener(childElement);
115
                selection_reference = null;
116
           }
117
          if (childElement instanceof TextWithLabelElement && ((TextWithLabelElement)childElement).equals(text_referenceDetail)) {
118

    
119
                  childElement.removeElements();
120

    
121
                  // unregister selection arbitrator
122
                  if(childElement instanceof ISelectableElement){
123
                      SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
124
                      if(selectionArbitrator != null){
125
                          formFactory.destroySelectionArbitrator(selectionArbitrator);
126
                      }
127
                  }
128

    
129
                  // unregister from property changes
130
                  formFactory.removePropertyChangeListener(childElement);
131
                  text_referenceDetail = null;
132

    
133

    
134
          }
135
        }
136

    
137
    }
138
    @Override
139
    public void handleEvent(Object eventSource) {
140
        if (eventSource == selection_reference) {
141
            getEntity().setCitation(selection_reference.getEntity());
142
            setEntity(entity);
143
        }
144
        if (eventSource == text_referenceDetail) {
145
            getEntity().setCitationMicroReference(text_referenceDetail.getText());
146
            setEntity(entity);
147
        }
148
    }
149

    
150
}
(1-1/21)