amuck
amuck
amuck
amuck

Java

Covers all my Java Projects

Updating and Refreshing a TableViewer in Eclipse RCP from Another Thread

July 19, 2010
By

This post has 182 words. It will take approximately 1 minute, 49 secondes for reading it.

I’m going to post this here mostly for my own memory. I’m guessing it is actually described somewhere but I had to have the help of a colleague to get this to work.

Problem:

I have a thread that is displayed in a TableViewer in my Eclipse RCP application. This thread has a status and will change its status as necessary and I want the status to be displayed in the TableViewer, however I keep getting an Illegal Thread Access Exception when I perform the TableViewer.refresh() or TableViewer.update(Object, String[]) calls.

The Fix:

The proper way to fix this is in your own update or refresh function to create a local “Runnable” class that will perform the update. Here’s some code to show you what I mean:

@Override
public void update(Object o)
{
     // This will update a specific object in the TableViewer without reloading the entire model.
     Display.getDefault().asyncExec(new Runnable() {
                @Override
                 public void run()
                 {
                        MyClass.this.viewer.update(o, null);
                 }
     });
}

There are some more parts to this to prevent errors but this is the basics.

Search

Important Pages

Calendar

February 2012
M T W T F S S
« Oct    
 12345
6789101112
13141516171819
20212223242526
272829