Project

General

Profile

Download (3.47 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.supplemental;
11

    
12
import org.eclipse.swt.SWT;
13
import org.eclipse.swt.events.SelectionListener;
14

    
15
import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
16
import eu.etaxonomy.cdm.model.reference.Reference;
17
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
18
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
19
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
20
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
21
import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
22
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
23
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
24
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
25
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
26

    
27
/**
28
 * @author n.hoffmann
29
 * @created Mar 25, 2010
30
 * @version 1.0
31
 */
32
public abstract class AbstractReferencedEntityElement<T extends ReferencedEntityBase>
33
		extends AbstractEntityCollectionElement<T> implements ISelectableElement {
34

    
35
	private SelectionArbitrator selectionArbitrator;
36

    
37
	protected EntitySelectionElement<Reference> selection_reference;
38
	protected TextWithLabelElement text_referenceDetail;
39

    
40
	protected boolean isCommonNameReference = false;
41

    
42
	public AbstractReferencedEntityElement(CdmFormFactory formFactory,
43
			AbstractFormSection section, T entity,
44
			SelectionListener removeListener, int style, boolean isCommonNameReference) {
45
		super(formFactory, section, entity, removeListener, null, style);
46
		// make this element selectable
47
		if(formFactory.getSelectionProvider() != null){
48
			selectionArbitrator = formFactory.createSelectionArbitrator(this);
49
		}
50
		this.isCommonNameReference = isCommonNameReference;
51
	}
52

    
53
	   public AbstractReferencedEntityElement(CdmFormFactory formFactory,
54
	            AbstractFormSection section, T entity,
55
	            SelectionListener removeListener, int style) {
56
	        super(formFactory, section, entity, removeListener, null, style);
57
	        // make this element selectable
58
	        if(formFactory.getSelectionProvider() != null){
59
	            selectionArbitrator = formFactory.createSelectionArbitrator(this);
60
	        }
61

    
62
	    }
63

    
64

    
65
	/** {@inheritDoc} */
66
	@Override
67
	public void createControls(ICdmFormElement formElement, int style) {
68
	    if (isCommonNameReference && PreferencesUtil.getFilterCommonNameReferences()){
69
	        selection_reference = formFactory
70
                    .createCommonNameReferenceSelectionElement(formElement, "Reference",
71
                            null, EntitySelectionElement.ALL, style);
72
	    }else{
73
	        selection_reference = formFactory
74
	                .createSelectionElement(Reference.class,//getConversationHolder(),
75
	                         formElement, "Reference",
76
	                        null, EntitySelectionElement.ALL, style);
77
	    }
78

    
79
		text_referenceDetail = formFactory.createTextWithLabelElement(
80
				formElement, "Reference Detail", null, SWT.NULL);
81
	}
82

    
83
	@Override
84
	public void setEntity(T entity) {
85
		this.entity = entity;
86

    
87
		selection_reference.setEntity(entity.getCitation());
88
		text_referenceDetail.setText(entity.getCitationMicroReference());
89
	}
90

    
91
	@Override
92
    public SelectionArbitrator getSelectionArbitrator() {
93
		return selectionArbitrator;
94
	}
95

    
96
}
(2-2/19)