1
|
/**
|
2
|
*
|
3
|
*/
|
4
|
package eu.etaxonomy.taxeditor.ui.section.supplemental;
|
5
|
|
6
|
import java.util.ArrayList;
|
7
|
import java.util.Collection;
|
8
|
import java.util.Collections;
|
9
|
import java.util.Comparator;
|
10
|
import java.util.List;
|
11
|
|
12
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
13
|
import eu.etaxonomy.cdm.model.common.IIdentifiableEntity;
|
14
|
import eu.etaxonomy.cdm.model.common.IdentifiableSource;
|
15
|
import eu.etaxonomy.cdm.model.common.OriginalSourceType;
|
16
|
import eu.etaxonomy.cdm.model.media.Media;
|
17
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
18
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
19
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
|
20
|
import eu.etaxonomy.taxeditor.ui.section.DefaultCdmBaseComparator;
|
21
|
import eu.etaxonomy.taxeditor.ui.section.description.SourceComparator;
|
22
|
|
23
|
/**
|
24
|
* <p>SourceSection class.</p>
|
25
|
*
|
26
|
* @author n.hoffmann
|
27
|
* @created Nov 17, 2009
|
28
|
* @version 1.0
|
29
|
*/
|
30
|
public class SourceSection extends AbstractEntityCollectionSection<IIdentifiableEntity, IdentifiableSource> {
|
31
|
|
32
|
/**
|
33
|
* <p>Constructor for SourceSection.</p>
|
34
|
*
|
35
|
* @param parentElement a {@link eu.etaxonomy.taxeditor.ui.element.ICdmFormElement} object.
|
36
|
* @param style a int.
|
37
|
* @param cdmFormFactory a {@link eu.etaxonomy.taxeditor.ui.element.CdmFormFactory} object.
|
38
|
* @param conversation a {@link eu.etaxonomy.cdm.api.conversation.ConversationHolder} object.
|
39
|
*/
|
40
|
public SourceSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation, ICdmFormElement parentElement, int style) {
|
41
|
super(cdmFormFactory, conversation, parentElement, "Sources", style);
|
42
|
}
|
43
|
|
44
|
/** {@inheritDoc} */
|
45
|
@Override
|
46
|
public IdentifiableSource createNewElement() {
|
47
|
IIdentifiableEntity entity = getEntity();
|
48
|
OriginalSourceType type;
|
49
|
if(entity instanceof Media) {
|
50
|
type = OriginalSourceType.PrimaryMediaSource;
|
51
|
}
|
52
|
else{
|
53
|
//default
|
54
|
type = OriginalSourceType.PrimaryTaxonomicSource;
|
55
|
}
|
56
|
return IdentifiableSource.NewInstance(type);
|
57
|
}
|
58
|
|
59
|
/** {@inheritDoc} */
|
60
|
@Override
|
61
|
public Collection<IdentifiableSource> getCollection(
|
62
|
IIdentifiableEntity entity) {
|
63
|
List<IdentifiableSource> sources = new ArrayList<IdentifiableSource>(entity.getSources());
|
64
|
Collections.sort(sources, new SourceComparator());
|
65
|
return sources;
|
66
|
}
|
67
|
|
68
|
@Override
|
69
|
public Comparator<IdentifiableSource> getComparator() {
|
70
|
return new DefaultCdmBaseComparator<>();
|
71
|
}
|
72
|
|
73
|
/** {@inheritDoc} */
|
74
|
@Override
|
75
|
public String getEmptyString() {
|
76
|
return "No references yet.";
|
77
|
}
|
78
|
|
79
|
/** {@inheritDoc} */
|
80
|
@Override
|
81
|
protected String getTooltipString() {
|
82
|
return "Create a new reference.";
|
83
|
}
|
84
|
|
85
|
/** {@inheritDoc} */
|
86
|
@Override
|
87
|
public void addElement(IdentifiableSource element) {
|
88
|
getEntity().addSource(element);
|
89
|
}
|
90
|
|
91
|
/** {@inheritDoc} */
|
92
|
@Override
|
93
|
public void removeElement(IdentifiableSource element) {
|
94
|
getEntity().removeSource(element);
|
95
|
}
|
96
|
|
97
|
/**
|
98
|
* {@inheritDoc}
|
99
|
*/
|
100
|
@Override
|
101
|
public IdentifiableSource addExisting() {
|
102
|
// TODO Auto-generated method stub
|
103
|
return null;
|
104
|
}
|
105
|
|
106
|
/**
|
107
|
* {@inheritDoc}
|
108
|
*/
|
109
|
@Override
|
110
|
public boolean allowAddExisting() {
|
111
|
// TODO Auto-generated method stub
|
112
|
return false;
|
113
|
}
|
114
|
|
115
|
}
|