]>
git.argeo.org Git - lgpl/argeo-commons.git/blob - base/runtime/org.argeo.eclipse.ui/src/main/java/org/argeo/eclipse/ui/GenericTableComparator.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.eclipse
.ui
;
18 import org
.eclipse
.jface
.viewers
.Viewer
;
19 import org
.eclipse
.jface
.viewers
.ViewerComparator
;
21 public abstract class GenericTableComparator
extends ViewerComparator
{
22 private static final long serialVersionUID
= -1175894935075325810L;
23 protected int propertyIndex
;
24 public static final int ASCENDING
= 0, DESCENDING
= 1;
25 protected int direction
= DESCENDING
;
28 * Creates an instance of a sorter for TableViewer.
30 * @param defaultColumn
31 * the default sorter column
34 public GenericTableComparator(int defaultColumnIndex
, int direction
) {
35 propertyIndex
= defaultColumnIndex
;
36 this.direction
= direction
;
39 public void setColumn(int column
) {
40 if (column
== this.propertyIndex
) {
41 // Same column as last sort; toggle the direction
42 direction
= 1 - direction
;
44 // New column; do a descending sort
45 this.propertyIndex
= column
;
46 direction
= DESCENDING
;
51 * Must be Overriden in each view.
53 public abstract int compare(Viewer viewer
, Object e1
, Object e2
);