Merge branch 'release/5.18.0'
[taxeditor.git] / eu.etaxonomy.taxeditor.store / src / main / java / eu / etaxonomy / taxeditor / ui / section / supplemental / AbstractSingleSourceElement.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.supplemental;
10
11 import eu.etaxonomy.cdm.model.common.SingleSourcedEntityBase;
12 import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
13 import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
14 import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
15 import eu.etaxonomy.taxeditor.ui.element.ISelectableElement;
16 import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
17 import eu.etaxonomy.taxeditor.ui.section.reference.OriginalSourceElement;
18
19 /**
20 * @author k.luther
21 * @since Aug 18, 2020
22 */
23 public abstract class AbstractSingleSourceElement <T extends SingleSourcedEntityBase>
24 extends AbstractCdmDetailElement<T> implements ISelectableElement{
25
26 protected OriginalSourceElement singleSourceSection;
27 private String label;
28
29 /**
30 * @param formFactory
31 * @param section
32 * @param entity
33 * @param removeListener
34 * @param backgroundColor
35 * @param style
36 */
37 public AbstractSingleSourceElement(CdmFormFactory formFactory, ICdmFormElement formElement) {
38 super(formFactory, formElement);
39
40 }
41
42 public String getLabel() {
43 return label;
44 }
45
46 public void setSourceLabel(String label) {
47 if (singleSourceSection != null){
48 singleSourceSection.getReferenceSelectionElement().setLabel(label);
49 }
50 this.label = label;
51 }
52
53 @Override
54 public void createControls(ICdmFormElement formElement, T entity, int style) {
55 singleSourceSection = formFactory.createOriginalSourceElement(formElement, entity, label);
56 if (entity.getSource() == null){
57 DescriptionElementSource source = DescriptionElementSource.NewPrimarySourceInstance(null, null);
58 entity.setSource(source);
59 singleSourceSection.setEntity(source);
60 }else{
61 singleSourceSection.setEntity(entity.getSource());
62
63 }
64 }
65
66 public void setIndent(int indent){
67 singleSourceSection.setIndent(indent);
68 }
69
70
71 }