Skip to main content



      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 02:26 Go to next message
Eclipse UserFriend
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 03:56 Go to previous messageGo to next message
Eclipse UserFriend
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 04:15 Go to previous messageGo to next message
Eclipse UserFriend
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 04:35 Go to previous messageGo to next message
Eclipse UserFriend
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 06:35 Go to previous message
Eclipse UserFriend
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: Sat Jul 05 14:14:40 EDT 2025

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

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

Back to the top