Project

General

Profile

Download (9.8 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.apache.logging.log4j.LogManager;
15
import org.apache.logging.log4j.Logger;
16
import org.eclipse.swt.events.SelectionListener;
17

    
18
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
19
import eu.etaxonomy.cdm.model.name.TypeDesignationBase;
20
import eu.etaxonomy.taxeditor.model.MessagingUtils;
21
import eu.etaxonomy.taxeditor.store.StoreUtil;
22
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
23
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
24
import eu.etaxonomy.taxeditor.ui.element.CheckboxElement;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
27
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
28
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
29
import eu.etaxonomy.taxeditor.ui.section.reference.OriginalSourceElement;
30
import eu.etaxonomy.taxeditor.ui.section.supplemental.AbstractSourcedEntityBaseElement;
31
import eu.etaxonomy.taxeditor.ui.section.supplemental.SourceSection;
32

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

    
42
	private static final Logger logger = LogManager.getLogger(AbstractTypeDesignationElement.class);
43
	protected CheckboxElement checkbox_notDesignated;
44
//	protected EntitySelectionElement<Reference> selection_reference;
45
//    protected TextWithLabelElement text_referenceDetail;
46
	protected OriginalSourceElement singleSourceElement;
47
    protected SourceSection sourceSection;
48
    protected ICdmFormElement formElement;
49
    protected int style;
50

    
51
	/**
52
	 * <p>Constructor for AbstractTypeDesignationElement.</p>
53
	 *
54
	 * @param formFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
55
	 * @param section a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection} object.
56
	 * @param entity a T object.
57
	 * @param removeListener a {@link org.eclipse.swt.events.SelectionListener} object.
58
	 * @param style a int.
59
	 * @param <T> a T object.
60
	 */
61
	public AbstractTypeDesignationElement(CdmFormFactory formFactory,
62
			AbstractFormSection section, T entity,
63
			SelectionListener removeListener, int style) {
64
		super(formFactory, section, entity, removeListener, style);
65
	}
66

    
67
	/** {@inheritDoc} */
68
	@Override
69
	public void createControls(ICdmFormElement formElement, int style) {
70
	    checkbox_notDesignated = formFactory.createCheckbox(formElement, "Not Designated", false, style);
71

    
72
        sourceSection = formFactory.createSourceSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(SourceSection.class, IdentifiableSource.class.getCanonicalName()));
73
        sourceSection.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
74
		this.formElement = formElement;
75
		this.style = style;
76
		if (this.entity != null){
77
			this.setEntity(entity);
78
		}
79
	}
80

    
81
	@Override
82
	public void setEntity(T entity){
83
	    super.setEntity(entity);
84
	    if (this.getElements() == null || this.getElements().isEmpty()){
85
	    	return;
86
	    }
87
	    removeSourcesControls();
88

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

    
121
	}
122

    
123
	/**
124
     * Updates all widgets to display the latest data
125
     */
126
    protected void updateContent() {
127
      // if (this.getParentElement() instanceof NameDetailSection
128

    
129
    }
130

    
131

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

    
153
                  childElement.removeElements();
154

    
155
                  // unregister selection arbitrator
156
                  if(childElement instanceof ISelectableElement){
157
                      SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
158
                      if(selectionArbitrator != null){
159
                          formFactory.destroySelectionArbitrator(selectionArbitrator);
160
                      }
161
                  }
162

    
163
                  // unregister from property changes
164
                  formFactory.removePropertyChangeListener(childElement);
165
                  singleSourceElement = null;
166
          }
167
        }
168

    
169
    }
170

    
171
    public void removeNotDesignatedControls(){
172
        for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
173
            ICdmFormElement childElement = iterator.next();
174
            // recursion
175
           if (childElement instanceof CheckboxElement && ((CheckboxElement)childElement).equals(this.checkbox_notDesignated)) {
176
                childElement.removeElements();
177

    
178
                // unregister selection arbitrator
179
                if(childElement instanceof ISelectableElement){
180
                    SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
181
                    if(selectionArbitrator != null){
182
                        formFactory.destroySelectionArbitrator(selectionArbitrator);
183
                    }
184
                }
185

    
186
                // unregister from property changes
187
                formFactory.removePropertyChangeListener(childElement);
188
                checkbox_notDesignated = null;
189
                break;
190
           }
191

    
192
        }
193

    
194
    }
195

    
196
    public void removeSourcesControls(){
197
        for (Iterator<ICdmFormElement> iterator = getElements().iterator();iterator.hasNext();) {
198
            ICdmFormElement childElement = iterator.next();
199
            // recursion
200
           if (childElement instanceof SourceSection) {
201
                childElement.removeElements();
202

    
203
                getElements().remove(childElement);
204

    
205
                // unregister selection arbitrator
206
                if(childElement instanceof ISelectableElement){
207
                    SelectionArbitrator selectionArbitrator = ((ISelectableElement) childElement).getSelectionArbitrator();
208
                    if(selectionArbitrator != null){
209
                        formFactory.destroySelectionArbitrator(selectionArbitrator);
210
                    }
211
                }
212

    
213
                // unregister from property changes
214
                formFactory.removePropertyChangeListener(childElement);
215
                ((SourceSection)childElement).dispose();
216
                sourceSection = null;
217
                break;
218
           }
219

    
220
        }
221

    
222
    }
223
    @Override
224
    public void handleEvent(Object eventSource) {
225
//        if (eventSource == selection_reference) {
226
//            getEntity().setCitation(selection_reference.getEntity());
227
//            setEntity(entity);
228
//        }
229
//        if (eventSource == text_referenceDetail) {
230
//            getEntity().setCitationMicroReference(text_referenceDetail.getText());
231
//            setEntity(entity);
232
//        }
233
        if (eventSource == checkbox_notDesignated) {
234
            getEntity().setNotDesignated(checkbox_notDesignated.getSelection());
235
        }
236
    }
237

    
238
}
(1-1/21)