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