| Summary: | When a user job runs a UIJob asynchronously MessageDialog#openConfirm closes and return true without user interaction | ||||||
|---|---|---|---|---|---|---|---|
| Product: | [Eclipse Project] Platform | Reporter: | Filipe Borges <fqborges> | ||||
| Component: | UI | Assignee: | Platform-UI-Inbox <Platform-UI-Inbox> | ||||
| Status: | RESOLVED INVALID | QA Contact: | |||||
| Severity: | normal | ||||||
| Priority: | P3 | CC: | remy.suen | ||||
| Version: | 4.1 | ||||||
| Target Milestone: | --- | ||||||
| Hardware: | PC | ||||||
| OS: | Windows XP | ||||||
| Whiteboard: | |||||||
| Attachments: |
|
||||||
|
Description
Filipe Borges
Created attachment 185224 [details]
Code for simpleHandler containing the problem
this is the code I used to reproduce the bug.
This is because your message dialog is parented off of the progress dialog that's showing your first job. Hence, when it gets disposed, your message dialog also gets disposed (as it is a child shell of the progress dialog's shell). You have two options here that I can think of. 1. Specify a small delay while scheduling your UI job. This will allow the dialog to be closed first before your UI job gets run. Then the active shell won't be the progress dialog of your first job. 2. Don't try to get the active shell from the display but instead be more specific about it (such as specifying the shell of the workbench window). (In reply to comment #2) > 2. Don't try to get the active shell from the display but instead be more > specific about it (such as specifying the shell of the workbench window). +1, it would be nice if UIJob provided a bit more intelligent answer, but changing it now will surely break somebody else. Thank you! (In reply to comment #3) > (In reply to comment #2) > > 2. Don't try to get the active shell from the display but instead be more > > specific about it (such as specifying the shell of the workbench window). > > +1, it would be nice if UIJob provided a bit more intelligent answer, but > changing it now will surely break somebody else. One more question: how could I get the shell from workbench window without using internal UIPlugin? There are many ways, some might fit better your needs then others.
One possibility is to get Shell from your handler's event and pass it to the Job that will show up the dialog:
public class SampleHandler ... {
...
public Object execute(ExecutionEvent event) throws ExecutionException {
static Shell shell;
IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindowChecked(event);
// TBD if (window != null); try/catch for ExecutionException
Shell shell = window.getShell();
Job job = getJob(shell);
...
}
====
Another possiblity is to use PlatformUI class:
shell = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
(this needs null checks and possibly #isWorkbenchRunning() check, if in doubt).
|