]> git.argeo.org Git - lgpl/argeo-commons.git/blob - org.argeo.eclipse.ui/src/org/argeo/eclipse/ui/GenericTableComparator.java
Merge branch 'master' of https://mbaudier@code.argeo.org/git/lgpl/argeo-commons.git
[lgpl/argeo-commons.git] / org.argeo.eclipse.ui / src / org / argeo / eclipse / ui / GenericTableComparator.java
1 package org.argeo.eclipse.ui;
2
3 import org.eclipse.jface.viewers.Viewer;
4 import org.eclipse.jface.viewers.ViewerComparator;
5
6 public abstract class GenericTableComparator extends ViewerComparator {
7 private static final long serialVersionUID = -1175894935075325810L;
8 protected int propertyIndex;
9 public static final int ASCENDING = 0, DESCENDING = 1;
10 protected int direction = DESCENDING;
11
12 /**
13 * Creates an instance of a sorter for TableViewer.
14 *
15 * @param defaultColumnIndex
16 * the default sorter column
17 */
18
19 public GenericTableComparator(int defaultColumnIndex, int direction) {
20 propertyIndex = defaultColumnIndex;
21 this.direction = direction;
22 }
23
24 public void setColumn(int column) {
25 if (column == this.propertyIndex) {
26 // Same column as last sort; toggle the direction
27 direction = 1 - direction;
28 } else {
29 // New column; do a descending sort
30 this.propertyIndex = column;
31 direction = DESCENDING;
32 }
33 }
34
35 /**
36 * Must be Overriden in each view.
37 */
38 public abstract int compare(Viewer viewer, Object e1, Object e2);
39 }