Project

General

Profile

Download (4.95 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
    protected String label = "Source";
37
    protected CdmBase cdmEntity;
38

    
39
    protected EntitySelectionElement<TaxonName> select_nameUsedInSource;
40
    protected ExternalLinksSection externalLinks;
41

    
42
    public NomenclaturalSourceElement(CdmFormFactory formFactory, ICdmFormElement formElement, CdmBase cdmEntity,
43
            String label) {
44
        super(formFactory, formElement, cdmEntity, label);
45
    }
46

    
47
    @Override
48
    protected void createControls(ICdmFormElement formElement, NomenclaturalSource entity,  int style) {
49

    
50
        entity = HibernateProxyHelper.deproxy(entity);
51

    
52
        selection_NomRef = formFactory.createSelectionElementWithAbbreviatedTitle(Reference.class,
53
                getConversationHolder(), formElement, "Reference",
54
                null,
55
                EntitySelectionElement.ALL, style);
56

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

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

    
67
        Label sep = formFactory.createLabel(formElement.getLayoutComposite(), "");
68
        sep.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 1));
69

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

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

    
78

    
79
        addControl(externalLinks);
80
        addElement(externalLinks);
81

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

    
94
    @Override
95
    public EntitySelectionElement<Reference> getReferenceSelectionElement(){
96
        return selection_NomRef;
97
    }
98

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