1
|
/**
|
2
|
* Copyright (C) 2018 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.description;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.Comparator;
|
13
|
import java.util.HashSet;
|
14
|
|
15
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
16
|
import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
|
17
|
import eu.etaxonomy.cdm.model.description.DescriptionElementSource;
|
18
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
|
19
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceType;
|
20
|
import eu.etaxonomy.cdm.model.reference.Reference;
|
21
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
22
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
23
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
|
24
|
|
25
|
/**
|
26
|
* DescriptionElementSourceSection class.
|
27
|
*
|
28
|
* @author n.hoffmann
|
29
|
* @created Nov 17, 2009
|
30
|
*/
|
31
|
public class DescriptionElementSourceSection extends
|
32
|
AbstractEntityCollectionSection<DescriptionElementBase, OriginalSourceBase> {
|
33
|
|
34
|
private Reference defaultSource;
|
35
|
|
36
|
public DescriptionElementSourceSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation,
|
37
|
ICdmFormElement parentElement, int style) {
|
38
|
super(cdmFormFactory, conversation, parentElement, "Sources", style);
|
39
|
}
|
40
|
|
41
|
public DescriptionElementSourceSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation,
|
42
|
ICdmFormElement parentElement, Reference defaultSource, int style) {
|
43
|
super(cdmFormFactory, conversation, parentElement, "Sources", style);
|
44
|
this.defaultSource = defaultSource;
|
45
|
}
|
46
|
|
47
|
@Override
|
48
|
public DescriptionElementSource createNewElement() {
|
49
|
DescriptionElementSource source = DescriptionElementSource.NewInstance(OriginalSourceType.PrimaryTaxonomicSource);
|
50
|
if (defaultSource != null){
|
51
|
source.setCitation(defaultSource);
|
52
|
}
|
53
|
return source;
|
54
|
}
|
55
|
|
56
|
@Override
|
57
|
public Collection<OriginalSourceBase> getCollection(DescriptionElementBase entity) {
|
58
|
Collection<OriginalSourceBase> sources = new HashSet<>();
|
59
|
sources.addAll(entity.getSources());
|
60
|
sources.addAll(entity.getInDescription().getSources());
|
61
|
|
62
|
return sources;
|
63
|
}
|
64
|
|
65
|
@Override
|
66
|
public Comparator<OriginalSourceBase> getComparator() {
|
67
|
return new SourceComparator<>();
|
68
|
}
|
69
|
|
70
|
@Override
|
71
|
public String getEmptyString() {
|
72
|
return "No references yet.";
|
73
|
}
|
74
|
|
75
|
@Override
|
76
|
protected String getTooltipString() {
|
77
|
return "Create a new reference";
|
78
|
}
|
79
|
|
80
|
@Override
|
81
|
public void addElement(OriginalSourceBase element) {
|
82
|
if (element instanceof DescriptionElementSource){
|
83
|
getEntity().addSource((DescriptionElementSource)element);
|
84
|
}
|
85
|
}
|
86
|
|
87
|
@Override
|
88
|
public void removeElement(OriginalSourceBase element) {
|
89
|
if (element instanceof DescriptionElementSource){
|
90
|
getEntity().removeSource((DescriptionElementSource)element);
|
91
|
}
|
92
|
}
|
93
|
|
94
|
@Override
|
95
|
public DescriptionElementSource addExisting() {
|
96
|
return null;
|
97
|
}
|
98
|
|
99
|
@Override
|
100
|
public boolean allowAddExisting() {
|
101
|
return false;
|
102
|
}
|
103
|
}
|