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 org
.apache
.commons
.lang3
.StringUtils
;
12 import org
.eclipse
.jface
.util
.IPropertyChangeListener
;
13 import org
.eclipse
.ui
.forms
.widgets
.TableWrapData
;
15 import eu
.etaxonomy
.cdm
.hibernate
.HibernateProxyHelper
;
16 import eu
.etaxonomy
.cdm
.model
.common
.CdmBase
;
17 import eu
.etaxonomy
.cdm
.model
.common
.TimePeriod
;
18 import eu
.etaxonomy
.cdm
.model
.description
.DescriptionElementSource
;
19 import eu
.etaxonomy
.cdm
.model
.reference
.INomenclaturalReference
;
20 import eu
.etaxonomy
.cdm
.model
.reference
.NamedSourceBase
;
21 import eu
.etaxonomy
.cdm
.model
.reference
.OriginalSourceBase
;
22 import eu
.etaxonomy
.cdm
.model
.reference
.Reference
;
23 import eu
.etaxonomy
.cdm
.model
.reference
.ReferenceType
;
24 import eu
.etaxonomy
.taxeditor
.model
.AbstractUtility
;
25 import eu
.etaxonomy
.taxeditor
.preference
.Resources
;
26 import eu
.etaxonomy
.taxeditor
.store
.StoreUtil
;
27 import eu
.etaxonomy
.taxeditor
.ui
.element
.CdmFormFactory
;
28 import eu
.etaxonomy
.taxeditor
.ui
.element
.ICdmFormElement
;
29 import eu
.etaxonomy
.taxeditor
.ui
.element
.LayoutConstants
;
30 import eu
.etaxonomy
.taxeditor
.ui
.element
.TextWithLabelElement
;
31 import eu
.etaxonomy
.taxeditor
.ui
.element
.TimePeriodElement
;
32 import eu
.etaxonomy
.taxeditor
.ui
.section
.AbstractCdmDetailElement
;
33 import eu
.etaxonomy
.taxeditor
.ui
.section
.common
.ExternalLinksSection
;
34 import eu
.etaxonomy
.taxeditor
.ui
.selection
.EntitySelectionElement
;
40 public class OriginalSourceElement
<T
extends OriginalSourceBase
>
41 extends AbstractCdmDetailElement
<T
>
42 implements IPropertyChangeListener
{
44 protected ICdmFormElement composite
;
45 protected EntitySelectionElement
<Reference
> selection_Ref
;
46 protected TextWithLabelElement microReference
;
47 protected TimePeriodElement accessed
;
48 protected OriginalSourceAdvancedSection advancedSection
;
49 protected String label
= "Source";
50 protected CdmBase cdmEntity
;
51 protected ExternalLinksSection externalLinks
;
52 protected ReferenceType refType
;
54 public OriginalSourceElement(CdmFormFactory formFactory
, ICdmFormElement formElement
, CdmBase cdmEntity
, String label
) {
55 super(formFactory
, formElement
);
56 this.cdmEntity
= cdmEntity
;
61 protected void createControls(ICdmFormElement formElement
, T entity
, int style
) {
63 selection_Ref
= formFactory
.createSelectionElement(Reference
.class,
64 formElement
, label
, null,
65 EntitySelectionElement
.ALL
, style
, 100);
68 selection_Ref
.setEntity(entity
.getCitation());
69 if (entity
.getCitation() != null) {
70 refType
= entity
.getCitation().getType();
74 selection_Ref
.setBackground(this.getPersistentBackground());
75 microReference
= formFactory
.createTextWithLabelElement(formElement
, "Details", entity
!= null? entity
.getCitationMicroReference(): "", style
);
76 microReference
.setIndent(10);
77 for (ICdmFormElement element
: selection_Ref
.getElements()){
78 element
.setBackground(getPersistentBackground());
81 //TODO preliminary #10057
82 if (entity
!= null && entity
.getCitation() != null && entity
.getCitation().isDynamic()){
83 TimePeriod acc
=entity
.getAccessed(); // (entity != null? entity.getAccessed(): null);
84 accessed
= formFactory
.createTimePeriodElement(formElement
, "Accessed", acc
, style
);
87 externalLinks
= formFactory
.createExternalLinksSection(formElement
, "Link(s)", StoreUtil
.getSectionStyle(ExternalLinksSection
.class, DescriptionElementSource
.class.getCanonicalName()));
88 externalLinks
.setLayoutData(LayoutConstants
.FILL_HORIZONTALLY(2, 3));
89 externalLinks
.setEntity(HibernateProxyHelper
.deproxy(entity
));
90 externalLinks
.setFont(AbstractUtility
.getFont(Resources
.COLOR_FONT_DEFAULT
));
91 externalLinks
.setEmptySectionString("No links yet.");
93 addControl(externalLinks
);
94 addElement(externalLinks
);
95 advancedSection
= formFactory
.createOriginalSourceAdvancedSection(formElement
, null, StoreUtil
.getSectionStyle(OriginalSourceAdvancedSection
.class, INomenclaturalReference
.class.getCanonicalName()));
96 TableWrapData layoutData
= LayoutConstants
.FILL_HORIZONTALLY(2, 1);
97 advancedSection
.setLayoutData(layoutData
);
98 advancedSection
.setFont(AbstractUtility
.getFont(Resources
.COLOR_FONT_DEFAULT
));
99 addControl(advancedSection
);
100 addElement(advancedSection
);
101 advancedSection
.setBackground(this.getPersistentBackground());
102 advancedSection
.setEntity(entity
);
104 advancedSection
.setExpanded(false);
105 }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)){
106 advancedSection
.setExpanded(true);
108 advancedSection
.setExpanded(false);
113 public void handleEvent(Object eventSource
) {
114 if (eventSource
.equals(selection_Ref
)){
116 getEntity().setCitation(selection_Ref
.getEntity());
117 ReferenceType newRefType
= getEntity().getCitation().getType();
118 if (refType
!= null && refType
.isDynamic() ^
getEntity().getCitation().getType().isDynamic()) {
120 // this.getParentElement().refresh();
122 refType
= newRefType
;
123 }else if (eventSource
.equals(microReference
)){
124 getEntity().setCitationMicroReference(microReference
.getText());
125 }else if(eventSource
== accessed
){
126 getEntity().setAccessed(accessed
.getTimePeriod());
130 public void setCdmEntity(CdmBase cdmEntity
) {
131 this.cdmEntity
= cdmEntity
;
134 public EntitySelectionElement
<Reference
> getReferenceSelectionElement(){
135 return selection_Ref
;
138 public void setIndent(int indent
){
139 selection_Ref
.setIndent(indent
);
140 microReference
.setIndent(indent
+10);
141 externalLinks
.setIndent(indent
+10);
142 advancedSection
.setIndent(indent
+10);
146 public void refresh() {
148 this.getParentElement().refresh();
152 public void fillFields() {
153 if (getEntity() != null) {
154 selection_Ref
.setEntity(getEntity().getCitation()!= null?
getEntity().getCitation(): null);
155 microReference
.setText(getEntity().getCitationMicroReference());
156 if (accessed
!= null) {
157 accessed
.setEntity(getEntity().getAccessed()!= null?
getEntity().getAccessed(): null);
159 if (advancedSection
!= null) {
160 advancedSection
.setEntity(getEntity());
163 externalLinks
.setEntity(getEntity());