Project

General

Profile

Download (5.31 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.NamedSourceBase;
19
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
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.element.TextWithLabelElement;
28
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
29
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection;
30
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
31

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

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

    
47
    public OriginalSourceElement(CdmFormFactory formFactory, ICdmFormElement formElement, CdmBase cdmEntity, String label) {
48
        super(formFactory, formElement);
49
        this.cdmEntity = cdmEntity;
50
        this.label = label;
51

    
52
    }
53

    
54
    @Override
55
    protected void createControls(ICdmFormElement formElement, T entity,  int style) {
56

    
57
        selection_Ref = formFactory.createSelectionElement(Reference.class,
58
                      formElement, label, null,
59
                      EntitySelectionElement.ALL, style, 100);
60

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

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

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

    
104
    public void setCdmEntity(CdmBase cdmEntity) {
105
        this.cdmEntity = cdmEntity;
106

    
107
    }
108

    
109
    public EntitySelectionElement<Reference> getReferenceSelectionElement(){
110
        return selection_Ref;
111
    }
112

    
113
    public void setIndent(int indent){
114
        selection_Ref.setIndent(indent);
115
        microReference.setIndent(indent+10);
116
        externalLinks.setIndent(indent+10);
117
        advancedSection.setIndent(indent+10);
118
    }
119

    
120
}
(7-7/12)