Project

General

Profile

Download (4.43 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.swt.SWT;
12
import org.eclipse.swt.graphics.Color;
13
import org.eclipse.swt.widgets.Display;
14

    
15
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
16
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
17
import eu.etaxonomy.cdm.model.name.TaxonName;
18
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
19
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
20
import eu.etaxonomy.taxeditor.store.StoreUtil;
21
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
22
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
23
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
24
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
25
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
26
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection;
27
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
28

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

    
35
    protected TextWithLabelElement text_idInSource;
36
    protected TextWithLabelElement text_idNamespace;
37
    protected TextWithLabelElement text_originaleNameString;
38
    protected TextWithLabelElement text_cdmsource;
39
    protected EntitySelectionElement<TaxonName> select_nameUsedInSource;
40

    
41
    protected ExternalLinksSection externalLinks;
42

    
43
    public AdvancedSourceElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
44
        super(formFactory, formElement);
45
    }
46

    
47
    @Override
48
    protected void createControls(ICdmFormElement formElement, DescriptionElementSource entity, int style) {
49
        Display display = Display.getCurrent();
50
        Color background = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
51

    
52

    
53
        if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSource.getKey())){
54
            text_idInSource = formFactory.createTextWithLabelElement(formElement, "ID in Source", entity != null?((OriginalSourceBase)entity).getIdInSource():null, style);
55
            text_idInSource.setBackground(background);
56

    
57
        }
58
        if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowNamespaceInSource.getKey())){
59
            text_idNamespace = formFactory.createTextWithLabelElement(formElement, "ID Namespace", entity != null?((OriginalSourceBase)entity).getIdNamespace():null, style);
60
            text_idNamespace.setBackground(background);
61
        }
62
        text_originaleNameString = formFactory.createTextWithLabelElement(
63
                formElement, "Original Information", entity != null?entity.getOriginalNameString():null, SWT.NULL);
64

    
65
        text_originaleNameString.setBackground(background);
66

    
67
        select_nameUsedInSource = formFactory.createSelectionElement(TaxonName.class, formElement, "Name in Source", entity != null? ((DescriptionElementSource)entity).getNameUsedInSource(): null, EntitySelectionElement.DELETABLE, style);
68
        select_nameUsedInSource.setBackground(background);
69

    
70
        externalLinks = formFactory.createExternalLinksSection(getConversationHolder(), formElement, StoreUtil.getSectionStyle(ExternalLinksSection.class, DescriptionElementSource.class.getCanonicalName()));
71
        externalLinks.setLayoutData(LayoutConstants.FILL_HORIZONTALLY(2, 3));
72
        externalLinks.setEntity(entity);
73
        externalLinks.setBackground(background);
74
        addControl(externalLinks);
75
        addElement(externalLinks);
76
    }
77

    
78
    @Override
79
    public void setEntity(DescriptionElementSource entity) {
80
        super.setEntity(entity);
81
        externalLinks.setEntity(entity);
82
    }
83

    
84
    @Override
85
    public void handleEvent(Object eventSource) {
86
        if (eventSource.equals(text_idInSource)){
87
             getEntity().setIdInSource(text_idInSource.getText());
88
         }else if (eventSource.equals(text_idNamespace)){
89
             getEntity().setIdNamespace(text_idNamespace.getText());
90
         }else if (eventSource.equals(text_originaleNameString)){
91
             getEntity().setOriginalNameString(text_originaleNameString.getText());
92
         }else if (eventSource.equals(select_nameUsedInSource)){
93
             getEntity().setNameUsedInSource(select_nameUsedInSource.getEntity());
94
         }
95
    }
96
}
(1-1/10)