Project

General

Profile

Download (4.76 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

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

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

    
35
    private EntitySelectionElementWithAbbreviatedTitle<Reference> selection_NomRef;
36
    private EntitySelectionElement<TaxonName> select_nameUsedInSource;
37

    
38

    
39
    public NomenclaturalSourceElement(CdmFormFactory formFactory, ICdmFormElement formElement, CdmBase cdmEntity,
40
            String label) {
41
        super(formFactory, formElement, cdmEntity, label);
42
    }
43

    
44
    @Override
45
    protected void createControls(ICdmFormElement formElement, NomenclaturalSource entity,  int style) {
46

    
47
        entity = HibernateProxyHelper.deproxy(entity);
48

    
49
        selection_NomRef = formFactory.createSelectionElementWithAbbreviatedTitle(Reference.class,
50
                formElement, "Reference",
51
                null,
52
                EntitySelectionElement.ALL, style);
53

    
54
        if (entity != null){
55
            selection_NomRef.setEntity(entity.getCitation());
56
        }
57
        selection_NomRef.setBackground(this.getPersistentBackground());
58
        for (ICdmFormElement element: selection_NomRef.getElements()){
59
            element.setBackground(getPersistentBackground());
60
        }
61

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

    
64
        Label sep = formFactory.createLabel(formElement.getLayoutComposite(), "");
65
        sep.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
66

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

    
69
        externalLinks = formFactory.createExternalLinksSection(formElement, "Protologue/Original Publication", false, StoreUtil.getSectionStyle(ExternalLinksSection.class, DescriptionElementSource.class.getCanonicalName()));
70
        externalLinks.setEmptySectionString("No protologue yet.");
71
        externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 3));
72
        externalLinks.setEntity(entity);
73
        externalLinks.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
74

    
75

    
76
        addControl(externalLinks);
77
        addElement(externalLinks);
78

    
79
//        advancedSection = formFactory.createOriginalSourceAdvancedSection(formElement, null, StoreUtil.getSectionStyle(OriginalSourceAdvancedSection.class, INomenclaturalReference.class.getCanonicalName()));
80
//        TableWrapData layoutData = LayoutConstants.FILL_HORIZONTALLY(2, 1);
81
//
82
//        advancedSection.setLayoutData(layoutData);
83
//        advancedSection.setBackground(this.getPersistentBackground());
84
//        advancedSection.setEntity(entity);
85
//        advancedSection.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
86
//        addControl(advancedSection);
87
//        addElement(advancedSection);
88
        this.getLayoutComposite().layout();
89
    }
90

    
91
    @Override
92
    public EntitySelectionElement<Reference> getReferenceSelectionElement(){
93
        return selection_NomRef;
94
    }
95

    
96
    @Override
97
    public void handleEvent(Object eventSource) {
98
        if (eventSource.equals(selection_NomRef)){
99
            getEntity().setCitation(selection_NomRef.getEntity());
100
        }
101
        if (eventSource.equals(microReference)){
102
            getEntity().setCitationMicroReference(microReference.getText());
103
        }
104
        if (eventSource.equals(select_nameUsedInSource)){
105
            (getEntity()).setNameUsedInSource(select_nameUsedInSource.getEntity());
106
        }
107
        super.handleEvent(eventSource);
108
    }
109
}
(5-5/15)