Project

General

Profile

Download (5.16 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2020 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.reference;
10

    
11
import org.eclipse.swt.widgets.Label;
12
import org.eclipse.ui.forms.widgets.TableWrapData;
13

    
14
import eu.etaxonomy.cdm.hibernate.HibernateProxyHelper;
15
import eu.etaxonomy.cdm.model.common.CdmBase;
16
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
17
import eu.etaxonomy.cdm.model.name.NomenclaturalSource;
18
import eu.etaxonomy.cdm.model.name.TaxonName;
19
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
20
import eu.etaxonomy.cdm.model.reference.Reference;
21
import eu.etaxonomy.taxeditor.model.AbstractUtility;
22
import eu.etaxonomy.taxeditor.preference.Resources;
23
import eu.etaxonomy.taxeditor.store.StoreUtil;
24
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
25
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
26
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
27
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection;
28
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
29
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElementWithAbbreviatedTitle;
30

    
31
/**
32
 * @author k.luther
33
 * @since Nov 11, 2020
34
 */
35
public class NomenclaturalSourceElement extends OriginalSourceElement<NomenclaturalSource> {
36

    
37
    private EntitySelectionElementWithAbbreviatedTitle<Reference> selection_NomRef;
38
    protected String label = "Source";
39
    protected CdmBase cdmEntity;
40

    
41
    protected EntitySelectionElement<TaxonName> select_nameUsedInSource;
42
    protected ExternalLinksSection externalLinks;
43

    
44

    
45
    /**
46
     * @param formFactory
47
     * @param formElement
48
     * @param cdmEntity
49
     * @param label
50
     */
51

    
52
    public NomenclaturalSourceElement(CdmFormFactory formFactory, ICdmFormElement formElement, CdmBase cdmEntity,
53
            String label) {
54
        super(formFactory, formElement, cdmEntity, label);
55

    
56
    }
57

    
58
    @Override
59
    protected void createControls(ICdmFormElement formElement, NomenclaturalSource entity,  int style) {
60

    
61
        entity = HibernateProxyHelper.deproxy(entity);
62

    
63
        selection_NomRef = formFactory.createSelectionElementWithAbbreviatedTitle(Reference.class,
64
                getConversationHolder(), formElement, "Reference",
65
                null,
66
                EntitySelectionElement.ALL, style);
67

    
68
        if (entity != null){
69
            selection_NomRef.setEntity(entity.getCitation());
70
        }
71
        selection_NomRef.setBackground(this.getPersistentBackground());
72
        for (ICdmFormElement element: selection_NomRef.getElements()){
73
            element.setBackground(getPersistentBackground());
74
        }
75

    
76
        microReference = formFactory.createTextWithLabelElement(formElement, "Details", entity != null? entity.getCitationMicroReference(): "", style);
77

    
78
        Label sep = formFactory.createLabel(formElement.getLayoutComposite(), "");
79
        sep.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
80

    
81
        select_nameUsedInSource = formFactory.createSelectionElement(TaxonName.class, formElement, "Original Spelling", entity != null? entity.getNameUsedInSource(): null, EntitySelectionElement.ALL, style);
82

    
83
        externalLinks = formFactory.createExternalLinksSection(getConversationHolder(), formElement, "Protologue/Original Publication", StoreUtil.getSectionStyle(ExternalLinksSection.class, DescriptionElementSource.class.getCanonicalName()));
84
        externalLinks.setEmptySectionString("No protologue yet.");
85
        externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 3));
86
        externalLinks.setEntity(entity);
87
        externalLinks.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
88

    
89

    
90
        addControl(externalLinks);
91
        addElement(externalLinks);
92

    
93
        advancedSection = formFactory.createOriginalSourceAdvancedSection(getConversationHolder(), formElement, null, StoreUtil.getSectionStyle(OriginalSourceAdvancedSection.class, INomenclaturalReference.class.getCanonicalName()));
94
        TableWrapData layoutData = LayoutConstants.FILL_HORIZONTALLY(2, 1);
95

    
96
        advancedSection.setLayoutData(layoutData);
97
        advancedSection.setBackground(this.getPersistentBackground());
98
        advancedSection.setEntity(entity);
99
        advancedSection.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
100
        addControl(advancedSection);
101
        addElement(advancedSection);
102
        this.getLayoutComposite().layout();
103

    
104
    }
105

    
106
    @Override
107
    public EntitySelectionElement<Reference> getReferenceSelectionElement(){
108

    
109
        return selection_NomRef;
110

    
111

    
112
    }
113

    
114
    @Override
115
    public void handleEvent(Object eventSource) {
116
        if (eventSource.equals(selection_NomRef)){
117
            getEntity().setCitation(selection_NomRef.getEntity());
118
        }
119
        if (eventSource.equals(microReference)){
120
            getEntity().setCitationMicroReference(microReference.getText());
121
        }
122
        if (eventSource.equals(select_nameUsedInSource)){
123
            (getEntity()).setNameUsedInSource(select_nameUsedInSource.getEntity());
124
        }
125
        super.handleEvent(eventSource);
126
    }
127

    
128

    
129

    
130
}
(5-5/12)