Community
Participate
Working Groups
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.
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 ? )
Created attachment 251418 [details] Testcase for bug 378861 e4 app single project that shows the bug.
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 ?
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
(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.
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.