2 * Copyright (C) 2007 EDIT
3 * European Distributed Institute of Taxonomy
4 * http://www.e-taxonomy.eu
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.
10 package eu
.etaxonomy
.taxeditor
.editor
.view
.checklist
;
12 import org
.eclipse
.jface
.viewers
.Viewer
;
13 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
15 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
22 public class ChecklistEditorComparator
extends ViewerComparator
{
24 private int propertyIndex
;
25 private static final int ASCENDING
= 0;
26 private static final int DESCENDING
= 1;
27 private int direction
= ASCENDING
;
29 public ChecklistEditorComparator() {
30 this.propertyIndex
= 1;
31 direction
= ASCENDING
;
34 public void setColumn(int column
) {
35 if (column
== this.propertyIndex
) {
36 // Same column as last sort; toggle the direction
37 direction
= 1 - direction
;
39 // New column; do an ascending sort
40 this.propertyIndex
= column
;
41 direction
= DESCENDING
;
46 * @see org.eclipse.jface.viewers.ViewerComparator#compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
49 public int compare(Viewer viewer
, Object e1
, Object e2
) {
50 Taxon d1
= (Taxon
) e1
;
51 Taxon d2
= (Taxon
) e2
;
55 switch (propertyIndex
) {
58 result
= d1
.getTitleCache().compareTo(d2
.getTitleCache());
61 // If descending order, flip the direction
62 if (direction
== DESCENDING
) {