Project

General

Profile

Download (1.6 KB) Statistics
| Branch: | Tag: | Revision:
1
/**
2
* Copyright (C) 2007 EDIT
3
* European Distributed Institute of Taxonomy
4
* http://www.e-taxonomy.eu
5
*
6
* The contents of this file are subject to the Mozilla Public License Version 1.1
7
* See LICENSE.TXT at the top of this package for the full license terms.
8
*/
9

    
10
package eu.etaxonomy.taxeditor.editor.view.checklist;
11

    
12
import org.eclipse.jface.viewers.Viewer;
13
import org.eclipse.jface.viewers.ViewerComparator;
14

    
15
import eu.etaxonomy.cdm.model.taxon.Taxon;
16

    
17
/**
18
 * @author a.oppermann
19
 * @created 30.04.2014
20
 * @version 1.0
21
 */
22
public class ChecklistEditorComparator extends ViewerComparator {
23

    
24
	private int propertyIndex;
25
	private static final int ASCENDING = 0;
26
	private static final int DESCENDING = 1;
27
	private int direction = ASCENDING;
28

    
29
	public ChecklistEditorComparator() {
30
		this.propertyIndex = 1;
31
		direction = ASCENDING;
32
	}
33

    
34
	public void setColumn(int column) {
35
		if (column == this.propertyIndex) {
36
			// Same column as last sort; toggle the direction
37
			direction = 1 - direction;
38
		} else {
39
			// New column; do an ascending sort
40
			this.propertyIndex = column;
41
			direction = DESCENDING;
42
		}
43
	}
44

    
45
	/* (non-Javadoc)
46
	 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
47
	 */
48
	@Override
49
	public int compare(Viewer viewer, Object e1, Object e2) {
50
	  Taxon d1 = (Taxon) e1;
51
	  Taxon d2 = (Taxon) e2;
52

    
53
		int result = 0;
54

    
55
		switch (propertyIndex) {
56

    
57
			default:
58
				result = d1.getTitleCache().compareTo(d2.getTitleCache());
59
		}
60

    
61
		// If descending order, flip the direction
62
		if (direction == DESCENDING) {
63
			result = -result;
64
		}
65
		return result;
66
	}
67
}
(2-2/4)