How to close Jface wizard while progress bar is running for a long time [message #335336] |
Thu, 02 April 2009 10:14  |
Eclipse User |
|
|
|
Hi
How to close the Jface wizard while progress bar is running doing a job
for a longer time.Since fewer times call to database is taking time i want
to close the Jface wizard but i am getting the following message
"wizard can not be closed due to an active operation. you must cancel the
operation before you can close the wizard".
How to cancel the operation from the UI.
Regards
NAAG
|
|
|
|
|
Re: How to close Jface wizard while progress bar is running for a long time [message #335348 is a reply to message #335347] |
Fri, 03 April 2009 06:23   |
Eclipse User |
|
|
|
Naag wrote:
> Hi prakash
>
> I have set the cancelled flag as true. I couldnt see any cancel image
> enabled next to progressbar.
>
> I am using a long run operation in wizard page. getContainer().run method
>
>
> //Sample code
> getContainer().run(true, true, new IRunnableWithProgress() {
This is correct. By providing cancelable=true, the Cancel Button will be
enabled while the operation is running.
> public void run(IProgressMonitor monitor) throws
> InvocationTargetException, InterruptedException {
> monitor.begintask("");
> //SDK and DB calls to fill the data to UI
Here, you have to check monitor.isCanceled() after each call and throw
an InteruptedException when it is true. See the JavaDoc of
IRunnableWithProgress.
>
> monitor.done();
> }
>
> what should i do now? please help me out
You have to catch the InteruptedException and close the wizard with
getShell().close().
This is a little bit ugly, as you make an assumption that the shell is
owned by the WizardDialog. In fact, a Wizard could be run by a container
that is no WizardDialog. For example, it could be run embedded in the
workbench window. Calling shell.close() here would have another meaning.
Anyway, WizardDialog is the only container I was using so far, and
AFAICS shell.close() is the only way of closing the wizard programmatically
>
> Thanks for the eclipse tips site
> NAAG
>
Regards, Sebastian
|
|
|
|
Re: How to close Jface wizard while progress bar is running for a long time [message #335351 is a reply to message #335349] |
Fri, 03 April 2009 07:42  |
Eclipse User |
|
|
|
Naag wrote:
> Thanks for the reply. When i make the isCancelled flag as true there
> is no cancel button enabled.
>
No, this is not what I said. You called getContainer().run(true, true,
new IRunnableWithProgress() {...} ). By providing true for the first two
arguments, the operation is cancelable and does not run on the UI thread
(in other words: the UI still responds while the op is running).
This alone should make your cancel button enabled, what means it can
actually be pressed. When the button is pressed by the user, the
IProgressMonitor.isCanceled() becomes true. Your Runnable should poll
this between method calls and break when it becomes true. The break can
be implemented by just throwing an InteruptedException.
Sebastian
|
|
|
Powered by
FUDForum. Page generated in 0.08254 seconds