Eclipse JFace Table - Tutorial / 10. Show/Hide Columns -> a mistake

517 views
Skip to first unread message

tru

unread,
Sep 22, 2010, 1:11:56 PM9/22/10
to vogella
Hi, man!

It seems I have found a mistake in your code (just check it).
Here it is: http://www.vogella.de/articles/EclipseJFaceTable/article.html

public class View extends ViewPart {
//...
private void createColumns(final Composite parent, final TableViewer
viewer) {
//...
tableSorter.setColumn(index);
int dir = viewer.getTable().getSortDirection();
if (viewer.getTable().getSortColumn() == column) {
dir = dir == SWT.UP ? SWT.DOWN : SWT.UP;
} else {
dir = SWT.DOWN;
}
viewer.getTable().setSortDirection(dir);
//..
}
}

This is an example of poor design, as you have already changed the
direction right inside the sorter class. That is why it works
incorrectly.
Instead of the above I have written a public function in the sorter
class:
public int getDirection(){
return direction== 1 ? SWT.DOWN : SWT.UP;
}
Now the code is more clear (and hopefully works, arrow shows the
correct direction of the sort):

tableSorter.setColumn(index);
int dir = tableSorter.getDirection();
viewer.getTable().setSortDirection(dir);

Anyway thank you for the Tutorial!

tru

unread,
Sep 22, 2010, 1:12:19 PM9/22/10
to vogella

Lars Vogel

unread,
Jun 25, 2011, 6:13:00 PM6/25/11
to vog...@googlegroups.com
Hi,

sorry for the late reply. Thanks for the suggestion. JFace Tutorial is updated: http://www.vogella.de/articles/EclipseJFaceTable/article.html

Best regards, Lars

2010/9/22 tru <achern...@gmail.com>

--
You received this message because you are subscribed to the Google Groups "vogella" group.
To post to this group, send email to vog...@googlegroups.com.
To unsubscribe from this group, send email to vogella+u...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/vogella?hl=en.




--
Lars
http://www.vogella.de - Tutorials about Java, Eclipse and Web programming
http://www.twitter.com/vogella - Lars on Twitter
Reply all
Reply to author
Forward
0 new messages