Project

General

Profile

Download (3.06 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
package eu.etaxonomy.taxeditor.ui.section.supplemental;
10

    
11
import org.eclipse.swt.events.SelectionListener;
12

    
13
import eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase;
14
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
15
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
16
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
17
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
18
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
19
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
20
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
21
import eu.etaxonomy.taxeditor.ui.section.reference.OriginalSourceElement;
22

    
23
/**
24
 * @author n.hoffmann
25
 * @created Mar 25, 2010
26
 */
27
public abstract class AbstractSourcedEntityElement<T extends SingleSourcedEntityBase>
28
		extends AbstractEntityCollectionElement<T> implements ISelectableElement {
29

    
30
	private SelectionArbitrator selectionArbitrator;
31
	private OriginalSourceElement sourceElement;
32
	private String label = "Source";
33
//	protected EntitySelectionElement<Reference> selection_reference;
34
//	protected TextWithLabelElement text_referenceDetail;
35

    
36
	protected boolean isCommonNameReference = false;
37

    
38
	public AbstractSourcedEntityElement(CdmFormFactory formFactory,
39
			AbstractFormSection section, T entity,
40
			SelectionListener removeListener, String label, int style, boolean isCommonNameReference) {
41
		super(formFactory, section, entity, removeListener, null, style);
42
		// make this element selectable
43
		if(formFactory.getSelectionProvider() != null){
44
			selectionArbitrator = formFactory.createSelectionArbitrator(this);
45
		}
46
		this.isCommonNameReference = isCommonNameReference;
47

    
48

    
49
	}
50

    
51
    public AbstractSourcedEntityElement(CdmFormFactory formFactory,
52
            AbstractFormSection section, T entity,
53
            SelectionListener removeListener, String label, int style) {
54
        this(formFactory, section, entity, removeListener, label, style, false);
55
    }
56

    
57

    
58
    @Override
59
	public void createControls(ICdmFormElement formElement, int style) {
60

    
61
	    sourceElement = formFactory.createOriginalSourceElement(formElement, entity, label);
62

    
63
        if (entity.getSource() == null){
64
            DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(null, null);
65
            entity.setSource(source);
66
            sourceElement.setEntity(source);
67
        }else{
68
            sourceElement.setEntity(entity.getSource());
69

    
70
        }
71

    
72
	}
73

    
74
	@Override
75
	public void setEntity(T entity) {
76
		this.entity = entity;
77
	}
78

    
79
	@Override
80
    public SelectionArbitrator getSelectionArbitrator() {
81
		return selectionArbitrator;
82
	}
83

    
84
	public void setSourceLabel(String sourceLabel){
85
	    this.label = sourceLabel;
86
	    if (sourceElement != null){
87
	        this.sourceElement.getReferenceSelectionElement().setLabel(sourceLabel);
88
	    }
89
	}
90

    
91
}
(4-4/21)