1
|
/**
|
2
|
* Copyright (C) 2007 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 org.eclipse.swt.SWT;
|
12
|
import org.eclipse.swt.events.SelectionListener;
|
13
|
import org.eclipse.swt.widgets.Text;
|
14
|
|
15
|
import eu.etaxonomy.cdm.common.CdmUtils;
|
16
|
import eu.etaxonomy.cdm.model.common.CdmBase;
|
17
|
import eu.etaxonomy.cdm.model.common.IdentifiableEntity;
|
18
|
import eu.etaxonomy.cdm.model.common.TimePeriod;
|
19
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
20
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
21
|
import eu.etaxonomy.cdm.model.occurrence.SpecimenOrObservationBase;
|
22
|
import eu.etaxonomy.cdm.model.reference.ICdmTarget;
|
23
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
|
24
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
|
25
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
26
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
27
|
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
|
28
|
import eu.etaxonomy.taxeditor.ui.combo.OriginalSourceTypeComparator;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
31
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
|
33
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
34
|
import eu.etaxonomy.taxeditor.ui.element.TimePeriodElement;
|
35
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
|
36
|
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection;
|
37
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
38
|
|
39
|
/**
|
40
|
* @author n.hoffmann
|
41
|
* @created Mar 16, 2010
|
42
|
*/
|
43
|
public abstract class AbstractOriginalSourceElement<T extends OriginalSourceBase>
|
44
|
extends AbstractEntityCollectionElement<T> {
|
45
|
|
46
|
private SelectionArbitrator selectionArbitrator;
|
47
|
|
48
|
protected boolean isCommonNameReference = false;
|
49
|
protected EntitySelectionElement<Reference> selection_reference;
|
50
|
protected EntitySelectionElement<SpecimenOrObservationBase> selection_specimen;
|
51
|
protected TextWithLabelElement text_referenceDetail;
|
52
|
protected TimePeriodElement accessed;
|
53
|
protected EnumComboElement<OriginalSourceType> combo_origsourcetype;
|
54
|
protected TextWithLabelElement text_idInSource;
|
55
|
protected TextWithLabelElement text_idNamespace;
|
56
|
protected TextWithLabelElement text_originalInfo;
|
57
|
protected TextWithLabelElement text_cdmsource;
|
58
|
|
59
|
protected ExternalLinksSection externalLinks;
|
60
|
|
61
|
public AbstractOriginalSourceElement(CdmFormFactory formFactory,
|
62
|
AbstractFormSection section,
|
63
|
T element, SelectionListener removeListener,
|
64
|
int style, boolean isCommonNameReference) {
|
65
|
super(formFactory, section, element, removeListener, null, style);
|
66
|
if(formFactory.getSelectionProvider() != null){
|
67
|
selectionArbitrator = formFactory.createSelectionArbitrator(this);
|
68
|
}
|
69
|
this.isCommonNameReference = isCommonNameReference;
|
70
|
}
|
71
|
|
72
|
public AbstractOriginalSourceElement(CdmFormFactory formFactory,
|
73
|
AbstractFormSection section,
|
74
|
T element, SelectionListener removeListener,
|
75
|
int style) {
|
76
|
this(formFactory, section, element, removeListener, style, false);
|
77
|
}
|
78
|
|
79
|
@Override
|
80
|
public void setEntity(T entity) {
|
81
|
this.entity = entity;
|
82
|
if (selection_reference != null){
|
83
|
selection_reference.setEntity(entity.getCitation());
|
84
|
text_referenceDetail.setText(entity.getCitationMicroReference());
|
85
|
text_originalInfo.setText(entity.getOriginalInfo());
|
86
|
|
87
|
ICdmTarget cdmSource = entity.getCdmSource();
|
88
|
if (cdmSource != null){
|
89
|
String source = "";
|
90
|
if(cdmSource instanceof IdentifiableEntity) {
|
91
|
source = ((IdentifiableEntity) cdmSource).getTitleCache();
|
92
|
} else if(cdmSource instanceof CdmBase) {
|
93
|
source += CdmUtils.isNotBlank(source)?"\nUUID: ":"";
|
94
|
source += ((CdmBase) cdmSource).getUuid().toString();
|
95
|
} else {
|
96
|
source = cdmSource.toString();
|
97
|
}
|
98
|
text_cdmsource.setText(source);
|
99
|
}
|
100
|
if (externalLinks != null){
|
101
|
externalLinks.setEntity(entity);
|
102
|
}
|
103
|
}
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* @wbp.parser.entryPoint*/
|
108
|
@Override
|
109
|
public void createControls(ICdmFormElement formElement, int style) {
|
110
|
if (isCommonNameReference && PreferencesUtil.getFilterCommonNameReferences()){
|
111
|
selection_reference = formFactory
|
112
|
.createCommonNameReferenceSelectionElement(formElement, "Reference",
|
113
|
null, EntitySelectionElement.ALL, style);
|
114
|
}else if (entity instanceof DescriptionElementSource && PreferencesUtil.getBooleanValue(PreferencePredicate.ShowSpecimenInFactSource.getKey())) {
|
115
|
selection_reference = formFactory
|
116
|
.createSelectionElement(Reference.class,
|
117
|
formElement, "Reference",
|
118
|
null, EntitySelectionElement.ALL, style);
|
119
|
selection_specimen = formFactory
|
120
|
.createSelectionElement(SpecimenOrObservationBase.class,
|
121
|
formElement, "or Specimen",
|
122
|
null, EntitySelectionElement.ALL, SWT.NULL);
|
123
|
}else{
|
124
|
selection_reference = formFactory
|
125
|
.createSelectionElement(Reference.class,
|
126
|
formElement, "Reference",
|
127
|
null, EntitySelectionElement.ALL, style);
|
128
|
}
|
129
|
|
130
|
text_referenceDetail = formFactory.createTextWithLabelElement(
|
131
|
formElement, "Reference Detail", null, SWT.NULL);
|
132
|
|
133
|
//TODO preliminary #10057
|
134
|
if (entity != null && entity.getCitation() != null && entity.getCitation().isDynamic()){
|
135
|
TimePeriod acc =entity.getAccessed(); // (entity != null? entity.getAccessed(): null);
|
136
|
accessed = formFactory.createTimePeriodElement(formElement, "Accessed", acc, style);
|
137
|
}
|
138
|
|
139
|
combo_origsourcetype = formFactory
|
140
|
.createEnumComboElement(OriginalSourceType.class,
|
141
|
formElement, new OriginalSourceTypeComparator(getEntity()), style, false);
|
142
|
|
143
|
if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSource.getKey())){
|
144
|
text_idInSource = formFactory.createTextWithLabelElement(formElement, "ID in Source", null, style);
|
145
|
}
|
146
|
if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowNamespaceInSource.getKey())){
|
147
|
text_idNamespace = formFactory.createTextWithLabelElement(formElement, "ID Namespace", null, style);
|
148
|
}
|
149
|
text_originalInfo = formFactory.createTextWithLabelElement(
|
150
|
formElement, "Original Information", null, SWT.NULL);
|
151
|
|
152
|
//we only show the cdm source if it exist.
|
153
|
//It can't be set during editing as it is read only.
|
154
|
if (this.entity != null && this.entity.getCdmSource() != null) {
|
155
|
text_cdmsource = formFactory.createTextWithLabelElement(
|
156
|
formElement, "CDM Source", null, SWT.NULL);
|
157
|
((Text) text_cdmsource.getMainControl()).setEditable(false);
|
158
|
}
|
159
|
|
160
|
if (entity != null){
|
161
|
selection_reference.setEntity(entity.getCitation());
|
162
|
if (selection_specimen != null && entity instanceof DescriptionElementSource) {
|
163
|
selection_specimen.setEntity(((DescriptionElementSource)entity).getSpecimen());
|
164
|
}
|
165
|
text_referenceDetail.setText(entity.getCitationMicroReference());
|
166
|
text_originalInfo.setText(entity.getOriginalInfo());
|
167
|
|
168
|
ICdmTarget cdmSource = entity.getCdmSource();
|
169
|
if (cdmSource != null){
|
170
|
String source = "";
|
171
|
if(cdmSource instanceof IdentifiableEntity) {
|
172
|
source = ((IdentifiableEntity) cdmSource).getTitleCache();
|
173
|
} else if(cdmSource instanceof CdmBase) {
|
174
|
source += CdmUtils.isNotBlank(source)?"\nUUID: ":"";
|
175
|
source += ((CdmBase) cdmSource).getUuid().toString();
|
176
|
} else {
|
177
|
source = cdmSource.toString();
|
178
|
}
|
179
|
text_cdmsource.setText(source);
|
180
|
}
|
181
|
if (externalLinks != null){
|
182
|
externalLinks.setEntity(entity);
|
183
|
}
|
184
|
}
|
185
|
}
|
186
|
|
187
|
@Override
|
188
|
public void handleEvent(Object eventSource) {
|
189
|
if(eventSource == text_idInSource){
|
190
|
getEntity().setIdInSource(text_idInSource.getText());
|
191
|
}
|
192
|
else if(eventSource == text_idNamespace){
|
193
|
getEntity().setIdNamespace(text_idNamespace.getText());
|
194
|
}
|
195
|
else if(eventSource == selection_reference){
|
196
|
getEntity().setCitation(selection_reference.getSelection());
|
197
|
}
|
198
|
else if(eventSource == text_referenceDetail){
|
199
|
getEntity().setCitationMicroReference(text_referenceDetail.getText());
|
200
|
}
|
201
|
else if(eventSource == text_originalInfo){
|
202
|
getEntity().setOriginalInfo(text_originalInfo.getText());
|
203
|
}
|
204
|
else if(eventSource == combo_origsourcetype){
|
205
|
getEntity().setType(combo_origsourcetype.getSelection());
|
206
|
}
|
207
|
else if(eventSource == accessed){
|
208
|
getEntity().setAccessed(accessed.getTimePeriod());
|
209
|
}
|
210
|
}
|
211
|
}
|