This Bugzilla instance is deprecated, and most Eclipse projects now use GitHub or Eclipse GitLab. Please see the deprecation plan for details.
Bug 375393 - Popup / Context Menu disapears after reopening a part (e4)
Summary: Popup / Context Menu disapears after reopening a part (e4)
Status: VERIFIED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows 7
: P3 major with 11 votes (vote)
Target Milestone: 4.4 M4   Edit
Assignee: Nobody - feel free to take it CLA
QA Contact:
URL:
Whiteboard:
Keywords:
: 374229 406058 (view as bug list)
Depends on:
Blocks:
 
Reported: 2012-03-27 05:54 EDT by Tom K. CLA
Modified: 2014-06-30 14:45 EDT (History)
16 users (show)

See Also:


Attachments
bug Demo Project (13.93 KB, application/x-zip-compressed)
2012-03-27 06:09 EDT, Tom K. CLA
no flags Details
Proposed patch (2.99 KB, patch)
2013-04-09 05:06 EDT, Nobody - feel free to take it CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Tom K. CLA 2012-03-27 05:54:01 EDT
When a popup menu is registered in a Part (in the @PostConstruct method)  
and the part opens the first time, the menu shows up and everthing is as it should be.

If you close the part and open it again (To be Rendered flag set to false and again to true) - the same code is called but the menu does not show up anymore.

Perhaps something is not de-registered correctly when your view is closed.

Tested and reproduced with:
Version: 4.2.0
Build id: I20120315-1300
Comment 1 Tom K. CLA 2012-03-27 06:09:32 EDT
Created attachment 213222 [details]
bug Demo Project

Little Project to demonstrate the Problem
Open Application - > Click on Label : Popup shows up
close View
File->Open : Page opens again
Click on Label : Popup does not show up anymore
Comment 2 Missing name CLA 2012-03-28 06:02:31 EDT
*** Bug 374229 has been marked as a duplicate of this bug. ***
Comment 3 Nobody - feel free to take it CLA 2012-03-28 09:25:41 EDT
The pushmenu in the second case actually IS in the model and doesn't render. If you call part.getMenus().get(0).toString() in both cases in the first on you see 
....widget: Menu {pushme}.... and the second widget: Menu{}...

Also if you set the application to remember its state and close it after you have closed the part, you will notice that when you run your app again and open the part for the first time the menu IS displayed. I believe this shows that the closing of the part, or specifically the setting false of the visibility of the part somehow prevents the renderer from displaying it again.
Comment 4 nikolaz nikolaz CLA 2012-09-09 06:43:44 EDT
I can share some debug information.

Let's have a look at MenuManagerRendere.processHandledItem(...)

void processHandledItem(MenuManager parentManager,
		MHandledMenuItem itemModel) {
	IContributionItem ici = getContribution(itemModel);
	if (ici != null) {
		return;
	}
	final IEclipseContext lclContext = getContext(itemModel);
	HandledContributionItem ci = ContextInjectionFactory.make(
			HandledContributionItem.class, lclContext);
	ci.setModel(itemModel);
	ci.setVisible(itemModel.isVisible());
	addToManager(parentManager, itemModel, ci);
	linkModelToContribution(itemModel, ci);
}
....
public IContributionItem getContribution(MMenuElement model) {
	return modelToContribution.get(model);
}


When it is invoked for the first time to generate Menu widget from Model, method getContribution(itemModel) return null and items are generated correctly. This method checks if model item already has a corresponding UI item. When processHandledItem is invoked for the second time, after part has been closed (Menu widget was disposed). Then getContribution returns not null and no MenuItems created. So the root of the issue it that modelToContribution is not cleaned in time when Menu Disposed. It means clearModelToContribution(..) is not called (or called unproperly)

public void clearModelToContribution(MMenuElement model,
		IContributionItem item) {
	modelToContribution.remove(model);
	contributionToModel.remove(item);
}
Comment 5 Tom K. CLA 2013-01-15 05:30:54 EST
Is there allready a schedule for this to fix on a Milestone?
If we can help something let us know...
Comment 6 Paul Webster CLA 2013-01-15 15:40:05 EST
No one has had a chance to look at this yet, as comment #4 mentioned something must not be cleaning up on the dispose.

