Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.

Bug 172321

Summary: [Commands] [GTK] Handler activation in editor when a dialog is closed is delayed
Product: [Eclipse Project] Platform Reporter: Jean-Michel Lemieux <jean-michel_lemieux>
Component: UIAssignee: Paul Webster <pwebster>
Status: VERIFIED FIXED QA Contact:
Severity: normal    
Priority: P3    
Version: 3.3   
Target Milestone: 3.4 M6   
Hardware: PC   
OS: Linux   
Whiteboard:
Bug Depends on: 173213    
Bug Blocks:    

Description Jean-Michel Lemieux CLA 2007-01-31 10:06:59 EST
Here is a test case which fails on Linux:

Setup: This code is run within an editor. When the editor is created, it registers a command handler. Within the widget selected event, a dialog is shown and when closed the command is invoked but the command handler isn't found.

But delaying the command invocation until some time has passed will succeed because the command handler has been reset since the shell disposed event has had time to be processed.

autoMergeButton.addSelectionListener(new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
                IPreferenceStore store = UiPlugin.getDefault().getPreferenceStore();
                boolean prompt = true; //MessageDialogWithToggle.PROMPT.equals(store.getString(UiPlugin.AUTO_MERGE_CONTENT_PROMPT));
                if(prompt) {
                    MessageDialogWithToggle dialog = MessageDialogWithToggle.openOkCancelConfirm(autoMergeButton.getShell(), 
                        "Auto-merge", 
                        "This will merge all non-conflicting changes in this file. It's possible that the file type being " +
                        "merged doesn't support this kind of operation, in which case you'll have to merge the file manually. Also, if the " +
                        "file has already been merged, this action will not change the file. After the auto-merge the file still " +
                        "needs to be saved. \n\n" +
                        "Do you want to continue?",
                        "Do not ask again", 
                        false, 
                        store, 
                        UiPlugin.AUTO_MERGE_CONTENT_PROMPT);
                
                    if(dialog.getReturnCode() != IDialogConstants.OK_ID)
                        return;
                }
                UIJob job = new UIJob(shell.getDisplay(), "Merging") {
                    @Override
                    public IStatus runInUIThread(IProgressMonitor monitor) {
                        mergeRightToLeft(parent.getShell());
                        return Status.OK_STATUS;
                    }
                
                };
                job.schedule(150);
            }
        });
Comment 1 Paul Webster CLA 2007-03-28 09:32:22 EDT
JM, bug 173213 is investigation a fix for this condition (running a workbench window command from a dialog).

If accepted, the fix basically involves registering the dialog shell to allow the active workbench window to continue to work.  ex:

dialog.create();
getContextService().registerShell(dialog.getShell(),
	IContextService.TYPE_DIALOG_SUPPORTS_WORKBENCH);
// Check result of dialog
if (dialog.open() == Window.OK) {

Then the command would work without the need to resort to a UI job.
PW
Comment 2 Paul Webster CLA 2007-06-26 10:28:58 EDT
This ended up being a complex problem.  In 3.3 we're experimenting with using a snapshot of the context to execute a command.

If this solution proves out, in 3.4 we'll work on making this API

PW
Comment 3 Paul Webster CLA 2008-02-27 15:34:02 EST
As per bug 183810 there is now API available to execute a command in a different context (where being in a dialog is definitely a different context).

ex: 
IEvaluationContext windowContext = handlerService.createContextSnapshot(true);
MyDialog d = ...;
d.setContext(windowContext);
d.open();

In MyDialog when executing, create the appropriate ParameterizedCommand and:

handlerService.executeCommandInContext(pCommand, null, windowContext);

PW
Comment 4 Paul Webster CLA 2008-03-24 14:07:50 EDT
fixed by bug 183810 
Comment 5 Paul Webster CLA 2008-03-25 10:44:06 EDT
In I20080325-0100