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.lang.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.common.ReferencedEntityBase;
17
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
18
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
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<ReferencedEntityBase> implements IPropertyChangeListener{
34

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

    
39
    private CdmBase cdmEntity;
40

    
41

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

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

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

    
55
        if (entity != null){
56
            selection_Ref.setEntity(entity.getCitation());
57
        }
58
        selection_Ref.setBackground(this.getPersistentBackground());
59
        microReference = formFactory.createTextWithLabelElement(formElement, "Details", entity != null? entity.getCitationMicroReference(): "", style);
60

    
61

    
62
        for (ICdmFormElement element: selection_Ref.getElements()){
63
            element.setBackground(getPersistentBackground());
64
        }
65

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

    
70
        advancedSection.setLayoutData(layoutData);
71

    
72
        addControl(advancedSection);
73
        addElement(advancedSection);
74
        advancedSection.setBackground(this.getPersistentBackground());
75
        advancedSection.setEntity(entity);
76
        advancedSection.setExpanded(false);
77
        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)){
78
            advancedSection.setExpanded(true);
79
        }
80

    
81
    }
82

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

    
90
        }
91

    
92
    }
93

    
94
    /**
95
     * @param cdmEntity2
96
     */
97
    public void setCdmEntity(CdmBase cdmEntity) {
98
        this.cdmEntity = cdmEntity;
99

    
100
    }
101

    
102

    
103

    
104
}
(5-5/10)