1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2018 EDIT
|
4
|
* European Distributed Institute of Taxonomy
|
5
|
* http://www.e-taxonomy.eu
|
6
|
*
|
7
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
8
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
9
|
*/
|
10
|
package eu.etaxonomy.taxeditor.editor.definedterm;
|
11
|
|
12
|
import org.eclipse.jface.viewers.Viewer;
|
13
|
import org.eclipse.jface.viewers.ViewerComparator;
|
14
|
|
15
|
import eu.etaxonomy.cdm.model.term.OrderedTermBase;
|
16
|
import eu.etaxonomy.cdm.persistence.dto.TermDto;
|
17
|
import eu.etaxonomy.cdm.persistence.dto.TermVocabularyDto;
|
18
|
import eu.etaxonomy.cdm.remote.l10n.TermRepresentation_L10n;
|
19
|
|
20
|
/**
|
21
|
* @author pplitzner
|
22
|
* @date 13.02.2018
|
23
|
*
|
24
|
*/
|
25
|
public class DefinedTermSorter extends ViewerComparator {
|
26
|
|
27
|
@Override
|
28
|
public int compare(Viewer viewer, Object e1, Object e2) {
|
29
|
// the comparison value in this method determines the
|
30
|
// location <-> add term method used in the MoveDefinedTermOperation
|
31
|
// execute call
|
32
|
//FIXME: remove this when all viewer are changed to use DTOs
|
33
|
if(e1 instanceof OrderedTermBase && e2 instanceof OrderedTermBase) {
|
34
|
OrderedTermBase otbe1 = (OrderedTermBase)e1;
|
35
|
OrderedTermBase otbe2 = (OrderedTermBase)e2;
|
36
|
if(otbe1.getOrderIndex() == otbe2.getOrderIndex()) {
|
37
|
return 0;
|
38
|
} else if (otbe1.getOrderIndex() < otbe2.getOrderIndex()){
|
39
|
return -1;
|
40
|
} else{
|
41
|
return 1;
|
42
|
}
|
43
|
}
|
44
|
else if(e1 instanceof TermDto && e2 instanceof TermDto) {
|
45
|
TermDto termDto1 = (TermDto)e1;
|
46
|
TermDto termDto2 = (TermDto)e2;
|
47
|
int orderIndexCompare = 0;
|
48
|
if(termDto1.getOrderIndex()!=null){
|
49
|
if(termDto2.getOrderIndex()!=null){
|
50
|
orderIndexCompare = termDto1.getOrderIndex() - termDto2.getOrderIndex();
|
51
|
}
|
52
|
else{
|
53
|
orderIndexCompare = 1;
|
54
|
}
|
55
|
}
|
56
|
else if(termDto2.getOrderIndex()!=null){
|
57
|
orderIndexCompare = -1;
|
58
|
}
|
59
|
if(orderIndexCompare != 0){
|
60
|
return orderIndexCompare;
|
61
|
}
|
62
|
else {
|
63
|
// order indexes are equal or null -> compare by label
|
64
|
termDto1.localize(new TermRepresentation_L10n());
|
65
|
termDto2.localize(new TermRepresentation_L10n());
|
66
|
if(termDto1.getRepresentation_L10n()!=null){
|
67
|
if(termDto2.getRepresentation_L10n()!=null) {
|
68
|
return termDto1.getRepresentation_L10n().toLowerCase().compareTo(termDto2.getRepresentation_L10n().toLowerCase());
|
69
|
}
|
70
|
else{
|
71
|
return 1;
|
72
|
}
|
73
|
}
|
74
|
else if(termDto2.getRepresentation_L10n()!=null){
|
75
|
return -1;
|
76
|
}
|
77
|
}
|
78
|
}
|
79
|
else if(e1 instanceof TermVocabularyDto && e2 instanceof TermVocabularyDto) {
|
80
|
TermVocabularyDto termVoc1 = (TermVocabularyDto)e1;
|
81
|
TermVocabularyDto termVoc2 = (TermVocabularyDto)e2;
|
82
|
termVoc1.localize(new TermRepresentation_L10n());
|
83
|
termVoc2.localize(new TermRepresentation_L10n());
|
84
|
if(termVoc1.getRepresentation_L10n()!=null){
|
85
|
if(termVoc2.getRepresentation_L10n()!=null) {
|
86
|
return termVoc1.getRepresentation_L10n().toLowerCase().compareTo(termVoc2.getRepresentation_L10n().toLowerCase());
|
87
|
}
|
88
|
else{
|
89
|
return 1;
|
90
|
}
|
91
|
}
|
92
|
else if(termVoc2.getRepresentation_L10n()!=null){
|
93
|
return -1;
|
94
|
}
|
95
|
}
|
96
|
return super.compare(viewer, e1, e2);
|
97
|
}
|
98
|
}
|