Project

General

Profile

Download (9.46 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.events.SelectionListener;
15

    
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;
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 OriginalSourceElement singleSourceElement;
43
    protected SourceSection sourceSection;
44
    protected ICdmFormElement formElement;
45
    protected int style;
46

    
47
	/**
48
	 * <p>Constructor for AbstractTypeDesignationElement.</p>
49
	 *
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.
54
	 * @param style a int.
55
	 * @param <T> a T object.
56
	 */
57
	public AbstractTypeDesignationElement(CdmFormFactory formFactory,
58
			AbstractFormSection section, T entity,
59
			SelectionListener removeListener, int style) {
60
		super(formFactory, section, entity, removeListener, style);
61
	}
62

    
63
	/** {@inheritDoc} */
64
	@Override
65
	public void createControls(ICdmFormElement formElement, int style) {
66
	    checkbox_notDesignated = formFactory.createCheckbox(formElement, "Not Designated", false, style);
67

    
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;
71
		this.style = style;
72
		if (this.entity != null){
73
			this.setEntity(entity);
74
		}
75
	}
76

    
77
	@Override
78
	public void setEntity(T entity){
79
	    super.setEntity(entity);
80
	    if (this.getElements() == null || this.getElements().isEmpty()){
81
	    	return;
82
	    }
83
	    removeSourcesControls();
84

    
85
	    if (this.entity != null && this.entity.hasDesignationSource()){
86
	        if (singleSourceElement == null){
87
	            removeNotDesignatedControls();
88
	            singleSourceElement = formFactory.createOriginalSourceElement(formElement, entity, "Status Reference");
89
//    	        selection_reference = formFactory
90
//                        .createSelectionElement(Reference.class, formElement, "Status Reference",
91
//                                entity.getCitation(), EntitySelectionElement.ALL, style);
92
//
93
//                text_referenceDetail = formFactory.createTextWithLabelElement(
94
//                    formElement, "Reference Detail", entity.getCitationMicroReference(), style);
95
                checkbox_notDesignated = formFactory.createCheckbox(formElement, "Not Designated", entity.isNotDesignated(), style);
96
	        }
97
        }else{
98
            if (singleSourceElement != null){
99
                removeReferenceControls();
100
                //check if there is still a reference
101
                if (this.entity.getCitation() != null){
102
                    this.entity.setCitation(null);
103
                    this.entity.setCitationMicroReference(null);
104
                }
105
            }
106
        }
107
	    if (entity.hasDesignationSource()){
108
            singleSourceElement.setEntity(entity.getDesignationSource(true));
109
        }
110
	    sourceSection = formFactory.createSourceSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(SourceSection.class, IdentifiableSource.class.getCanonicalName()));
111
        sourceSection.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
112
        sourceSection.setEntity(entity);
113
        StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
114

    
115
	}
116

    
117
	/**
118
     * Updates all widgets to display the latest data
119
     */
120
    protected void updateContent() {
121
      // if (this.getParentElement() instanceof NameDetailSection
122

    
123
    }
124

    
125

    
126
    public void removeReferenceControls(){
127
        for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
128
            ICdmFormElement childElement = iterator.next();
129
            // recursion
130
//           if (childElement instanceof EntitySelectionElement && ((EntitySelectionElement)childElement).equals(selection_reference)) {
131
//                childElement.removeElements();
132
//
133
//                // unregister selection arbitrator
134
//                if(childElement instanceof ISelectableElement){
135
//                    SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
136
//                    if(selectionArbitrator != null){
137
//                        formFactory.destroySelectionArbitrator(selectionArbitrator);
138
//                    }
139
//                }
140
//
141
//                // unregister from property changes
142
//                formFactory.removePropertyChangeListener(childElement);
143
//                singleSourceElement = null;
144
//           }
145
          if (childElement instanceof OriginalSourceElement && ((OriginalSourceElement)childElement).equals(singleSourceElement)) {
146

    
147
                  childElement.removeElements();
148

    
149
                  // unregister selection arbitrator
150
                  if(childElement instanceof ISelectableElement){
151
                      SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
152
                      if(selectionArbitrator != null){
153
                          formFactory.destroySelectionArbitrator(selectionArbitrator);
154
                      }
155
                  }
156

    
157
                  // unregister from property changes
158
                  formFactory.removePropertyChangeListener(childElement);
159
                  singleSourceElement = null;
160
          }
161
        }
162

    
163
    }
164

    
165
    public void removeNotDesignatedControls(){
166
        for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
167
            ICdmFormElement childElement = iterator.next();
168
            // recursion
169
           if (childElement instanceof CheckboxElement && ((CheckboxElement)childElement).equals(this.checkbox_notDesignated)) {
170
                childElement.removeElements();
171

    
172
                // unregister selection arbitrator
173
                if(childElement instanceof ISelectableElement){
174
                    SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
175
                    if(selectionArbitrator != null){
176
                        formFactory.destroySelectionArbitrator(selectionArbitrator);
177
                    }
178
                }
179

    
180
                // unregister from property changes
181
                formFactory.removePropertyChangeListener(childElement);
182
                checkbox_notDesignated = null;
183
                break;
184
           }
185

    
186
        }
187

    
188
    }
189

    
190
    public void removeSourcesControls(){
191
        for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
192
            ICdmFormElement childElement = iterator.next();
193
            // recursion
194
           if (childElement instanceof SourceSection) {
195
                childElement.removeElements();
196

    
197
                getElements().remove(childElement);
198

    
199
                // unregister selection arbitrator
200
                if(childElement instanceof ISelectableElement){
201
                    SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
202
                    if(selectionArbitrator != null){
203
                        formFactory.destroySelectionArbitrator(selectionArbitrator);
204
                    }
205
                }
206

    
207
                // unregister from property changes
208
                formFactory.removePropertyChangeListener(childElement);
209
                ((SourceSection)childElement).dispose();
210
                sourceSection = null;
211
                break;
212
           }
213

    
214
        }
215

    
216
    }
217
    @Override
218
    public void handleEvent(Object eventSource) {
219
//        if (eventSource == selection_reference) {
220
//            getEntity().setCitation(selection_reference.getEntity());
221
//            setEntity(entity);
222
//        }
223
//        if (eventSource == text_referenceDetail) {
224
//            getEntity().setCitationMicroReference(text_referenceDetail.getText());
225
//            setEntity(entity);
226
//        }
227
        if (eventSource == checkbox_notDesignated) {
228
            getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
229
        }
230
    }
231

    
232
}
(1-1/21)