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.lang3.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.description.DescriptionElementSource;
|
17
|
import eu.etaxonomy.cdm.model.reference.INomenclaturalReference;
|
18
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
19
|
import eu.etaxonomy.taxeditor.store.StoreUtil;
|
20
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.LayoutConstants;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
24
|
import eu.etaxonomy.taxeditor.ui.section.AbstractCdmDetailElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
26
|
|
27
|
/**
|
28
|
* @author k.luther
|
29
|
* @since Jul 1, 2020
|
30
|
*/
|
31
|
public class OriginalSourceElement extends AbstractCdmDetailElement<DescriptionElementSource> implements IPropertyChangeListener{
|
32
|
|
33
|
private EntitySelectionElement<Reference> selection_Ref;
|
34
|
private TextWithLabelElement microReference;
|
35
|
private OriginalSourceAdvancedSection advancedSection;
|
36
|
private String label = "Source";
|
37
|
private CdmBase cdmEntity;
|
38
|
|
39
|
public OriginalSourceElement(CdmFormFactory formFactory, ICdmFormElement formElement, CdmBase cdmEntity, String label) {
|
40
|
super(formFactory, formElement);
|
41
|
this.cdmEntity = cdmEntity;
|
42
|
this.label = label;
|
43
|
|
44
|
}
|
45
|
|
46
|
@Override
|
47
|
protected void createControls(ICdmFormElement formElement, DescriptionElementSource entity, int style) {
|
48
|
|
49
|
selection_Ref = formFactory.createSelectionElement(Reference.class,
|
50
|
formElement, label, null,
|
51
|
EntitySelectionElement.DELETABLE, style, 100);
|
52
|
|
53
|
if (entity != null){
|
54
|
selection_Ref.setEntity(entity.getCitation());
|
55
|
}
|
56
|
selection_Ref.setBackground(this.getPersistentBackground());
|
57
|
microReference = formFactory.createTextWithLabelElement(formElement, "Details", entity != null? entity.getCitationMicroReference(): "", style);
|
58
|
microReference.setIndent(10);
|
59
|
for (ICdmFormElement element: selection_Ref.getElements()){
|
60
|
element.setBackground(getPersistentBackground());
|
61
|
}
|
62
|
|
63
|
advancedSection = formFactory.createOriginalSourceAdvancedSection(getConversationHolder(), formElement, null, StoreUtil.getSectionStyle(OriginalSourceAdvancedSection.class, INomenclaturalReference.class.getCanonicalName()));
|
64
|
TableWrapData layoutData = LayoutConstants.FILL_HORIZONTALLY(2, 1);
|
65
|
layoutData.indent = 10;
|
66
|
|
67
|
advancedSection.setLayoutData(layoutData);
|
68
|
|
69
|
addControl(advancedSection);
|
70
|
addElement(advancedSection);
|
71
|
advancedSection.setBackground(this.getPersistentBackground());
|
72
|
advancedSection.setEntity(entity);
|
73
|
|
74
|
if (StringUtils.isNotBlank(entity.getIdInSource()) || StringUtils.isNotBlank(entity.getIdNamespace()) || StringUtils.isNotBlank(entity.getOriginalNameString()) || (entity.getLinks() != null && !entity.getLinks().isEmpty()) || (entity.getNameUsedInSource() != null)){
|
75
|
advancedSection.setExpanded(true);
|
76
|
}else{
|
77
|
advancedSection.setExpanded(false);
|
78
|
}
|
79
|
}
|
80
|
|
81
|
@Override
|
82
|
public void handleEvent(Object eventSource) {
|
83
|
if (eventSource.equals(selection_Ref)){
|
84
|
getEntity().setCitation(selection_Ref.getEntity());
|
85
|
}else if (eventSource.equals(microReference)){
|
86
|
getEntity().setCitationMicroReference(microReference.getText());
|
87
|
}
|
88
|
}
|
89
|
|
90
|
public void setCdmEntity(CdmBase cdmEntity) {
|
91
|
this.cdmEntity = cdmEntity;
|
92
|
|
93
|
}
|
94
|
|
95
|
public EntitySelectionElement<Reference> getReferenceSelectionElement(){
|
96
|
return selection_Ref;
|
97
|
}
|
98
|
|
99
|
}
|