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
        StoreUtil.reflowParentScrolledForm(getLayoutComposite(), true);
119
        MessagingUtils.info("New source section created.");
120
	}
121

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

    
128
    }
129

    
130

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

    
152
                  childElement.removeElements();
153

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

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

    
168
    }
169

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

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

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

    
191
        }
192

    
193
    }
194

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

    
202
                getElements().remove(childElement);
203

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

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

    
219
        }
220

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

    
237
}
(1-1/21)