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 01:58 Go to next message
Maik Michel is currently offline Maik Michel
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 09:28 Go to previous message
Christoph Keimel is currently offline Christoph Keimel
Messages: 335
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:org.eclipse.ui.PartInitException
Next Topic:JFace TableViewer/Table setitemcount() slow
Goto Forum:
  


Current Time: Thu Jul 31 15:42:47 EDT 2014

Powered by FUDForum. Page generated in 0.12693 seconds