Project

General

Profile

Download (4.19 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.l10n.Messages;
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.element.TextWithLabelElement;
26
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
27
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
28

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

    
35
    private EntitySelectionElement<Reference> selection_Ref;
36
    private TextWithLabelElement microReference;
37
    private OriginalSourceAdvancedSection advancedSection;
38

    
39
    private CdmBase cdmEntity;
40

    
41
    public OriginalSourceElement(CdmFormFactory formFactory, ICdmFormElement formElement, CdmBase cdmEntity) {
42
        super(formFactory, formElement);
43
        this.cdmEntity = cdmEntity;
44
//        selectionArbitrator = formFactory.createSelectionArbitrator(this);
45
    }
46

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

    
50
        selection_Ref = formFactory.createSelectionElement(Reference.class,
51
                      formElement, Messages.TaxonNodeWizardPage_PLACEMENT_SOURCE, null,
52
                      EntitySelectionElement.DELETABLE, style, 100);
53

    
54
        if (entity != null){
55
            selection_Ref.setEntity(entity.getCitation());
56
        }
57
        selection_Ref.setBackground(this.getPersistentBackground());
58
        microReference = formFactory.createTextWithLabelElement(formElement, "Details", entity != null? entity.getCitationMicroReference(): "", style);
59
        microReference.setIndent(10);
60
        for (ICdmFormElement element: selection_Ref.getElements()){
61
            element.setBackground(getPersistentBackground());
62
        }
63

    
64
        advancedSection = formFactory.createOriginalSourceAdvancedSection(getConversationHolder(), formElement, null, StoreUtil.getSectionStyle(OriginalSourceAdvancedSection.class, INomenclaturalReference.class.getCanonicalName()));
65
        TableWrapData layoutData = LayoutConstants.FILL_HORIZONTALLY(2, 1);
66
        layoutData.indent = 10;
67

    
68
        advancedSection.setLayoutData(layoutData);
69

    
70
        addControl(advancedSection);
71
        addElement(advancedSection);
72
        advancedSection.setBackground(this.getPersistentBackground());
73
        advancedSection.setEntity(entity);
74
        advancedSection.setExpanded(false);
75
        if (StringUtils.isNotBlank(((DescriptionElementSource)entity).getIdInSource()) || StringUtils.isNotBlank(((DescriptionElementSource)entity).getIdNamespace()) || StringUtils.isNotBlank(((DescriptionElementSource)entity).getOriginalNameString()) || (((DescriptionElementSource)entity).getLinks() != null && !((DescriptionElementSource)entity).getLinks().isEmpty())  || (((DescriptionElementSource)entity).getNameUsedInSource() != null)){
76
            advancedSection.setExpanded(true);
77
        }
78
    }
79

    
80
    @Override
81
    public void handleEvent(Object eventSource) {
82
        if (eventSource.equals(selection_Ref)){
83
            getEntity().setCitation(selection_Ref.getEntity());
84
        }else if (eventSource.equals(microReference)){
85
            getEntity().setCitationMicroReference(microReference.getText());
86
        }
87
    }
88

    
89
    public void setCdmEntity(CdmBase cdmEntity) {
90
        this.cdmEntity = cdmEntity;
91

    
92
    }
93
}
(5-5/10)