// make sure that similiar job isn't already running
Job[] jobs = Job.getJobManager().find(
CardImageLoaderJob.FAMILY_CARDIMAGELOADER_JOB);
for (Job element : jobs) {
CardImageLoaderJob cjob = (CardImageLoaderJob) element;
if (cjob.getCard() == adapter)
return;
}
// start thejob
Job job = new CardImageLoaderJob(adapter);
// update view when job get's done
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if (event.getResult().isOK()) {
CardImageLoaderJob job = (CardImageLoaderJob) event.getJob();
if (adapter == job.getCard()) {
Display.getDefault().asyncExec(new Runnable() {
public void run() {
updateImage(adapter.getImage(), adapter.getBorder());
}
});
}
} else if (event.getResult().getCode() == IStatus.ERROR) {
// finished with error, do we have to prevent
// further jobs from spawning?
doCardImageLoad = false;
}
}
});
job.schedule(); // start as soon as possible
}
}
}