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.common;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.Comparator;
|
13
|
|
14
|
import eu.etaxonomy.cdm.api.conversation.ConversationHolder;
|
15
|
import eu.etaxonomy.cdm.model.reference.OriginalSourceBase;
|
16
|
import eu.etaxonomy.cdm.model.media.ExternalLink;
|
17
|
import eu.etaxonomy.cdm.model.media.ExternalLinkType;
|
18
|
import eu.etaxonomy.taxeditor.ui.element.CdmFormFactory;
|
19
|
import eu.etaxonomy.taxeditor.ui.element.ICdmFormElement;
|
20
|
import eu.etaxonomy.taxeditor.ui.section.AbstractEntityCollectionSection;
|
21
|
|
22
|
/**
|
23
|
* @author k.luther
|
24
|
* @since 23.08.2018
|
25
|
*
|
26
|
*/
|
27
|
public class ExternalLinksSection extends AbstractEntityCollectionSection<OriginalSourceBase, ExternalLink> {
|
28
|
|
29
|
|
30
|
|
31
|
/**
|
32
|
* @param formFactory
|
33
|
* @param formElement
|
34
|
*/
|
35
|
public ExternalLinksSection(CdmFormFactory cdmFormFactory, ConversationHolder conversation, ICdmFormElement parentElement, int style) {
|
36
|
super(cdmFormFactory, conversation, parentElement, "External Links", style);
|
37
|
|
38
|
}
|
39
|
|
40
|
|
41
|
@Override
|
42
|
public Comparator<ExternalLink> getComparator() {
|
43
|
return new Comparator<ExternalLink>(){
|
44
|
|
45
|
@Override
|
46
|
public int compare(ExternalLink o1, ExternalLink o2) {
|
47
|
if (o1 == o2){
|
48
|
return 0;
|
49
|
}
|
50
|
if (o1 == null){
|
51
|
return -1;
|
52
|
|
53
|
}
|
54
|
if (o2== null){
|
55
|
return 1;
|
56
|
}
|
57
|
if (o1.getUri() == o1.getUri()){
|
58
|
return 0;
|
59
|
}
|
60
|
if (o1.getUri() == null){
|
61
|
return -1;
|
62
|
}
|
63
|
if (o2.getUri() == null){
|
64
|
return 1;
|
65
|
}
|
66
|
return o1.getUri().toString().compareTo(o2.getUri().toString());
|
67
|
|
68
|
}
|
69
|
|
70
|
};
|
71
|
|
72
|
}
|
73
|
|
74
|
|
75
|
|
76
|
@Override
|
77
|
public Collection<ExternalLink> getCollection(OriginalSourceBase entity) {
|
78
|
if (entity != null){
|
79
|
return entity.getLinks();
|
80
|
} else {
|
81
|
return null;
|
82
|
}
|
83
|
|
84
|
}
|
85
|
|
86
|
@Override
|
87
|
public ExternalLink createNewElement() {
|
88
|
ExternalLink link = ExternalLink.NewInstance(ExternalLinkType.Unknown, null);
|
89
|
return link;
|
90
|
}
|
91
|
|
92
|
@Override
|
93
|
public void addElement(ExternalLink element) {
|
94
|
getEntity().addLink(element);
|
95
|
|
96
|
}
|
97
|
|
98
|
@Override
|
99
|
public ExternalLink addExisting() {
|
100
|
return null;
|
101
|
}
|
102
|
|
103
|
@Override
|
104
|
public boolean allowAddExisting() {
|
105
|
return false;
|
106
|
}
|
107
|
|
108
|
@Override
|
109
|
public void removeElement(ExternalLink element) {
|
110
|
getEntity().removeLink(element);
|
111
|
|
112
|
}
|
113
|
|
114
|
@Override
|
115
|
public String getEmptyString() {
|
116
|
return "No external link yet.";
|
117
|
}
|
118
|
|
119
|
|
120
|
@Override
|
121
|
protected String getTooltipString() {
|
122
|
return null;
|
123
|
}
|
124
|
|
125
|
}
|