Project

General

Profile

Download (2.7 KB) Statistics
| Branch: | Tag: | Revision:
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.common.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
            if(termDto1.getOrderIndex() == termDto2.getOrderIndex()) {
48
                return 0;
49
            } else if (termDto1.getOrderIndex() < termDto2.getOrderIndex()){
50
                return -1;
51
            } else{
52
                return 1;
53
            }
54
        }
55
        else if(e1 instanceof TermVocabularyDto && e2 instanceof TermVocabularyDto) {
56
            TermVocabularyDto termVoc1 = (TermVocabularyDto)e1;
57
            TermVocabularyDto termVoc2 = (TermVocabularyDto)e2;
58
            termVoc1.localize(new TermRepresentation_L10n());
59
            termVoc2.localize(new TermRepresentation_L10n());
60
            if(termVoc1.getRepresentation_L10n()!=null){
61
                if(termVoc2.getRepresentation_L10n()!=null) {
62
                    return termVoc1.getRepresentation_L10n().compareTo(termVoc2.getRepresentation_L10n());
63
                }
64
                else{
65
                    return 1;
66
                }
67
            }
68
            else if(termVoc2.getRepresentation_L10n()!=null){
69
                return -1;
70
            }
71
        }
72
        return super.compare(viewer, e1, e2);
73
    }
74
}
(1-1/6)