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

Bug 154112

Summary: [ViewMgmt] partActivated on PartListener called before completion of part activation
Product: [Eclipse Project] Platform Reporter: Alex Sanielevici <alexsani>
Component: UIAssignee: Boris Bokowski <bokowski>
Status: RESOLVED WONTFIX QA Contact:
Severity: normal    
Priority: P3 CC: daniel_megert, Nick.Chiu, pwebster
Version: 3.2   
Target Milestone: ---   
Hardware: PC   
OS: Windows XP   
Whiteboard:

Description Alex Sanielevici CLA 2006-08-16 13:53:05 EDT
According to the IPartListener2 javadoc, partActivated is called *after* the referenced part is activated:

    /**
     * Notifies this listener that the given part has been activated.
     *
     * @param partRef the part that was activated
     * @see IWorkbenchPage#activate
     */
    public void partActivated(IWorkbenchPartReference partRef);

However:

WorkbenchPage.class line 3190 triggers PartList.setActivePart() which calls fireActivePartChanged *before* partBeingActivated is set to null in the finally block:
            partList.setActivePart(partref);
        } finally {
            partBeingActivated = null;

Since partBeingActivated is not null when the part listener's partActivated() is called, the activation of a different part from the partActivated() results in the following:

java.lang.RuntimeException: WARNING: Prevented recursive attempt to activate part org.eclipse.ui.DefaultTextEditor while still in the middle of activating part org.eclipse.ui.DefaultTextEditor
Comment 1 Nick Chiu CLA 2009-09-15 00:19:36 EDT
I'm having the same problem, using eclipse 3.4.0, any updates on this issue?
Comment 2 Boris Bokowski CLA 2009-09-21 14:42:38 EDT
(In reply to comment #0)
> Since partBeingActivated is not null when the part listener's partActivated()
> is called, the activation of a different part from the partActivated() results
> in the following:
> 
> java.lang.RuntimeException: WARNING: Prevented recursive attempt to activate
> part org.eclipse.ui.DefaultTextEditor while still in the middle of activating
> part org.eclipse.ui.DefaultTextEditor

It is too late to change this. I am not sure if I agree with your assessment in comment 0, but even if I did, I don't think I would be able to change this behaviour in 3.x.

You seem to be fighting what the user tried to do, why do you need to activate a part instead of the one that is originally being activated?

If you really need to do this, the workaround is to post an asyncExec to activate a different part.
Comment 3 Nick Chiu CLA 2009-09-21 15:16:41 EDT
(In reply to comment #2)

> You seem to be fighting what the user tried to do, why do you need to activate
> a part instead of the one that is originally being activated?
> If you really need to do this, the workaround is to post an asyncExec to
> activate a different part.

When i'm having the exception, the partActivated is called by the eclipse framework, any other workarounds without modifying eclipse code?
Comment 4 Boris Bokowski CLA 2009-09-23 16:39:43 EDT
(In reply to comment #3)
> (In reply to comment #2)
> 
> > You seem to be fighting what the user tried to do, why do you need to activate
> > a part instead of the one that is originally being activated?
> > If you really need to do this, the workaround is to post an asyncExec to
> > activate a different part.
> 
> When i'm having the exception, the partActivated is called by the eclipse
> framework, any other workarounds without modifying eclipse code?

Do you have a stack trace?
Comment 5 Nick Chiu CLA 2009-09-23 18:36:48 EDT
(In reply to comment #4)
> (In reply to comment #3)
> > (In reply to comment #2)
> > 
> > > You seem to be fighting what the user tried to do, why do you need to activate
> > > a part instead of the one that is originally being activated?
> > > If you really need to do this, the workaround is to post an asyncExec to
> > > activate a different part.
> > 
> > When i'm having the exception, the partActivated is called by the eclipse
> > framework, any other workarounds without modifying eclipse code?
> Do you have a stack trace?

Stack Trace:
[[WorkbenchPage.setActivePart(3441)] - java.lang.RuntimeException - WARNING: Prevented recursive attempt to activate part myBookPage while still in the middle of activating part myEditor
	org.eclipse.ui.internal.WorkbenchPage.setActivePart(WorkbenchPage.java:3441)
	org.eclipse.ui.internal.WorkbenchPage.requestActivation(WorkbenchPage.java:3034)
	org.eclipse.ui.internal.PartPane.requestActivation(PartPane.java:272)
	org.eclipse.ui.internal.PartPane.handleEvent(PartPane.java:236)
	org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
	org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1003)
	org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1027)
	org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1008)
	org.eclipse.swt.widgets.Shell.setActiveControl(Shell.java:1353)
	org.eclipse.swt.widgets.Control.sendFocusEvent(Control.java:2443)
	org.eclipse.swt.widgets.Widget.wmSetFocus(Widget.java:2266)
	org.eclipse.swt.widgets.Control.WM_SETFOCUS(Control.java:4414)
	org.eclipse.swt.widgets.Control.windowProc(Control.java:3855)
	org.eclipse.swt.widgets.Display.windowProc(Display.java:4528)
	org.eclipse.swt.internal.win32.OS.ShowWindow(Native Method)
	org.eclipse.swt.widgets.Control.showWidget(Control.java:2409)
	org.eclipse.swt.widgets.Control.setVisible(Control.java:3206)
	org.eclipse.ui.part.PageBook.showPage(PageBook.java:118)
	org.eclipse.ui.part.PageBookView.showPageRec(PageBookView.java:964)
	org.eclipse.ui.part.PageBookView.partActivated(PageBookView.java:746)
	org.eclipse.ui.internal.PartListenerList$1.run(PartListenerList.java:72)
	org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:37)
	org.eclipse.core.runtime.Platform.run(Platform.java:880)
	org.eclipse.ui.internal.PartListenerList.fireEvent(PartListenerList.java:57)
	org.eclipse.ui.internal.PartListenerList.firePartActivated(PartListenerList.java:70)
	org.eclipse.ui.internal.PartService.firePartActivated(PartService.java:186)
	org.eclipse.ui.internal.PartService.setActivePart(PartService.java:305)
	org.eclipse.ui.internal.WorkbenchPagePartList.fireActivePartChanged(WorkbenchPagePartList.java:56)
	org.eclipse.ui.internal.PartList.setActivePart(PartList.java:126)
	org.eclipse.ui.internal.WorkbenchPage.setActivePart(WorkbenchPage.java:3491)
	org.eclipse.ui.internal.WorkbenchPage.activate(WorkbenchPage.java:610)
	org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2832)
	org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2729)
	org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:2721)
	org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:2673)
	org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
	org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2668)
	org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2652)
	org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2635)
Comment 6 Boris Bokowski CLA 2009-09-23 19:35:54 EDT
Nick, you probably have an editor that does not implement setFocus() properly. Every part has to set focus to the appropriate widget from their setFocus() method.
Comment 7 Nick Chiu CLA 2009-09-25 20:00:47 EDT
(In reply to comment #6)
> Nick, you probably have an editor that does not implement setFocus() properly.
> Every part has to set focus to the appropriate widget from their setFocus()
> method.

Awesome, this fixes the problem, although maybe it should be fixed in:

org.eclipse.ui.part.MultiPageEditorPart#setFocus() where it doesn't set focus if no page is active. I've fixed my issue by overriding and setting the active shell to focus (need to set something to focus)