Project

General

Profile

Download (1.85 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

    
18
/**
19
 * @author pplitzner
20
 * @date 13.02.2018
21
 *
22
 */
23
public class DefinedTermSorter extends ViewerComparator {
24

    
25
    @Override
26
    public int compare(Viewer viewer, Object e1, Object e2) {
27
     // the comparison value in this method determines the
28
        // location <-> add term method used in the MoveDefinedTermOperation
29
        // execute call
30
        //FIXME: remove this when all viewer are changed to use DTOs
31
        if(e1 instanceof OrderedTermBase && e2 instanceof OrderedTermBase) {
32
            OrderedTermBase otbe1 = (OrderedTermBase)e1;
33
            OrderedTermBase otbe2 = (OrderedTermBase)e2;
34
            if(otbe1.getOrderIndex() == otbe2.getOrderIndex()) {
35
                return 0;
36
            } else if (otbe1.getOrderIndex() < otbe2.getOrderIndex()){
37
                return -1;
38
            } else{
39
                return 1;
40
            }
41
        }
42
        else if(e1 instanceof TermDto && e2 instanceof TermDto) {
43
            TermDto termDto1 = (TermDto)e1;
44
            TermDto termDto2 = (TermDto)e2;
45
            if(termDto1.getOrderIndex() == termDto2.getOrderIndex()) {
46
                return 0;
47
            } else if (termDto1.getOrderIndex() < termDto2.getOrderIndex()){
48
                return -1;
49
            } else{
50
                return 1;
51
            }
52
        }
53
        else {
54
            return super.compare(viewer, e1, e2);
55
        }
56
    }
57
}
(1-1/9)