I am working on an eclipse RCP application.
I have a ScalableLayeredPane
on which I have around 800 figures.
I need to change the zoom value by using setScale()
method.
Also I want to display progress of the zooming using Job.
I am using asyncexec
method to call setScale()
function. However, my GUI is starving and I can not click on the cancel button also.
Any help on this will be appreciated.
Here is what I am doing.
Job job = new Job("Some job") {
@Override
protected IStatus run(IProgressMonitor monitor) {
// Decide scaling amount
PlatformUI.getWorkbench().getDisplay().asyncExec(new Runnable() {
@Override
public void run() {
scalableLayeredPaneObj.setScale(scale); }
});
// Check if cancel is pressed and return status accordingly
if(monitor.isCanceled()) {
return Status.CANCEL_STATUS;
}
return Status.OK_STATUS;
}
};
job.addJobChangeListener(new JobChangeAdapter() {
@Override
public void done(IJobChangeEvent event) {
if(event.getResult().isOK()) {
System.out.println("Job done!");
// Do something
} else {
System.out.println("Job cancelled!");
// Do something else
}
}
});
job.setUser(true);
job.schedule();
However, when this particular code is run, GUI becomes unresponsive and cancel button can not be pressed. I am always getting "Job done!"
message.
I have also tried using PlatformUI#getWorkbench()#getDisplay()#syncExec
method for running UI thread. That didn't work.
What my analysis suggests is setScale
operation itself taking a long time thus making GUI unresponsive. I need to call setScale
from another thread(if possible) so that Main
thread will not hang up.
Issue is related to
setScale()
method only. Due to large canvas size,setScale()
is taking a long time in UI thread.Basically
Job
is used to perform non-UI activities in backend. For UI activities,busy indicator
is suitable. However, since I wanted to cancel the scaling task, I was using user Job. Issue can be resolved using busy indicator instead and thus no cancel action could be provided.