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
|
|
10
|
package eu.etaxonomy.taxeditor.ui.section.supplemental;
|
11
|
|
12
|
import java.util.Comparator;
|
13
|
|
14
|
import org.eclipse.swt.SWT;
|
15
|
import org.eclipse.swt.events.SelectionListener;
|
16
|
|
17
|
import eu.etaxonomy.cdm.model.metadata.PreferencePredicate;
|
18
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
|
19
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
|
20
|
import eu.etaxonomy.taxeditor.preference.PreferencesUtil;
|
21
|
import eu.etaxonomy.taxeditor.ui.combo.EnumComboElement;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.AbstractFormSection;
|
23
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
24
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
25
|
import eu.etaxonomy.taxeditor.ui.element.TextWithLabelElement;
|
26
|
import eu.etaxonomy.taxeditor.ui.section.common.ExternalLinksSection;
|
27
|
|
28
|
/**
|
29
|
* @author n.hoffmann
|
30
|
* @created Mar 16, 2010
|
31
|
* @version 1.0
|
32
|
*/
|
33
|
public abstract class AbstractOriginalSourceElement<T extends OriginalSourceBase> extends AbstractReferencedEntityElement<T> {
|
34
|
protected EnumComboElement<OriginalSourceType> combo_origsourcetype;
|
35
|
protected TextWithLabelElement text_idInSource;
|
36
|
protected TextWithLabelElement text_idNamespace;
|
37
|
protected TextWithLabelElement text_originaleNameString;
|
38
|
|
39
|
protected ExternalLinksSection externalLinks;
|
40
|
|
41
|
public AbstractOriginalSourceElement(CdmFormFactory formFactory,
|
42
|
AbstractFormSection section,
|
43
|
T element, SelectionListener removeListener,
|
44
|
int style, boolean isCommonNameReference) {
|
45
|
super(formFactory, section, element, removeListener, style, isCommonNameReference);
|
46
|
}
|
47
|
|
48
|
public AbstractOriginalSourceElement(CdmFormFactory formFactory,
|
49
|
AbstractFormSection section,
|
50
|
T element, SelectionListener removeListener,
|
51
|
int style) {
|
52
|
super(formFactory, section, element, removeListener, style);
|
53
|
}
|
54
|
|
55
|
/**
|
56
|
* {@inheritDoc}
|
57
|
*/
|
58
|
@Override
|
59
|
public void setEntity(T entity) {
|
60
|
super.setEntity(entity);
|
61
|
text_originaleNameString.setText(entity.getOriginalNameString());
|
62
|
externalLinks.setEntity(entity);
|
63
|
}
|
64
|
|
65
|
/** {@inheritDoc}
|
66
|
* @wbp.parser.entryPoint*/
|
67
|
@Override
|
68
|
public void createControls(ICdmFormElement formElement, int style) {
|
69
|
combo_origsourcetype = formFactory
|
70
|
.createEnumComboElement(OriginalSourceType.class,
|
71
|
formElement, new OriginalSourceTypeComparator(getEntity()), style);
|
72
|
super.createControls(formElement, style);
|
73
|
if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowIdInSource.getKey())){
|
74
|
text_idInSource = formFactory.createTextWithLabelElement(formElement, "ID in Source", null, style);
|
75
|
}
|
76
|
if (PreferencesUtil.getBooleanValue(PreferencePredicate.ShowNamespaceInSource.getKey())){
|
77
|
text_idNamespace = formFactory.createTextWithLabelElement(formElement, "ID Namespace", null, style);
|
78
|
}
|
79
|
text_originaleNameString = formFactory.createTextWithLabelElement(
|
80
|
formElement, "Original Information", null, SWT.NULL);
|
81
|
|
82
|
|
83
|
|
84
|
}
|
85
|
|
86
|
/**
|
87
|
* Sorts source type combo alphabetically <b>except</b> for PrimaryTaxonomicSource resp.
|
88
|
* PrimaryMediaSource which are always on top depending on the IdentifiableSource;
|
89
|
* <br>
|
90
|
* The last two are always "Other" followed by "Unknown"
|
91
|
* @author pplitzner
|
92
|
* @date Jan 6, 2017
|
93
|
*
|
94
|
*/
|
95
|
private class OriginalSourceTypeComparator implements Comparator<OriginalSourceType>{
|
96
|
|
97
|
private OriginalSourceBase entity;
|
98
|
|
99
|
public OriginalSourceTypeComparator(OriginalSourceBase entity) {
|
100
|
this.entity = entity;
|
101
|
}
|
102
|
|
103
|
/**
|
104
|
* {@inheritDoc}
|
105
|
*/
|
106
|
@Override
|
107
|
public int compare(OriginalSourceType o1, OriginalSourceType o2) {
|
108
|
if(o1==null){
|
109
|
if(o2==null){
|
110
|
return 0;
|
111
|
}
|
112
|
else{
|
113
|
return -1;
|
114
|
}
|
115
|
}
|
116
|
if(o2==null){
|
117
|
return 1;
|
118
|
}
|
119
|
//both are either taxonomic or media
|
120
|
else if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource)
|
121
|
&& o2.equals(OriginalSourceType.PrimaryMediaSource)){
|
122
|
if(entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){
|
123
|
return 1;
|
124
|
}
|
125
|
else{
|
126
|
return -1;
|
127
|
}
|
128
|
}
|
129
|
else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource)
|
130
|
&& o1.equals(OriginalSourceType.PrimaryMediaSource)){
|
131
|
if(entity.getType().equals(OriginalSourceType.PrimaryMediaSource)){
|
132
|
return -1;
|
133
|
}
|
134
|
else{
|
135
|
return 1;
|
136
|
}
|
137
|
}
|
138
|
//one is not taxonomic or media
|
139
|
else if(o1.equals(OriginalSourceType.PrimaryTaxonomicSource)
|
140
|
||o1.equals(OriginalSourceType.PrimaryMediaSource)){
|
141
|
return -1;
|
142
|
|
143
|
}
|
144
|
else if(o2.equals(OriginalSourceType.PrimaryTaxonomicSource)
|
145
|
|| o2.equals(OriginalSourceType.PrimaryMediaSource)){
|
146
|
return 1;
|
147
|
}
|
148
|
//The last two are always "Other" followed by "Unknown"
|
149
|
else if(o1.equals(OriginalSourceType.Other)){
|
150
|
if(o2.equals(OriginalSourceType.Unknown)){
|
151
|
return -11;
|
152
|
}
|
153
|
else{
|
154
|
return 1;
|
155
|
}
|
156
|
}
|
157
|
if(o2.equals(OriginalSourceType.Other)){
|
158
|
return 1;
|
159
|
}
|
160
|
else{
|
161
|
String message1 = o1.getKey();
|
162
|
String message2 = o2.getKey();
|
163
|
return message1.compareTo(message2);
|
164
|
}
|
165
|
}
|
166
|
|
167
|
}
|
168
|
}
|