2 * Copyright (C) 2020 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
9 package eu
.etaxonomy
.taxeditor
.ui
.section
.reference
;
11 import java
.awt
.Component
;
13 import org
.apache
.commons
.lang3
.StringUtils
;
14 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
15 import org
.eclipse
.swt
.widgets
.Composite
;
16 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
17 import org
.hibernate
.EntityMode
;
19 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
20 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
21 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
22 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
23 import eu
.etaxonomy
.cdm
.model
.reference
.INomenclaturalReference
;
24 import eu
.etaxonomy
.cdm
.model
.reference
.NamedSourceBase
;
25 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceBase
;
26 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
27 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
28 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
29 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
30 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
32 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
34 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
35 import eu
.etaxonomy
.taxeditor
.ui
.element
.TimePeriodElement
;
36 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
37 import eu
.etaxonomy
.taxeditor
.ui
.section
.common
.ExternalLinksSection
;
38 import eu
.etaxonomy
.taxeditor
.ui
.section
.taxon
.TaxonBaseDetailSection
;
39 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
45 public class OriginalSourceElement
<T
extends OriginalSourceBase
>
46 extends AbstractCdmDetailElement
<T
>
47 implements IPropertyChangeListener
{
49 protected ICdmFormElement composite
;
50 protected EntitySelectionElement
<Reference
> selection_Ref
;
51 protected TextWithLabelElement microReference
;
52 protected TimePeriodElement accessed
;
53 protected OriginalSourceAdvancedSection advancedSection
;
54 protected String label
= "Source";
55 protected CdmBase cdmEntity
;
56 protected ExternalLinksSection externalLinks
;
57 protected ReferenceType refType
;
59 public OriginalSourceElement(CdmFormFactory formFactory
, ICdmFormElement formElement
, CdmBase cdmEntity
, String label
) {
60 super(formFactory
, formElement
);
61 this.cdmEntity
= cdmEntity
;
66 protected void createControls(ICdmFormElement formElement
, T entity
, int style
) {
68 selection_Ref
= formFactory
.createSelectionElement(Reference
.class,
69 formElement
, label
, null,
70 EntitySelectionElement
.ALL
, style
, 100);
73 selection_Ref
.setEntity(entity
.getCitation());
74 if (entity
.getCitation() != null) {
75 refType
= entity
.getCitation().getType();
79 selection_Ref
.setBackground(this.getPersistentBackground());
80 microReference
= formFactory
.createTextWithLabelElement(formElement
, "Details", entity
!= null? entity
.getCitationMicroReference(): "", style
);
81 microReference
.setIndent(10);
82 for (ICdmFormElement element
: selection_Ref
.getElements()){
83 element
.setBackground(getPersistentBackground());
86 //TODO preliminary #10057
87 if (entity
!= null && entity
.getCitation() != null && entity
.getCitation().isDynamic()){
88 TimePeriod acc
=entity
.getAccessed(); // (entity != null? entity.getAccessed(): null);
89 accessed
= formFactory
.createTimePeriodElement(formElement
, "Accessed", acc
, style
);
92 externalLinks
= formFactory
.createExternalLinksSection(formElement
, "Link(s)", StoreUtil
.getSectionStyle(ExternalLinksSection
.class, DescriptionElementSource
.class.getCanonicalName()));
93 externalLinks
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 3));
94 externalLinks
.setEntity(HibernateProxyHelper
.deproxy(entity
));
95 externalLinks
.setFont(AbstractUtility
.getFont(Resources
.COLOR_FONT_DEFAULT
));
96 externalLinks
.setEmptySectionString("No links yet.");
98 addControl(externalLinks
);
99 addElement(externalLinks
);
100 advancedSection
= formFactory
.createOriginalSourceAdvancedSection(formElement
, null, StoreUtil
.getSectionStyle(OriginalSourceAdvancedSection
.class, INomenclaturalReference
.class.getCanonicalName()));
101 TableWrapData layoutData
= LayoutConstants
.FILL_HORIZONTALLY(2, 1);
102 advancedSection
.setLayoutData(layoutData
);
103 advancedSection
.setFont(AbstractUtility
.getFont(Resources
.COLOR_FONT_DEFAULT
));
104 addControl(advancedSection
);
105 addElement(advancedSection
);
106 advancedSection
.setBackground(this.getPersistentBackground());
107 advancedSection
.setEntity(entity
);
109 advancedSection
.setExpanded(false);
110 }else if (StringUtils
.isNotBlank(entity
.getIdInSource()) || StringUtils
.isNotBlank(entity
.getIdNamespace()) || StringUtils
.isNotBlank(entity
.getOriginalInfo()) || (entity
.getLinks() != null && !entity
.getLinks().isEmpty()) || (entity
instanceof DescriptionElementSource
&& ((NamedSourceBase
)entity
).getNameUsedInSource() != null)){
111 advancedSection
.setExpanded(true);
113 advancedSection
.setExpanded(false);
118 public void handleEvent(Object eventSource
) {
119 if (eventSource
.equals(selection_Ref
)){
121 getEntity().setCitation(selection_Ref
.getEntity());
122 ReferenceType newRefType
= getEntity().getCitation().getType();
123 if (refType
!= null && refType
.isDynamic() ^
getEntity().getCitation().getType().isDynamic()) {
125 // this.getParentElement().refresh();
127 refType
= newRefType
;
128 }else if (eventSource
.equals(microReference
)){
129 getEntity().setCitationMicroReference(microReference
.getText());
130 }else if(eventSource
== accessed
){
131 getEntity().setAccessed(accessed
.getTimePeriod());
135 public void setCdmEntity(CdmBase cdmEntity
) {
136 this.cdmEntity
= cdmEntity
;
139 public EntitySelectionElement
<Reference
> getReferenceSelectionElement(){
140 return selection_Ref
;
143 public void setIndent(int indent
){
144 selection_Ref
.setIndent(indent
);
145 microReference
.setIndent(indent
+10);
146 externalLinks
.setIndent(indent
+10);
147 advancedSection
.setIndent(indent
+10);
151 public void refresh() {
153 this.getParentElement().refresh();
157 public void fillFields() {
158 if (getEntity() != null) {
159 selection_Ref
.setEntity(getEntity().getCitation()!= null?
getEntity().getCitation(): null);
160 microReference
.setText(getEntity().getCitationMicroReference());
161 if (accessed
!= null) {
162 accessed
.setEntity(getEntity().getAccessed()!= null?
getEntity().getAccessed(): null);
164 if (advancedSection
!= null) {
165 advancedSection
.setEntity(getEntity());
168 externalLinks
.setEntity(getEntity());