Bug 170187 - [Viewers] Provide table sorting by clicking on column headers
Summary: [Viewers] Provide table sorting by clicking on column headers
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 3.3   Edit
Hardware: PC Windows XP
: P3 enhancement with 2 votes (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard:
Keywords: api
Depends on:
Blocks:
 
Reported: 2007-01-11 04:51 EST by Mark McLaren CLA
Modified: 2019-09-06 16:13 EDT (History)
4 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Mark McLaren CLA 2007-01-11 04:51:06 EST
A common requirement is to allow the user to sort a table by clicking on the column header.  The JFace viewer framework should provide a standard way to do this.
Comment 1 Krzysztof Daniel CLA 2007-01-11 12:18:59 EST
API Changes proposal:

new parameter boolean sortOnClick in the method <code> Table.setHeaderVisible </code> and new method to the TableViewer: 
<code> void addSorterFactory(ComparatorFactory factory) </code>

the interface ComparatorFactory might look like this
<code>
public interface ComparatorFactory {
    public Comparator createComparator(TableColumn column);
}
</code>

The idea is that slighty modified TableViewer (maybe extended one) listen to the its every TableColumn and, if sorting is activated by user click, sets the right 
Comparator.

It might be good to implement some default ComparatorFactory class that would compare eg. Strings.
Comment 2 Thomas Schindl CLA 2007-01-11 12:26:38 EST
Well if you ask me the new API has to be added to the ViewerColumn (you need to get 3.3M4 to see this class). 

In my think it looks like the following:

TableViewerColumn vcolumn = new TableViewerColumn(tableViewer,SWT.NONE);
vColumn.setEditingSupport(new MyEditingSupport());
vColumn.setLabelProvider(new MyLabelProvider());
vColumn.setComparator(new CustomViewerComparator());
// this automatically sets up all listeners in the background
// no other custom code needed
Comment 3 Krzysztof Daniel CLA 2007-01-12 04:18:30 EST
Tom, you are approach is better.

Change of ViewerColumn in a way you proposed is a nice idea but it requires some more investigation, because it will affects two classes: TableViewerColumn and TreeViewerColumn. Both classes contain field column, but it has two different types, but each type has method addSelectionListener which is interesting to us.

I propose extract interface or (maybe even supertype) Column from TreeColumn and TableColumn and then pull up field column (of type Column) from TableViewerColumn and TreeViewerColumn to ViewerColumn.
Comment 4 Krzysztof Daniel CLA 2007-01-12 04:39:27 EST
It seems to me that this bug is duplicates 
https://bugs.eclipse.org/bugs/show_bug.cgi?id=166153
Comment 5 Thomas Schindl CLA 2007-01-12 04:44:18 EST
ok I are my 2¢ your approach has to done on the SWT-Level which might not happen although there's a feature request for this but I can't remember nevertheless I want to stay open for all implementation not only for SWT-Tree/Table (we opened the API in 3.3 for other widget implementors) so the concept has to be different:

1. ViewerColumn remembers the widget it is created upon this way it can register 
   event listening using Widget#addListener(...)

2. ViewerColumn gets the following abstract methods:
   - doActivateSort()
   - doDeactivateSort()
Comment 6 Thomas Schindl CLA 2007-01-12 04:44:59 EST
I knew that where already a request for this ;-)
Comment 7 Krzysztof Daniel CLA 2007-01-12 05:27:40 EST
(In reply to comment #5)

Is (de)activation necessary? Maybe passing Comparator should activate, and passing null deactivate?
Comment 8 Thomas Schindl CLA 2007-01-12 05:56:01 EST
(In reply to comment #7)
> (In reply to comment #5)
> 
> Is (de)activation necessary? Maybe passing Comparator should activate, and
> passing null deactivate?
> 

you are right so we have:
- ViewerColumn#setSorter(ViewerColumnComparator) 
  => adds listener and restore the  comparator for later usage
- ViewerColumn#setSorter()
- ViewerColumn#activate() 
  => allow programmatic activation of sorter
- ViewerColumn#deactivate()
  => allow deactivation of sorter
- abstract ViewerColumn#doActivateComparator(ViewerColumnComparator) 
  => real activation
- abstract boolean isSortColumn()
  => needed to check if the current column is a sort column

A new class ViewerColumnComparator:
- ViewerColumnComparator#is2waySort()
  => does the second click sort in the other direction
- ViewerColumnComparator#getPrimarySortType()
  => returns SWT.UP or SWT.DOWN by default SWT.DOWN
- ViewerColumnComparator#cycle()
  => this is used to check if the 3 third click triggers:
     - removing of sorter
     - starting from the begining => getPrimarySortType()

There's a bit more because I also want to support multiple sort columns at once ;-) I think I need to give it a shot when other things are done. 
Comment 9 Daniel Krügler CLA 2008-11-21 06:46:27 EST
(In reply to comment #8)
> A new class ViewerColumnComparator:
> - ViewerColumnComparator#is2waySort()
>   => does the second click sort in the other direction

Do I correctly understand that if is2waySort() returns false this is supposed to effectly behave like three states asc, desc, and none (original sort order). Such kind of triple-state sort order is a case which is often required by customers.

> - ViewerColumnComparator#getPrimarySortType()
>   => returns SWT.UP or SWT.DOWN by default SWT.DOWN
> - ViewerColumnComparator#cycle()
>   => this is used to check if the 3 third click triggers:
>      - removing of sorter
>      - starting from the begining => getPrimarySortType()
> 
> There's a bit more because I also want to support multiple sort columns at once
> ;-) I think I need to give it a shot when other things are done. 

I would strong appreciate the possibility of multiple-column sorting. I wonder in which way you would visualize the column sort order image?

Comment 10 Boris Bokowski CLA 2009-11-26 09:49:53 EST
Hitesh is now responsible for watching bugs in the [Viewers] component area.
Comment 11 Eclipse Webmaster CLA 2019-09-06 16:13:17 EDT
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.