Java tutorial
/******************************************************************************* * Copyright (c) 2011 Softberries Krzysztof Grajek. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Softberries Krzysztof Grajek - initial API and implementation ******************************************************************************/ package com.softberries.klerk.gui.helpers.table; import org.eclipse.jface.viewers.ViewerComparator; import org.eclipse.swt.SWT; public abstract class SimpleKlerkComparator extends ViewerComparator { protected int propertyIndex; protected static final int DESCENDING = 1; protected int direction = DESCENDING; public SimpleKlerkComparator() { this.propertyIndex = 0; direction = DESCENDING; } public int getDirection() { return direction == 1 ? SWT.DOWN : SWT.UP; } public void setColumn(int column) { if (column == this.propertyIndex) { // Same column as last sort; toggle the direction direction = 1 - direction; } else { // New column; do an ascending sort this.propertyIndex = column; direction = DESCENDING; } } }