Project

General

Profile

Download (5.25 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.apache.commons.lang3.StringUtils;
12
import org.eclipse.jface.util.IPropertyChangeListener;
13
import org.eclipse.ui.forms.widgets.TableWrapData;
14

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

    
31
/**
32
 * @author k.luther
33
 * @since Jul 1, 2020
34
 */
35
public class OriginalSourceElement extends AbstractCdmDetailElement<OriginalSourceBase> implements IPropertyChangeListener{
36

    
37
    protected EntitySelectionElement<Reference> selection_Ref;
38
    protected TextWithLabelElement microReference;
39
    protected OriginalSourceAdvancedSection advancedSection;
40
    protected String label = "Source";
41
    protected CdmBase cdmEntity;
42
    protected ExternalLinksSection externalLinks;
43

    
44
    public OriginalSourceElement(CdmFormFactory formFactory, ICdmFormElement formElement, CdmBase cdmEntity, String label) {
45
        super(formFactory, formElement);
46
        this.cdmEntity = cdmEntity;
47
        this.label = label;
48

    
49
    }
50

    
51
    @Override
52
    protected void createControls(ICdmFormElement formElement, OriginalSourceBase entity,  int style) {
53

    
54
        selection_Ref = formFactory.createSelectionElement(Reference.class,
55
                      formElement, label, null,
56
                      EntitySelectionElement.ALL, style, 100);
57

    
58
        if (entity != null){
59
            selection_Ref.setEntity(entity.getCitation());
60
        }
61
        selection_Ref.setBackground(this.getPersistentBackground());
62
        microReference = formFactory.createTextWithLabelElement(formElement, "Details", entity != null? entity.getCitationMicroReference(): "", style);
63
        microReference.setIndent(10);
64
        for (ICdmFormElement element: selection_Ref.getElements()){
65
            element.setBackground(getPersistentBackground());
66
        }
67
        externalLinks = formFactory.createExternalLinksSection(getConversationHolder(), formElement, "Link(s)", StoreUtil.getSectionStyle(ExternalLinksSection.class, DescriptionElementSource.class.getCanonicalName()));
68
        externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 3));
69
        externalLinks.setEntity(entity);
70
        externalLinks.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
71
        externalLinks.setEmptySectionString("No links yet.");
72

    
73
        addControl(externalLinks);
74
        addElement(externalLinks);
75
        advancedSection = formFactory.createOriginalSourceAdvancedSection(getConversationHolder(), formElement, null, StoreUtil.getSectionStyle(OriginalSourceAdvancedSection.class, INomenclaturalReference.class.getCanonicalName()));
76
        TableWrapData layoutData = LayoutConstants.FILL_HORIZONTALLY(2, 1);
77
        advancedSection.setLayoutData(layoutData);
78
        advancedSection.setFont(AbstractUtility.getFont(Resources.COLOR_FONT_DEFAULT));
79
        addControl(advancedSection);
80
        addElement(advancedSection);
81
        advancedSection.setBackground(this.getPersistentBackground());
82
        advancedSection.setEntity(entity);
83
        if (entity == null){
84
            advancedSection.setExpanded(false);
85
        }else if (StringUtils.isNotBlank(entity.getIdInSource()) || StringUtils.isNotBlank(entity.getIdNamespace()) || StringUtils.isNotBlank(entity.getOriginalNameString()) || (entity.getLinks() != null && !entity.getLinks().isEmpty())  || (entity instanceof DescriptionElementSource && ((DescriptionElementSource)entity).getNameUsedInSource() != null)){
86
            advancedSection.setExpanded(true);
87
        }else{
88
            advancedSection.setExpanded(false);
89
        }
90
    }
91

    
92
    @Override
93
    public void handleEvent(Object eventSource) {
94
        if (eventSource.equals(selection_Ref)){
95
            getEntity().setCitation(selection_Ref.getEntity());
96
        }else if (eventSource.equals(microReference)){
97
            getEntity().setCitationMicroReference(microReference.getText());
98
        }
99
    }
100

    
101
    public void setCdmEntity(CdmBase cdmEntity) {
102
        this.cdmEntity = cdmEntity;
103

    
104
    }
105

    
106
    public EntitySelectionElement<Reference> getReferenceSelectionElement(){
107
        return selection_Ref;
108
    }
109

    
110
    public void setIndent(int indent){
111
        selection_Ref.setIndent(indent);
112
        microReference.setIndent(indent+10);
113
        externalLinks.setIndent(indent+10);
114
        advancedSection.setIndent(indent+10);
115
    }
116

    
117
}
(7-7/12)