Project

General

Profile

Download (4.51 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.jface.util.IPropertyChangeListener;
12
import org.eclipse.ui.forms.widgets.TableWrapData;
13

    
14
import eu.etaxonomy.cdm.model.common.CdmBase;
15
import eu.etaxonomy.cdm.model.common.ReferencedEntityBase;
16
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
17
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
18
import eu.etaxonomy.cdm.model.reference.Reference;
19
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
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
        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

    
67

    
68
        advancedSection.setLayoutData(layoutData);
69

    
70
        addControl(advancedSection);
71
        addElement(advancedSection);
72
        advancedSection.setBackground(this.getPersistentBackground());
73
        advancedSection.setEntity(entity);
74

    
75
    }
76

    
77
    @Override
78
    public void handleEvent(Object eventSource) {
79
        if (eventSource.equals(selection_Ref)){
80

    
81
            if (getEntity() == null){
82
                Reference ref = selection_Ref.getEntity();
83
                DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(null, null);
84
                setEntity(source);
85
                selection_Ref.setEntity(ref);
86
                if (cdmEntity != null && cdmEntity instanceof TaxonNode){
87
                    ((TaxonNode)cdmEntity).setSource(source);
88
                }
89
            }
90
            //TODO: why is this null????ß
91
            getEntity().setCitation(selection_Ref.getEntity());
92

    
93
        }else if (eventSource.equals(microReference)){
94

    
95
            if (getEntity() == null){
96
                DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(null, null);
97
                setEntity(source);
98
                if (cdmEntity != null && cdmEntity instanceof TaxonNode){
99
                    ((TaxonNode)cdmEntity).setSource(source);
100
                }
101
            }
102
            //TODO: why is this null????ß
103
            getEntity().setCitationMicroReference(microReference.getText());
104

    
105
        }
106

    
107
    }
108

    
109
    /**
110
     * @param cdmEntity2
111
     */
112
    public void setCdmEntity(CdmBase cdmEntity) {
113
        this.cdmEntity = cdmEntity;
114

    
115
    }
116

    
117

    
118

    
119
}
(5-5/10)