Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsGridTableViewer and sorting
https://www.eclipse.org/forums/index.php/mv/msg/19601/62890/#msg_62890
How do I sort a Grid when using a GridTableViewer? I tried it using a
ColumnViewerSorter, but that doesn't seem to work. Furthermore, Grid
doesn't seem to have API like setSortColumn() or setSortDirection().
Any help is highly appreciated.
Thanks,
Christian]]>Christian Hauser2009-02-24T10:32:42-00:00Re: GridTableViewer and sorting
https://www.eclipse.org/forums/index.php/mv/msg/19601/593805/#msg_593805
> Hi all
>
> How do I sort a Grid when using a GridTableViewer? I tried it using a
> ColumnViewerSorter, but that doesn't seem to work. Furthermore, Grid
> doesn't seem to have API like setSortColumn() or setSortDirection().
ColumnViewerSorter is a ViewerComparator. However, I can only set a
ViewerComparator to the GridTableViewer, not to its columns. How is this
supposed to be used?
I'm still confused and would be very happy for any hint.
Christian]]>Christian Hauser2009-02-24T11:34:07-00:00Re: GridTableViewer and sorting
https://www.eclipse.org/forums/index.php/mv/msg/19601/62892/#msg_62892
> Hi all
>
> How do I sort a Grid when using a GridTableViewer? I tried it using a
> ColumnViewerSorter, but that doesn't seem to work. Furthermore, Grid
> doesn't seem to have API like setSortColumn() or setSortDirection().
ColumnViewerSorter is a ViewerComparator. However, I can only set a
ViewerComparator to the GridTableViewer, not to its columns. How is this
supposed to be used?
I'm still confused and would be very happy for any hint.
Christian]]>Christian Hauser2009-02-24T11:34:07-00:00Re: GridTableViewer and sorting
https://www.eclipse.org/forums/index.php/mv/msg/19601/593817/#msg_593817
I managed to get my Grid to sort the columns. I had a problem in my code.
This is the way I'm doing the sorting now:
For each column I add a new ColumnViewerSorter:
new ColumnViewerSorter(myGridTableViewer, myGridViewerColumn) {
@Override
protected int doCompare (Viewer viewer, Object e1, Object e2) {
// compare the two items e1 and e2
}
};
And this is the implementation of ColumnViewerSorter:
public abstract class ColumnViewerSorter extends ViewerComparator {
public static final int ASC= 1;
public static final int NONE= 0;
public static final int DESC= -1;
private int direction= 0;
private final GridViewerColumn column;
private final ColumnViewer viewer;
public ColumnViewerSorter (ColumnViewer viewer, GridViewerColumn
column) {
this.viewer= viewer;
this.column= column;
this.column.getColumn().addSelectionListener(new
SelectionAdapter() {
@Override
public void widgetSelected (SelectionEvent e) {
if (ColumnViewerSorter.this.viewer.getComparator() !=
null) {
if (ColumnViewerSorter.this.viewer.getComparator()
== ColumnViewerSorter.this) {
int tdirection= ColumnViewerSorter.this.direction;
@Override
public int compare (Viewer viewer, Object e1, Object e2) {
return direction * doCompare(viewer, e1, e2);
}
protected abstract int doCompare (Viewer viewer, Object e1, Object e2);
}]]>Christian Hauser2009-02-24T11:47:52-00:00Re: GridTableViewer and sorting
https://www.eclipse.org/forums/index.php/mv/msg/19601/62894/#msg_62894
I managed to get my Grid to sort the columns. I had a problem in my code.
This is the way I'm doing the sorting now:
For each column I add a new ColumnViewerSorter:
new ColumnViewerSorter(myGridTableViewer, myGridViewerColumn) {
@Override
protected int doCompare (Viewer viewer, Object e1, Object e2) {
// compare the two items e1 and e2
}
};
And this is the implementation of ColumnViewerSorter:
public abstract class ColumnViewerSorter extends ViewerComparator {
public static final int ASC= 1;
public static final int NONE= 0;
public static final int DESC= -1;
private int direction= 0;
private final GridViewerColumn column;
private final ColumnViewer viewer;
public ColumnViewerSorter (ColumnViewer viewer, GridViewerColumn
column) {
this.viewer= viewer;
this.column= column;
this.column.getColumn().addSelectionListener(new
SelectionAdapter() {
@Override
public void widgetSelected (SelectionEvent e) {
if (ColumnViewerSorter.this.viewer.getComparator() !=
null) {
if (ColumnViewerSorter.this.viewer.getComparator()
== ColumnViewerSorter.this) {
int tdirection= ColumnViewerSorter.this.direction;