Community
Participate
Working Groups
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.
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.
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
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.
It seems to me that this bug is duplicates https://bugs.eclipse.org/bugs/show_bug.cgi?id=166153
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()
I knew that where already a request for this ;-)
(In reply to comment #5) Is (de)activation necessary? Maybe passing Comparator should activate, and passing null deactivate?
(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.
(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?
Hitesh is now responsible for watching bugs in the [Viewers] component area.
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.