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.metadata.PreferencePredicate;
|
19
|
import eu.etaxonomy.cdm.model.reference.ICdmTarget;
|
20
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
|
21
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
|
22
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
23
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
24
|
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.combo.OriginalSourceTypeComparator;
|
26
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
27
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
28
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
29
|
import eu.etaxonomy.taxeditor.ui.element.SelectionArbitrator;
|
30
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
31
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionElement;
|
32
|
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection;
|
33
|
import eu.etaxonomy.taxeditor.ui.selection.EntitySelectionElement;
|
34
|
|
35
|
/**
|
36
|
* @author n.hoffmann
|
37
|
* @created Mar 16, 2010
|
38
|
*/
|
39
|
public abstract class AbstractOriginalSourceElement<T extends OriginalSourceBase> extends AbstractEntityCollectionElement<T> {
|
40
|
|
41
|
private SelectionArbitrator selectionArbitrator;
|
42
|
|
43
|
protected boolean isCommonNameReference = false;
|
44
|
protected EntitySelectionElement<Reference> selection_reference;
|
45
|
protected TextWithLabelElement text_referenceDetail;
|
46
|
protected EnumComboElement<OriginalSourceType> combo_origsourcetype;
|
47
|
protected TextWithLabelElement text_idInSource;
|
48
|
protected TextWithLabelElement text_idNamespace;
|
49
|
protected TextWithLabelElement text_originaleNameString;
|
50
|
protected TextWithLabelElement text_cdmsource;
|
51
|
|
52
|
protected ExternalLinksSection externalLinks;
|
53
|
|
54
|
public AbstractOriginalSourceElement(CdmFormFactory formFactory,
|
55
|
AbstractFormSection section,
|
56
|
T element, SelectionListener removeListener,
|
57
|
int style, boolean isCommonNameReference) {
|
58
|
super(formFactory, section, element, removeListener, null, style);
|
59
|
if(formFactory.getSelectionProvider() != null){
|
60
|
selectionArbitrator = formFactory.createSelectionArbitrator(this);
|
61
|
}
|
62
|
this.isCommonNameReference = isCommonNameReference;
|
63
|
}
|
64
|
|
65
|
public AbstractOriginalSourceElement(CdmFormFactory formFactory,
|
66
|
AbstractFormSection section,
|
67
|
T element, SelectionListener removeListener,
|
68
|
int style) {
|
69
|
this(formFactory, section, element, removeListener, style, false);
|
70
|
}
|
71
|
|
72
|
@Override
|
73
|
public void setEntity(T entity) {
|
74
|
this.entity = entity;
|
75
|
if (selection_reference != null){
|
76
|
selection_reference.setEntity(entity.getCitation());
|
77
|
text_referenceDetail.setText(entity.getCitationMicroReference());
|
78
|
text_originaleNameString.setText(entity.getOriginalNameString());
|
79
|
ICdmTarget cdmSource = entity.getCdmSource();
|
80
|
String source = "";
|
81
|
if(cdmSource instanceof IdentifiableEntity) {
|
82
|
source = ((IdentifiableEntity) cdmSource).getTitleCache();
|
83
|
} else if(cdmSource instanceof CdmBase) {
|
84
|
source += CdmUtils.isNotBlank(source)?"\nUUID: ":"";
|
85
|
source += ((CdmBase) cdmSource).getUuid().toString();
|
86
|
} else if(cdmSource!=null){
|
87
|
source = cdmSource.toString();
|
88
|
}
|
89
|
text_cdmsource.setText(source);
|
90
|
externalLinks.setEntity(entity);
|
91
|
}
|
92
|
}
|
93
|
|
94
|
/**
|
95
|
* @wbp.parser.entryPoint*/
|
96
|
@Override
|
97
|
public void createControls(ICdmFormElement formElement, int style) {
|
98
|
if (isCommonNameReference && PreferencesUtil.getFilterCommonNameReferences()){
|
99
|
selection_reference = formFactory
|
100
|
.createCommonNameReferenceSelectionElement(formElement, "Reference",
|
101
|
null, EntitySelectionElement.ALL, style);
|
102
|
}else{
|
103
|
selection_reference = formFactory
|
104
|
.createSelectionElement(Reference.class,//getConversationHolder(),
|
105
|
formElement, "Reference",
|
106
|
null, EntitySelectionElement.ALL, style);
|
107
|
}
|
108
|
|
109
|
text_referenceDetail = formFactory.createTextWithLabelElement(
|
110
|
formElement, "Reference Detail", null, SWT.NULL);
|
111
|
|
112
|
combo_origsourcetype = formFactory
|
113
|
.createEnumComboElement(OriginalSourceType.class,
|
114
|
formElement, new OriginalSourceTypeComparator(getEntity()), style, false);
|
115
|
|
116
|
if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSource.getKey())){
|
117
|
text_idInSource = formFactory.createTextWithLabelElement(formElement, "ID in Source", null, style);
|
118
|
}
|
119
|
if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowNamespaceInSource.getKey())){
|
120
|
text_idNamespace = formFactory.createTextWithLabelElement(formElement, "ID Namespace", null, style);
|
121
|
}
|
122
|
text_originaleNameString = formFactory.createTextWithLabelElement(
|
123
|
formElement, "Original Information", null, SWT.NULL);
|
124
|
text_cdmsource = formFactory.createTextWithLabelElement(
|
125
|
formElement, "CDM Source", null, SWT.NULL);
|
126
|
((Text) text_cdmsource.getMainControl()).setEditable(false);
|
127
|
|
128
|
if (entity != null){
|
129
|
selection_reference.setEntity(entity.getCitation());
|
130
|
text_referenceDetail.setText(entity.getCitationMicroReference());
|
131
|
text_originaleNameString.setText(entity.getOriginalNameString());
|
132
|
ICdmTarget cdmSource = entity.getCdmSource();
|
133
|
String source = "";
|
134
|
if(cdmSource instanceof IdentifiableEntity) {
|
135
|
source = ((IdentifiableEntity) cdmSource).getTitleCache();
|
136
|
} else if(cdmSource instanceof CdmBase) {
|
137
|
source += CdmUtils.isNotBlank(source)?"\nUUID: ":"";
|
138
|
source += ((CdmBase) cdmSource).getUuid().toString();
|
139
|
} else if(cdmSource!=null){
|
140
|
source = cdmSource.toString();
|
141
|
}
|
142
|
text_cdmsource.setText(source);
|
143
|
if (externalLinks != null){
|
144
|
externalLinks.setEntity(entity);
|
145
|
}
|
146
|
}
|
147
|
}
|
148
|
}
|