Merge branch 'release/5.18.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / reference / AdvancedSourceElement.java
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.ui.element.CdmFormFactory;
21 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
22 import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
23 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
24 import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
25
26 /**
27 * @author k.luther
28 * @since Jul 2, 2020
29 */
30 public class AdvancedSourceElement extends AbstractCdmDetailElement<OriginalSourceBase> {
31
32 protected TextWithLabelElement text_idInSource;
33 protected TextWithLabelElement text_idNamespace;
34 protected TextWithLabelElement text_originaleNameString;
35 protected TextWithLabelElement text_cdmsource;
36 protected EntitySelectionElement<TaxonName> select_nameUsedInSource;
37
38 // protected ExternalLinksSection externalLinks;
39
40 public AdvancedSourceElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
41 super(formFactory, formElement);
42 }
43
44 @Override
45 protected void createControls(ICdmFormElement formElement, OriginalSourceBase entity, int style) {
46 Display display = Display.getCurrent();
47 Color background = display.getSystemColor(SWT.COLOR_WIDGET_BACKGROUND);
48
49
50 if (entity instanceof DescriptionElementSource){
51 select_nameUsedInSource = formFactory.createSelectionElement(TaxonName.class, formElement, "Name in Source", entity != null? ((DescriptionElementSource)entity).getNameUsedInSource(): null, EntitySelectionElement.DELETABLE, style);
52 select_nameUsedInSource.setBackground(background);
53 }
54 text_originaleNameString = formFactory.createTextWithLabelElement(
55 formElement, "Original Information", entity != null?entity.getOriginalNameString():null, SWT.NULL);
56
57 text_originaleNameString.setBackground(background);
58
59 if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowNamespaceInSource.getKey())){
60 text_idNamespace = formFactory.createTextWithLabelElement(formElement, "ID Namespace", entity != null?entity.getIdNamespace():null, style);
61 text_idNamespace.setBackground(background);
62 }
63 if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSource.getKey())){
64 text_idInSource = formFactory.createTextWithLabelElement(formElement, "ID in Source", entity != null?entity.getIdInSource():null, style);
65 text_idInSource.setBackground(background);
66
67 }
68
69 }
70
71 @Override
72 public void setEntity(OriginalSourceBase entity) {
73 super.setEntity(entity);
74 }
75
76 @Override
77 public void handleEvent(Object eventSource) {
78 if (eventSource.equals(text_idInSource)){
79 getEntity().setIdInSource(text_idInSource.getText());
80 }else if (eventSource.equals(text_idNamespace)){
81 getEntity().setIdNamespace(text_idNamespace.getText());
82 }else if (eventSource.equals(text_originaleNameString)){
83 getEntity().setOriginalNameString(text_originaleNameString.getText());
84 }else if (eventSource.equals(select_nameUsedInSource)){
85 ((DescriptionElementSource)getEntity()).setNameUsedInSource(select_nameUsedInSource.getEntity());
86 }
87 }
88 }