Progress Service Not Working [message #989868] |
Sat, 08 December 2012 19:37 |
Steve Biggs Messages: 5 Registered: November 2012 |
Junior Member |
|
|
I'm using the progress service and am having a problem with it under certain circumstances. I call the same method from two different places in my application and in one case the progress service displays a dialog as expected and in the other it doesn't. Nothing fails and there's no exceptions, it just never displays the progress dialog.
Here's the method I'm calling that runs an IRunnableWithProgress using the progress service.
public static void loginWithProgress(Shell parent) {
// The login job
IRunnableWithProgress job=new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException {
ApplicationManager.getSessionManager().login(intranetId,password,monitor);
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(job);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
ApplicationManager.getSessionManager().loginCancelled();
}
}
When I call this from a handler it works fine and the progress dialog is displayed after 800 ms (as expected).
public class Connect extends AbstractHandler {
public class Connect extends AbstractHandler {
public Connect() {
}
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
Application.loginWithProgress(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
return null;
}
}
But when I call this same method from the WorkbenchWindowAdvisor.postWindowOpen() method the IRunnableWithProgress will execute successfully but no progress dialog appears.
public class ApplicationWorkbenchWindowAdvisor extends WorkbenchWindowAdvisor {
// A bunch of stuff removed from here for brevity
@Override
public void postWindowOpen() {
// A bunch of stuff removed from here for brevity
Application.loginWithProgress(getWindowConfigurer().getWindow().getShell());
super.postWindowOpen();
}
}
Any suggestions as to why the progress dialog isn't appearing when called in the manner outlined above?
Thanks.
Steve Biggs
|
|
|
Re: Progress Service Not Working [message #989934 is a reply to message #989868] |
Mon, 10 December 2012 07:14 |
|
I'm not sure because it doesn't make sense but still did you tried like this.
@Override
public void postWindowOpen() {
// A bunch of stuff removed from here for brevity
Application.loginWithProgress(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
super.postWindowOpen();
}
And one more thing in your public static void loginWithProgress(Shell parent) what is the use of Shell parent. Are you using it some where.?
[Updated on: Mon, 10 December 2012 07:17] Report message to a moderator
|
|
|
|
Re: Progress Service Not Working [message #992930 is a reply to message #990043] |
Sun, 23 December 2012 02:31 |
Steve Biggs Messages: 5 Registered: November 2012 |
Junior Member |
|
|
In case anyone is experiencing the same issue, I have figured out my problem.
It seems that while the workbench is starting, PlatformUI.getWorkbench().getProgressService() will return an instance of the progress service even though it's not ready to be used yet. According to the documentation for PlatformUI.getWorkbench().isStarting():
Quote:
isStarting
boolean isStarting()
Returns a boolean indicating whether the workbench is in the process of starting. During this phase, it is not safe to make calls to other methods of the workbench, or of objects owned by the workbench. To delay work until after the workbench has been initialized, use IStartup or Display.asyncExec(Runnable).
The code below delays executing the call to run the progress service until the workbench has started, fixing my problem.
Display.getDefault().asyncExec(new Runnable() {
public void run() {
IRunnableWithProgress job=new IRunnableWithProgress() {
public void run(IProgressMonitor monitor) throws InvocationTargetException,InterruptedException {
// Do some work here
}
};
try {
PlatformUI.getWorkbench().getProgressService().busyCursorWhile(job);
} catch (InvocationTargetException e) {
e.printStackTrace();
} catch (InterruptedException e) {
// Job was cancelled
}
}
});
Steve Biggs
|
|
|
Powered by
FUDForum. Page generated in 0.03221 seconds