3 * Copyright (C) 2018 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.definedterm
;
12 import org
.eclipse
.jface
.viewers
.Viewer
;
13 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
15 import eu
.etaxonomy
.cdm
.api
.service
.l10n
.TermRepresentation_L10n
;
16 import eu
.etaxonomy
.cdm
.model
.term
.OrderedTermBase
;
17 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermDto
;
18 import eu
.etaxonomy
.cdm
.persistence
.dto
.TermVocabularyDto
;
24 public class DefinedTermSorter
extends ViewerComparator
{
27 public int compare(Viewer viewer
, Object e1
, Object e2
) {
28 // the comparison value in this method determines the
29 // location <-> add term method used in the MoveDefinedTermOperation
31 //FIXME: remove this when all viewer are changed to use DTOs
32 if(e1
instanceof OrderedTermBase
&& e2
instanceof OrderedTermBase
) {
33 OrderedTermBase otbe1
= (OrderedTermBase
)e1
;
34 OrderedTermBase otbe2
= (OrderedTermBase
)e2
;
35 if(otbe1
.getOrderIndex() == otbe2
.getOrderIndex()) {
37 } else if (otbe1
.getOrderIndex() < otbe2
.getOrderIndex()){
43 else if(e1
instanceof TermDto
&& e2
instanceof TermDto
) {
44 TermDto termDto1
= (TermDto
)e1
;
45 TermDto termDto2
= (TermDto
)e2
;
46 int orderIndexCompare
= 0;
47 if(termDto1
.getOrderIndex()!=null){
48 if(termDto2
.getOrderIndex()!=null){
49 orderIndexCompare
= termDto1
.getOrderIndex() - termDto2
.getOrderIndex();
52 orderIndexCompare
= 1;
55 else if(termDto2
.getOrderIndex()!=null){
56 orderIndexCompare
= -1;
58 if(orderIndexCompare
!= 0){
59 return orderIndexCompare
;
62 // order indexes are equal or null -> compare by label
63 termDto1
.localize(new TermRepresentation_L10n());
64 termDto2
.localize(new TermRepresentation_L10n());
65 if(termDto1
.getRepresentation_L10n()!=null){
66 if(termDto2
.getRepresentation_L10n()!=null) {
67 return termDto1
.getRepresentation_L10n().toLowerCase().compareTo(termDto2
.getRepresentation_L10n().toLowerCase());
73 else if(termDto2
.getRepresentation_L10n()!=null){
78 else if(e1
instanceof TermVocabularyDto
&& e2
instanceof TermVocabularyDto
) {
79 TermVocabularyDto termVoc1
= (TermVocabularyDto
)e1
;
80 TermVocabularyDto termVoc2
= (TermVocabularyDto
)e2
;
81 termVoc1
.localize(new TermRepresentation_L10n());
82 termVoc2
.localize(new TermRepresentation_L10n());
83 if(termVoc1
.getRepresentation_L10n()!=null){
84 if(termVoc2
.getRepresentation_L10n()!=null) {
85 return termVoc1
.getRepresentation_L10n().toLowerCase().compareTo(termVoc2
.getRepresentation_L10n().toLowerCase());
91 else if(termVoc2
.getRepresentation_L10n()!=null){
95 return super.compare(viewer
, e1
, e2
);