Bug 378861 - [Contributions] Context Menu not available for Dialogs
Summary: [Contributions] Context Menu not available for Dialogs
Status: CLOSED WONTFIX
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.2   Edit
Hardware: PC Windows 7
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform UI Triaged CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords: helpwanted
Depends on:
Blocks:
 
Reported: 2012-05-08 11:44 EDT by Markus Stier CLA
Modified: 2019-12-09 09:13 EST (History)
5 users (show)

See Also:


Attachments
Testcase for bug 378861 (13.66 KB, application/x-zip-compressed)
2015-03-09 22:18 EDT, Patrik Suzzi CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Markus Stier CLA 2012-05-08 11:44:36 EDT
I'm trying to add a context menu to an SWT control which sits on a dialog. The application is a plain e4 app without compatibility layer.

The Dialog, login dialog, is shown just before any other part. In the initialization of the EMenuService I get a NPE because the service could not find a valid MPart within the context. Since the context menu is about to be added to a dialog this is not surprising. But it seems there is no EMenuService which could deal with a dialog.
Comment 1 Patrik Suzzi CLA 2015-03-05 22:28:47 EST
I want to reproduce the error, and I need some information

The problem reworded:

We have a plain E4 app, with no compat layer. We add a Login Dialog, displayed before any other part in the application. In this part there is an SWT control to which we want to add a context menu.

For context menu we initialize the EMenuService, and during this initialization we get a Null Pointer Exception (NPE) . We suppose the reason is that there is no valid MPart in the context.

Then, I have two questions:

1. Is the login dialog launched in the lifecycle ? ( short code example ? )
2. How you get the EMenuService instance? ( ctor/field inj?, any example ? )
Comment 2 Patrik Suzzi CLA 2015-03-09 22:18:24 EDT
Created attachment 251418 [details]
Testcase for bug 378861

e4 app single project that shows the bug.
Comment 3 Patrik Suzzi CLA 2015-03-09 22:21:08 EDT
I reproduced the bug. See attachment #1 [details]

The LoginDialog is instantiated in E4Lifecycle, @ProcessAdditions, via injection

LoginDialog dialog = ContextInjectionFactory.make(LoginDialog.class, workbenchContext);

When trying to instantiate the EMenuService, I get the following error

MenuService: WorkbenchContext: org.eclipse.e4.core.di.InjectionException: 
Unable to process "MenuService.myPart": no actual value was found for the argument "MPart".

I already discussed this bug with a committer. 
The point is the LoginDialog is not an MPart, and the MenuService, as is defined, can live only in an MPart context

public class MenuService implements EMenuService {
    @Inject
    private MPart myPart;
 
    // .. all the code
 
}

( defined in bundle: org.eclipse.e4.ui.workbench.swt  ) 

Is it enough to declare @Optional the injection or is required a more complex solution, like changing the EMF model ?
Comment 4 Paul Webster CLA 2015-03-30 10:40:37 EDT
I haven't had a chance to look at it in depth, but really the part you need is: org.eclipse.e4.ui.internal.workbench.swt.MenuService.registerMenu(Control, MPopupMenu, IEclipseContext).  It's not exposed at the moment, but it doesn't require the MPart to function.

That's a static method.  You would need a model container for the MPopupMenu since it has to live in some context.

I don't know how much work went into org.eclipse.e4.ui.model.application.ui.basic.MDialog in Luna or Mars, but that's a possible context for the menu.  Lars, do you know?

PW
Comment 5 Lars Vogel CLA 2015-03-30 11:23:27 EDT
(In reply to Paul Webster from comment #4)
> I don't know how much work went into
> org.eclipse.e4.ui.model.application.ui.basic.MDialog in Luna or Mars, but
> that's a possible context for the menu.  Lars, do you know?

Tom plans to work on MDialog via Bug 460826, so far it is unchanged since Eric introduced it.
Comment 6 Eclipse Genie CLA 2019-12-09 09:13:46 EST
This bug hasn't had any activity in quite some time. Maybe the problem got resolved, was a duplicate of something else, or became less pressing for some reason - or maybe it's still relevant but just hasn't been looked at yet.

If you have further information on the current state of the bug, please add it. The information can be, for example, that the problem still occurs, that you still want the feature, that more information is needed, or that the bug is (for whatever reason) no longer relevant.

--
The automated Eclipse Genie.