Project

General

Profile

Download (3.93 KB) Statistics
| Branch: | Tag: | Revision:
1
// $Id$
2
/**
3
* Copyright (C) 2014 EDIT
4
* European Distributed Institute of Taxonomy
5
* http://www.e-taxonomy.eu
6
*
7
* The contents of this file are subject to the Mozilla Public License Version 1.1
8
* See LICENSE.TXT at the top of this package for the full license terms.
9
*/
10
package eu.etaxonomy.taxeditor.ui.section.occurrence.dna;
11

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

    
15
import eu.etaxonomy.cdm.model.molecular.Sequence;
16
import eu.etaxonomy.cdm.model.reference.Reference;
17
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
18
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
19
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
20
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
21
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
22
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
23

    
24
/**
25
 * @author pplitzner
26
 * @date 07.01.2014
27
 *
28
 */
29
public class SequenceReferenceCollectionDetailElement extends AbstractEntityCollectionElement<Reference<?>>{
30

    
31
    protected EntitySelectionElement<Reference> selection_reference;
32
    protected TextWithLabelElement text_referenceDetail;
33

    
34
    /**
35
     * <p>
36
     * Constructor for AbstractReferencedEntityElement.
37
     * </p>
38
     *
39
     * @param formFactory
40
     *            a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory}
41
     *            object.
42
     * @param section
43
     *            a {@link eu.etaxonomy.taxeditor.ui.element.AbstractFormSection}
44
     *            object.
45
     * @param entity
46
     *            a T object.
47
     * @param removeListener
48
     *            a {@link org.eclipse.swt.events.SelectionListener} object.
49
     * @param style
50
     *            a int.
51
     * @param <T>
52
     *            a T object.
53
     */
54
    public SequenceReferenceCollectionDetailElement(CdmFormFactory formFactory,
55
            AbstractFormSection<?> section, Reference<?> entity,
56
            SelectionListener removeListener, int style) {
57
        super(formFactory, section, entity, removeListener, null, style);
58
    }
59

    
60
    /*
61
     * (non-Javadoc)
62
     *
63
     * @see
64
     * eu.etaxonomy.taxeditor.forms.section.AbstractEntityCollectionElement#
65
     * createControls(eu.etaxonomy.taxeditor.forms.ICdmFormElement, int)
66
     */
67
    /** {@inheritDoc} */
68
    @Override
69
    public void createControls(ICdmFormElement formElement, int style) {
70
        selection_reference = formFactory
71
                .createSelectionElement(Reference.class,
72
                        getConversationHolder(), formElement, "Reference",
73
                        null, EntitySelectionElement.SELECTABLE|EntitySelectionElement.EDITABLE, style);
74
        text_referenceDetail = formFactory.createTextWithLabelElement(
75
                formElement, "Reference Detail", null, SWT.NULL);
76
    }
77

    
78
    /**
79
     * <p>
80
     * setEntity
81
     * </p>
82
     *
83
     * @param entity
84
     *            a T object.
85
     */
86
    @Override
87
    public void setEntity(Reference<?> entity) {
88
        this.entity = entity;
89
        selection_reference.setEntity(entity);
90
        text_referenceDetail.setText(entity.getReferenceAbstract());
91
    }
92

    
93
    /* (non-Javadoc)
94
     * @see eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement#handleEvent(java.lang.Object)
95
     */
96
    @Override
97
    public void handleEvent(Object eventSource) {
98
        if(eventSource==selection_reference){
99
            if(getParentElement() instanceof SequenceReferenceCollectionDetailSection){
100
                Sequence sequence = ((SequenceReferenceCollectionDetailSection) getParentElement()).getEntity();
101
                sequence.removeCitation(entity);
102
                Reference<?> newCitation = selection_reference.getSelection();
103
                sequence.addCitation(newCitation);
104
                entity = newCitation;
105

    
106
                text_referenceDetail.setEnabled(true);
107
            }
108
        } else if(eventSource==text_referenceDetail){
109
            entity.setReferenceAbstract(text_referenceDetail.getText());
110
        }
111
    }
112

    
113
}
(24-24/30)