PW
Comment 7 Laura V CLA 2013-04-08 04:51:00 EDT
This is a pretty bad bug. Eclipse is built to be working with windows that can be moved around and closed / reopened. If the menus for a part disappear, for the user it is then impossible to interact with it.
In my humble opinion this issue should get a higher priority.
Comment 8 Paul Webster CLA 2013-04-08 08:13:31 EDT
See http://wiki.eclipse.org/Platform_UI/How_to_Contribute if someone would like to take a crack at a patch.

PW
Comment 9 Nobody - feel free to take it CLA 2013-04-09 05:06:22 EDT
Created attachment 229488 [details]
Proposed patch

Just doing removeGui on the popup menu is not enough as a clean up step. Additional cleaning is required.
Comment 10 Paul Webster CLA 2013-04-09 07:28:21 EDT
Patch in Gerrit

https://git.eclipse.org/r/11742

PW
Comment 11 Paul Webster CLA 2013-04-22 11:26:27 EDT
*** Bug 406058 has been marked as a duplicate of this bug. ***
Comment 12 Jonas Helming CLA 2013-10-01 11:33:32 EDT
Hi,
would it be possible to apply this patch for the next milestone? There there something open to help with?

Regards

Jonas
Comment 13 Paul Webster CLA 2013-10-01 11:44:28 EDT
(In reply to Jonas Helming from comment #12)
> Hi,
> would it be possible to apply this patch for the next milestone? There there
> something open to help with?

There are outstanding comments on the Gerrit review.

PW
Comment 14 Nobody - feel free to take it CLA 2013-11-12 08:16:10 EST
(In reply to Paul Webster from comment #13)
> (In reply to Jonas Helming from comment #12)
> > Hi,
> > would it be possible to apply this patch for the next milestone? There there
> > something open to help with?
> 
> There are outstanding comments on the Gerrit review.
> 
> PW

Gerrit updated with new patchset. Can we squeeze this in M4?
Comment 15 Paul Webster CLA 2013-11-15 14:25:16 EST
(In reply to Sopot Cela from comment #14)
> 
> Gerrit updated with new patchset. Can we squeeze this in M4?

Released as http://git.eclipse.org/c/platform/eclipse.platform.ui.git/commit/?id=4765bf418d00ccbe40662c4d57015305985e95c9

PW
Comment 16 Markus Keller CLA 2013-11-20 07:43:29 EST
(In reply to Paul Webster from comment #15)
This commit broke context menus in the EGit view. I only see the "Show In >" menu now. When I revert this commit, the other menu items are back.
Comment 17 Nobody - feel free to take it CLA 2013-11-20 08:08:31 EST
(In reply to Markus Keller from comment #16)
> (In reply to Paul Webster from comment #15)
> This commit broke context menus in the EGit view. I only see the "Show In >"
> menu now. When I revert this commit, the other menu items are back.

I'm not sure why the compat layer calls cleanUp on Eclipse startup. This is the stack which causes the removal of the menu items. Investigating. 

Thread [main] (Suspended (breakpoint at line 436 in MenuManagerRenderer))	
	MenuManagerRenderer.cleanUp(MMenu) line: 436	
	PopupMenuExtender.cleanUpContributionCache() line: 488	
	PopupMenuExtender.createModelFor(String) line: 186	
	PopupMenuExtender.<init>(String, MenuManager, ISelectionProvider, IWorkbenchPart, IEclipseContext, boolean) line: 156	
	PartSite.registerContextMenu(String, MenuManager, ISelectionProvider, boolean, IWorkbenchPart, IEclipseContext, Collection) line: 131	
	ViewSite(PartSite).registerContextMenu(String, MenuManager, ISelectionProvider) line: 508	
	ViewSite(PartSite).registerContextMenu(MenuManager, ISelectionProvider) line: 516	
	RepositoriesView.createEmptyArea(Composite) line: 262	
	RepositoriesView.createPartControl(Composite) line: 354	
	CompatibilityView(CompatibilityPart).createPartControl(IWorkbenchPart, Composite) line: 138	
	CompatibilityView.createPartControl(IWorkbenchPart, Composite) line: 155	
	CompatibilityView(CompatibilityPart).create() line: 319	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	Method.invoke(Object, Object...) line: not available	
	MethodRequestor.execute() line: 56	
	InjectorImpl.processAnnotated(Class<Annotation>, Object, Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier, ArrayList<Class<?>>) line: 877	
	InjectorImpl.processAnnotated(Class<Annotation>, Object, Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier, ArrayList<Class<?>>) line: 857	
	InjectorImpl.inject(Object, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 119	
	InjectorImpl.internalMake(Class<?>, PrimaryObjectSupplier, PrimaryObjectSupplier) line: 333	
	InjectorImpl.make(Class<T>, PrimaryObjectSupplier) line: 254	
	ContextInjectionFactory.make(Class<T>, IEclipseContext) line: 162	
	ReflectionContributionFactory.createFromBundle(Bundle, IEclipseContext, IEclipseContext, URI) line: 102	
	ReflectionContributionFactory.doCreate(String, IEclipseContext, IEclipseContext) line: 71	
	ReflectionContributionFactory.create(String, IEclipseContext) line: 53	
	ContributedPartRenderer.createWidget(MUIElement, Object) line: 129	
	PartRenderingEngine.createWidget(MUIElement, Object) line: 949	
	PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 633	
	PartRenderingEngine$6.run() line: 526	
	SafeRunner.run(ISafeRunnable) line: 42	
	PartRenderingEngine.createGui(MUIElement, Object, IEclipseContext) line: 511	
	ElementReferenceRenderer.createWidget(MUIElement, Object) line: 61	
	PartRenderingEngine.createWidget(MUIElement, Object) line: 949	
	PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 633	
	PartRenderingEngine.safeCreateGui(MUIElement) line: 735	
	PartRenderingEngine.access$2(PartRenderingEngine, MUIElement) line: 706	
	PartRenderingEngine$7.run() line: 700	
	SafeRunner.run(ISafeRunnable) line: 42	
	PartRenderingEngine.createGui(MUIElement) line: 685	
	StackRenderer.showTab(MUIElement) line: 1208	
	StackRenderer(LazyStackRenderer).postProcess(MUIElement) line: 96	
	PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 649	
	PartRenderingEngine.safeCreateGui(MUIElement) line: 735	
	PartRenderingEngine.access$2(PartRenderingEngine, MUIElement) line: 706	
	PartRenderingEngine$7.run() line: 700	
	SafeRunner.run(ISafeRunnable) line: 42	
	PartRenderingEngine.createGui(MUIElement) line: 685	
	SashRenderer(SWTPartRenderer).processContents(MElementContainer<MUIElement>) line: 67	
	PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 645	
	PartRenderingEngine.safeCreateGui(MUIElement) line: 735	
	PartRenderingEngine.access$2(PartRenderingEngine, MUIElement) line: 706	
	PartRenderingEngine$7.run() line: 700	
	SafeRunner.run(ISafeRunnable) line: 42	
	PartRenderingEngine.createGui(MUIElement) line: 685	
	SashRenderer(SWTPartRenderer).processContents(MElementContainer<MUIElement>) line: 67	
	PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 645	
	PartRenderingEngine.safeCreateGui(MUIElement) line: 735	
	PartRenderingEngine.access$2(PartRenderingEngine, MUIElement) line: 706	
	PartRenderingEngine$7.run() line: 700	
	SafeRunner.run(ISafeRunnable) line: 42	
	PartRenderingEngine.createGui(MUIElement) line: 685	
	PerspectiveRenderer(SWTPartRenderer).processContents(MElementContainer<MUIElement>) line: 67	
	PerspectiveRenderer.processContents(MElementContainer<MUIElement>) line: 59	
	PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 645	
	PartRenderingEngine.safeCreateGui(MUIElement) line: 735	
	PartRenderingEngine.access$2(PartRenderingEngine, MUIElement) line: 706	
	PartRenderingEngine$7.run() line: 700	
	SafeRunner.run(ISafeRunnable) line: 42	
	PartRenderingEngine.createGui(MUIElement) line: 685	
	PerspectiveStackRenderer.showTab(MUIElement) line: 103	
	PerspectiveStackRenderer(LazyStackRenderer).postProcess(MUIElement) line: 96	
	PerspectiveStackRenderer.postProcess(MUIElement) line: 77	
	PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 649	
	PartRenderingEngine.safeCreateGui(MUIElement) line: 735	
	PartRenderingEngine.access$2(PartRenderingEngine, MUIElement) line: 706	
	PartRenderingEngine$7.run() line: 700	
	SafeRunner.run(ISafeRunnable) line: 42	
	PartRenderingEngine.createGui(MUIElement) line: 685	
	SashRenderer(SWTPartRenderer).processContents(MElementContainer<MUIElement>) line: 67	
	PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 645	
	PartRenderingEngine.safeCreateGui(MUIElement) line: 735	
	PartRenderingEngine.access$2(PartRenderingEngine, MUIElement) line: 706	
	PartRenderingEngine$7.run() line: 700	
	SafeRunner.run(ISafeRunnable) line: 42	
	PartRenderingEngine.createGui(MUIElement) line: 685	
	WBWRenderer(SWTPartRenderer).processContents(MElementContainer<MUIElement>) line: 67	
	WBWRenderer.processContents(MElementContainer<MUIElement>) line: 582	
	PartRenderingEngine.safeCreateGui(MUIElement, Object, IEclipseContext) line: 645	
	PartRenderingEngine.safeCreateGui(MUIElement) line: 735	
	PartRenderingEngine.access$2(PartRenderingEngine, MUIElement) line: 706	
	PartRenderingEngine$7.run() line: 700	
	SafeRunner.run(ISafeRunnable) line: 42	
	PartRenderingEngine.createGui(MUIElement) line: 685	
	PartRenderingEngine$9.run() line: 1042	
	Realm.runWithDefault(Realm, Runnable) line: 332	
	PartRenderingEngine.run(MApplicationElement, IEclipseContext) line: 997	
	E4Workbench.createAndRunUI(MApplicationElement) line: 146	
	Workbench$5.run() line: 613	
	Realm.runWithDefault(Realm, Runnable) line: 332	
	Workbench.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 567	
	PlatformUI.createAndRunWorkbench(Display, WorkbenchAdvisor) line: 150	
	IDEApplication.start(IApplicationContext) line: 124	
	EclipseAppHandle.run(Object) line: 196	
	EclipseAppLauncher.runApplication(Object) line: 109	
	EclipseAppLauncher.start(Object) line: 80	
	EclipseStarter.run(Object) line: 372	
	EclipseStarter.run(String[], Runnable) line: 226	
	NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method]	
	NativeMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: not available	
	Method.invoke(Object, Object...) line: not available	
	Main.invokeFramework(String[], URL[]) line: 636	
	Main.basicRun(String[]) line: 591	
	Main.run(String[]) line: 1450	
	Main.main(String[]) line: 1426
Comment 18 Nobody - feel free to take it CLA 2013-11-20 09:28:52 EST
This does not happen on Patchset 4 in Gerrit
Comment 19 Paul Webster CLA 2013-11-20 09:41:38 EST
(In reply to Sopot Cela from comment #18)
> This does not happen on Patchset 4 in Gerrit

OK, shall I revert the current fix from the Gerrit change, and then can you re-push patchset 4 up and we'll review it again?

PW
Comment 20 Nobody - feel free to take it CLA 2013-11-20 09:47:11 EST
Maybe it's easier if I send a gerrit request which just updates the actual code in the repository (remove unlink from cleanup and add it in the event handler) ?
Comment 21 Paul Webster CLA 2013-11-20 10:04:43 EST
Sure, that works to.

PW
Comment 22 Nobody - feel free to take it CLA 2013-11-20 10:07:09 EST
https://git.eclipse.org/r/18617
Comment 24 Nobody - feel free to take it CLA 2013-11-25 16:23:01 EST
Resolving.
Comment 25 Paul Elder CLA 2013-12-12 09:34:24 EST
Verified in 4.4.0.I20131211-2000