Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Standard Widget Toolkit (SWT) » Update TableViewer with event from a Job
Update TableViewer with event from a Job [message #892398] Thu, 28 June 2012 06:26 Go to next message
Mikael Petterson is currently offline Mikael PettersonFriend
Messages: 158
Registered: July 2009
Senior Member
Hi,

I have a TableViewer containing a list of jobs:

Name State

JobA Not started

When I select a Job it will be started and executed with something like:

final Job job = new Job("JobA") {
protected IStatus run(IProgressMonitor monitor) {
try {
while(hasMoreWorkToDo()) {
// do some work
// ...
if (monitor.isCanceled()) return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
} finally {
schedule(60000); // start again in an hour
}
}
};

Then I have added a job change listener so that I know if job was executed successfully ( no interrupt). If it was successful I want to update the "State"
of the Job.

job.addJobChangeListener(new JobChangeAdapter() {
public void done(IJobChangeEvent event) {
if (event.getResult().isOK())
postMessage("Job completed successfully");
//Send event possible to update data used in table viewer.
else
postError("Job did not complete successfully");
}
});

I have a Job object for each row in the table. Name is unique.

Is there any specific support for eclipse for handling events or should I use the
regular java java.util.EventObject and add my own listener on the Job object?


br,

//mike
Re: Update TableViewer with event from a Job [message #892419 is a reply to message #892398] Thu, 28 June 2012 07:56 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Hi,

you can implement all methods from the IJobChangeListener and call tableViewer.update(event.getJob(), null).
Your label provider then ask the Job for its state and update the label in the table accordingly.
Re: Update TableViewer with event from a Job [message #892429 is a reply to message #892419] Thu, 28 June 2012 08:15 Go to previous messageGo to next message
Mikael Petterson is currently offline Mikael PettersonFriend
Messages: 158
Registered: July 2009
Senior Member
Thanks for reply Jan.

So I need to implement IJobChangeListener for my Viewer class to receive calls when Jobs change state?

//mike

Re: Update TableViewer with event from a Job [message #892438 is a reply to message #892398] Thu, 28 June 2012 08:35 Go to previous messageGo to next message
Jan Krakora is currently offline Jan KrakoraFriend
Messages: 477
Registered: December 2009
Location: Prague
Senior Member
Mikael Petterson wrote on Thu, 28 June 2012 08:26

Then I have added a job change listener so that I know if job was executed successfully ( no interrupt). If it was successful I want to update the "State"
of the Job.

job.addJobChangeListener(new JobChangeAdapter() {
public void done(IJobChangeEvent event) {
if (event.getResult().isOK())
postMessage("Job completed successfully");
//Send event possible to update data used in table viewer.
else
postError("Job did not complete successfully");
}
});


You already did that doesn't you? I would just implement all other methods and call tableViewer.update(event.getJob(), null) from them, including the done().
Re: Update TableViewer with event from a Job [message #892468 is a reply to message #892438] Thu, 28 June 2012 10:35 Go to previous message
Mikael Petterson is currently offline Mikael PettersonFriend
Messages: 158
Registered: July 2009
Senior Member
Sorry I misunderstood. But now it is clear Smile

Thanks!

//mike
Previous Topic:SWT Table - Performance
Next Topic:Thread deadlock when call to org.eclipse.swt.ole.win32.OleClientSite.doVerb is made
Goto Forum:
  


Current Time: Thu Apr 25 09:56:12 GMT 2024

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

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

Back to the top