1
|
// $Id$
|
2
|
/**
|
3
|
* Copyright (C) 2007 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
|
|
11
|
package eu.etaxonomy.taxeditor.editor.view.checklist;
|
12
|
|
13
|
import org.eclipse.jface.viewers.Viewer;
|
14
|
import org.eclipse.jface.viewers.ViewerComparator;
|
15
|
|
16
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
17
|
|
18
|
/**
|
19
|
* @author a.oppermann
|
20
|
* @created 30.04.2014
|
21
|
* @version 1.0
|
22
|
*/
|
23
|
public class ChecklistEditorComparator extends ViewerComparator {
|
24
|
|
25
|
private int propertyIndex;
|
26
|
private static final int ASCENDING = 0;
|
27
|
private static final int DESCENDING = 1;
|
28
|
private int direction = ASCENDING;
|
29
|
|
30
|
public ChecklistEditorComparator() {
|
31
|
this.propertyIndex = 1;
|
32
|
direction = ASCENDING;
|
33
|
}
|
34
|
|
35
|
public void setColumn(int column) {
|
36
|
if (column == this.propertyIndex) {
|
37
|
// Same column as last sort; toggle the direction
|
38
|
direction = 1 - direction;
|
39
|
} else {
|
40
|
// New column; do an ascending sort
|
41
|
this.propertyIndex = column;
|
42
|
direction = DESCENDING;
|
43
|
}
|
44
|
}
|
45
|
|
46
|
/* (non-Javadoc)
|
47
|
* @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
|
48
|
*/
|
49
|
@Override
|
50
|
public int compare(Viewer viewer, Object e1, Object e2) {
|
51
|
Taxon d1 = (Taxon) e1;
|
52
|
Taxon d2 = (Taxon) e2;
|
53
|
|
54
|
int result = 0;
|
55
|
|
56
|
switch (propertyIndex) {
|
57
|
|
58
|
default:
|
59
|
result = d1.getTitleCache().compareTo(d2.getTitleCache());
|
60
|
}
|
61
|
|
62
|
// If descending order, flip the direction
|
63
|
if (direction == DESCENDING) {
|
64
|
result = -result;
|
65
|
}
|
66
|
return result;
|
67
|
}
|
68
|
}
|