Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
Copyright (c) 2009 IBM Corporation and others. 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: IBM Corporation - initial API and implementation /
 
 package org.eclipse.ant.internal.ui;
 
 import  org.eclipse.swt.SWT;
 import  org.eclipse.swt.events.SelectionAdapter;
 import  org.eclipse.swt.events.SelectionEvent;
 import  org.eclipse.swt.widgets.TableColumn;

A sorter that can be attached to a given column in a given viewer. This comparator uses the AntObjectLabelProvider to get the text to compare

Since:
3.5
 
 public abstract class ColumnSorter extends ViewerComparator {
 	
 	private ColumnViewer cviewer = null;
 	private TableColumn column = null;
 	private int direction = SWT.DOWN;
 	private int columnidx = 0;

Constructor

Parameters:
cviewer
column
 
 	public ColumnSorter(ColumnViewer cviewer, TableColumn column) {
 		this. = cviewer;
 		this. = column;
 		this..addSelectionListener(new SelectionAdapter() {
 			public void widgetSelected(SelectionEvent e) {
 					setDirection(SWT.DOWN);
 				}
 				else {
 					int tdirection = ColumnSorter.this..getParent().getSortDirection();
 					if(tdirection == SWT.NONE) {
 						setDirection(SWT.DOWN);
 					}
 					else {
 						setDirection(tdirection == SWT.UP ? SWT.DOWN : SWT.UP);
 					}
 				}
 			}
 		});
 
 	}

Returns the compare text that should be used for the given object coming from the given column index

Parameters:
obj
columnindex
Returns:
the text to compare with
 
 	public abstract String getCompareText(Object objint columnindex);

Sets the sorting direction for this sorter to use

Parameters:
direction
 
 	public void setDirection(int direction) {
 		this..getParent().setSortColumn(this.);
 		this. = direction;
 		this..getParent().setSortDirection(this.);
 		if(this..getComparator() == this) {
 			this..refresh();
 		}
 		else {
 			this..setComparator(this);
 		}
 	}

See also:
org.eclipse.jface.viewers.ViewerComparator.compare(org.eclipse.jface.viewers.Viewer, java.lang.Object, java.lang.Object)
 
 	public int compare(Viewer viewerObject e1Object e2) {
 		String text1 = getCompareText(e1this.);
 		if(text1 == null) {
 			text1 = ""//$NON-NLS-1$
 		}
 		String text2 = getCompareText(e2this.);
 		if(text2 == null) {
 			text2 = ""//$NON-NLS-1$
		}
		return (this. == SWT.UP ? -1 : 1) * 
			text1.compareTo(text2);
	}

Returns the index of the given column in the backing table for this page, or 0

Returns:
the index of the column in the backing table for this page or 0
	private int getColumnIndex() {
		int idx = this..getParent().indexOf(this.);
		return (idx < 0 ? 0 : idx);
	}
New to GrepCode? Check out our FAQ X