Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » JFace » JFace TableViewer sorting in another thread
JFace TableViewer sorting in another thread [message #986597] Wed, 21 November 2012 06:58 Go to next message
Maik Michel is currently offline Maik MichelFriend
Messages: 1
Registered: November 2012
Junior Member
I have a JFaceTableViewer with many rows. These rows I have previously fetched by using JPA. I have put the fetching in another thread to show a progress while fetching and it works.

Now I have put an SelectionAdapter on each of the columns to allow sorting on that column. Here is the code:
private SelectionAdapter getSelectionAdapter(final TableColumn column, final String colName) {
    SelectionAdapter selectionAdapter = new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            comparator.setColumnName(colName);
            int dir = comparator.getDirection();
            resultTableViewer.getTable().setSortDirection(dir);
            resultTableViewer.getTable().setSortColumn(column);
            resultTableViewer.refresh();                
          }
        };
        return selectionAdapter;
      }


How can I execute these lines for sorting in another thread to show a progressbar? Everytime I try to call methods on resultTableViewer I got the exception: InvalidThreadAccess

Any ideas???
Re: JFace TableViewer sorting in another thread [message #986749 is a reply to message #986597] Wed, 21 November 2012 14:28 Go to previous message
Christoph Keimel is currently offline Christoph KeimelFriend
Messages: 482
Registered: December 2010
Location: Germany
Senior Member
Hi Maik

I think you need to execute the code on the UI thread through Display.asyncExec. I.e. something like this:
Runnable runnable = new Runnable() {
	@Override
	public void run() {
		resultTableViewer.getTable().getDisplay().asyncExec(new Runnable() {
			@Override
			public void run() {
				comparator.setColumnName(colName);
				int dir = comparator.getDirection();
				resultTableViewer.getTable().setSortDirection(dir);
				resultTableViewer.getTable().setSortColumn(column);
				resultTableViewer.refresh();
			}
		});
	}
};
new Thread(runnable).start();


Hope that helps!
Christoph
Previous Topic:trying to show File Diff in a TrayDialog
Next Topic:JFace TableViewer/Table setitemcount() slow
Goto Forum:
  


Current Time: Thu Mar 28 09:42:35 GMT 2024

Powered by FUDForum. Page generated in 0.02845 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top