This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 398666 - partOpened not called for views in default Perspective when welcome view opens first
Summary: partOpened not called for views in default Perspective when welcome view open...
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2.1   Edit
Hardware: PC All
: P3 minor (vote)
Target Milestone: 4.4 M7   Edit
Assignee: Eric Moffatt CLA
QA Contact:
URL:
Whiteboard: candidate43
Keywords:
Depends on:
Blocks:
 
Reported: 2013-01-21 13:06 EST by Steven Horsman CLA
Modified: 2014-04-29 06:11 EDT (History)
3 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Steven Horsman CLA 2013-01-21 13:06:34 EST
We have hit a problem where partOpened callbacks for views in the default perspective were not triggered on the first run of the application (when the welcome/intro page comes up on top of it).
Our application was relying on this callback in Eclipse 3.4+ to trigger other listeners on the view, but in 4.2.1 we have had to move them into createPartControl() temporarily.

I have re-produced this problem in Eclipse 4.2.1 by creating a plug-in from the "Plug-in with a view" template, adding it to the default perspective and calling the following in the createPartControl of SampleView:

private void addListeners () {
	IWorkbenchWindow workbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
	partListener = new IPartListener() {
	
	@Override
	public void partOpened(IWorkbenchPart part) {
		if (part == SampleView.this) {
			System.out.println("Hi, I'm " + getPartName() + " and I'm opened");
		}
	}
		
	@Override
	public void partDeactivated(IWorkbenchPart part) {}
		
	@Override
	public void partClosed(IWorkbenchPart part) {}
	
	@Override
	public void partBroughtToTop(IWorkbenchPart part) {}
	
	@Override
	public void partActivated(IWorkbenchPart part) {}
	
	};
	workbenchWindow.getPartService().addPartListener(partListener);
}

(Apologies if the formatting is poor)

When I run this with a new workspace Eclipse starts with the welcome page and when closed my sample view is shown, but the partOpened code is not run.
Re-running this without clearing the workspace the view is shown on the default perspective and the partOpened code is run.
Comment 1 Eric Moffatt CLA 2013-01-23 16:34:43 EST
Steven, I'll have to look at this one tomorrow...it's certainly fixable though even if the TCS (Time Constrained Solution...;-) is to force the events to fire when the Intro view closes or goes into standby mode (i.e. gets unmaximized).
Comment 2 Eric Moffatt CLA 2013-01-24 14:22:47 EST
Steven, I've just tried this and as far as I can determine we're firing all the partOpened avents even when the Intro is coming up...by putting a brealpoint in WorkbenchPage#firePartOpened I get the following output when opening on a 'clean' workspace...

Fire: Package Explorer
Fire: Outline
Fire: Problems
Fire: Welcome

If possible could you re-test this with as recent an M-build as you can get ?
Comment 3 Steven Horsman CLA 2013-01-24 14:46:14 EST
Hi Eric,

I have re-tried using last nights M-build and the partOpened and partActivated get called whilst the welcome screen is open. It is a little earlier than I expected, but I'm happy with that behaviour, so it looks like this one has been fixed in 4.2.2 :D
Thanks!
Comment 4 Eric Moffatt CLA 2013-01-25 09:18:57 EST
Steven, if you're happy so am I...except that I don't see the sysout as you describe when I copy in your listener code.

I did track this down but expect that it's too deep in the code to make a quick fix for so as long as it's not affecting you I think I'll move this defect over to 4.3.
Comment 5 Eric Moffatt CLA 2013-01-25 10:18:11 EST
For future reference...We 'clone' the listener list(s) between the PartService (where they're registered) and WorkbenchPage (where we for some reason have duplicated the code to actually fire the listeners. The underlying reason for this is to prevent issues should a new listener get added as the result of some other listener's handling (can lead to ConcurrentModificationExceptions...).

Obviously this synch'ing isn't taking place in 'real-time' nor is it copied at the instant of wanting to fire the events (a performance optimization ??).
Comment 6 Wojciech Sudol CLA 2014-03-05 06:33:49 EST
The direct cause of the problem is that PartService is added to WorkbenchPage listeners too late - after WorkbenchPage.firePartOpened(*) is called for all views.
The problem occurs only when starting eclipse with fresh workspace. After restart the initialization order is correct, even if welcome page remains open and on top.
Comment 7 Wojciech Sudol CLA 2014-03-05 08:57:31 EST
Gerrit URL: https://git.eclipse.org/r/#/c/22931/
Comment 8 Eric Moffatt CLA 2014-03-05 15:10:15 EST
Wojciech, I'm not sure what your patch was supposed to do but see comment #2, I think that there's actually no defect here to fix.

If I put a breakpoint in WorkbenchPage#firePartOpened we always get one on a fresh start for all the visible views...with or without your fix.

Perhaps you were looking at 'partVisible' instead (since the changed code is where 'fireInitialPartVisibilityEvents'  is called) ?

How did you test whether or not the patch was working ? Perhaps I'm just testing the wrong things ?
Comment 9 Wojciech Sudol CLA 2014-03-05 15:26:52 EST
I was using the code snippet from comment 0.

Also:
(In reply to Eric Moffatt from comment #4)
> Steven, if you're happy so am I...except that I don't see the sysout as you
> describe when I copy in your listener code.
Comment 10 Wojciech Sudol CLA 2014-03-06 05:29:25 EST
Let me elaborate.
The problem is that listeners added to PartService (as in the example - workbenchWindow.getPartService().addPartListener(partListener)) are not notified when eclipse opens with a fresh workspace. In 3.8 the problem does not occur.
Moreover it has nothing to do with welcome page.
Comment 11 Eric Moffatt CLA 2014-03-06 14:49:02 EST
Wojciech, thanks...I've verified that the patch works. I can't commit it today because we've still locked out of commits in case something M6 jeopardizing comes up, I'll commit this on Monday.

Sorry for the confusion on my part...
Comment 12 Eric Moffatt CLA 2014-03-10 11:04:08 EDT
Committed Wojciech's patch, thanks dude !

http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=b20df982add55483c95e33f97d29807712ccae1c
Comment 13 Wojciech Sudol CLA 2014-04-29 06:11:25 EDT
Verified in I20140428-2000.