Bug 573448 - No way to specify main menu as SWT widget
Summary: No way to specify main menu as SWT widget
Status: NEW
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.21   Edit
Hardware: PC Windows 10
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2021-05-10 04:17 EDT by Joachim Leiser CLA
Modified: 2021-06-21 11:21 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 Joachim Leiser CLA 2021-05-10 04:17:10 EDT
Currently it is possible to specify MenuContributions to the Main Menu with a text and icon. 

But I want to replace the main menu with a widget (Button) of my own. Eclipse provides no way to customize the behavior of the main menu apart from the entries. 

I would expect to be able to give a Main Menu item of the application model my own implementation. Or at least provide a way to extend/replace the Renderers so I can write my own version of a main menu. 

Steps to Reproduce:
Create a standard RCP application
In Application.e4xmi create a Window, Main Menu and Menu item. 
Now I would expect to be able to link a Main Menu to a custom implementation that allows me to specify a SWT Control.
Comment 1 Wim Jongman CLA 2021-05-10 16:41:27 EDT
You can choose not to have the main menu and use the toolbar with toolcontrol to create your own button-based menu.
Comment 2 Rolf Theunissen CLA 2021-05-11 02:57:24 EDT
Eclipse E4 allows full customization of rendering, especially in an full E4 application. You wouldn't be even be limited to SWT. Besides fully replacing the rendering, there are some more fine grained customization levels.

The rendering is executed by the IPresentationEngine, the default one that is used is PartRenderingEngine. That engine uses Renderers that extend AbstractPartRenderer. By default the engine uses a factory WorkbenchRendererFactory that creates different renderers for each different classes in the E4 model.
This behavior can be customized in two ways:
1. Provide an custom factory for the renderers, by providing a custom IRendererFactory with the E4Workbench.RENDERER_FACTORY_URI in the context.
2. Add a IPresentationEngine.CUSTOM_RENDERER_KEY with an uri to a custom AbstractPartRenderer to the persisted state of an model element, this renderer would be used for this specific element.

First a disclaimer w.r.t. the custom renderer, I expect that not all renderers currently respect the custom renderer, so do expect issues when you go that way.

In your case, you would want to customize the MenuManagerRenderer which is used for menu items. However, this is one of the most tricky to customize, even in the engine there are some special cases w.r.t. menus. Also the renderer uses JFace MenuManager to render the menu, AFAIK, that doesn't allow custom controls in menus.

As Wim suggested, you will have most success (or least effort) when you would be using a toolbar with a toolcontrol, which is designed to use custom controls. It should also be possible to have that toolbar button open a (popup) menu that is managed in the model.
Comment 3 Thomas Schindl CLA 2021-05-11 06:25:47 EDT
Well the main complexity in the current menu-rendering is caused by fact that the compat story was pushed down to the e4 codebase. 

Implementing a pure e4 compatible way of a menu-system would be much more lightweight. One thing we never accomplished in e4-swt is to split out the none UI-specific logic into base classes so that people can reuse them.

In e(fx)clipse I've done that split and so implementing custom renderers is much easier as all the logic (like visible-when, ...) covered by generic code [1] and you only have to deal your UI-Specific stuff [2].


[1]https://github.com/eclipse-efx/efxclipse-rt/blob/3.x/modules/ui/org.eclipse.fx.ui.workbench.renderers.base/src/main/java/org/eclipse/fx/ui/workbench/renderers/base/BaseMenuBarRenderer.java
[2]https://github.com/eclipse-efx/efxclipse-rt/blob/3.x/modules/ui/org.eclipse.fx.ui.workbench.renderers.fx/src/main/java/org/eclipse/fx/ui/workbench/renderers/fx/DefMenuRenderer.java
Comment 4 Joachim Leiser CLA 2021-06-21 11:21:37 EDT
Hey, thank you for the quick replys. Sorry for my late reply, it took me a while to get the time to take a thorough look at it. 

The solution with the toolbar may be very well possible, but doesn't feel quite right and produces other problems in our application.

So we are going the proper way and are trying to use the MenuManagerRenderer (and WBWRenderer). Thanks to your explanations I finally got how this all works. Using a custom MenuManagerRenderer extending the standard Renderer with some changes works well. But the WBWRenderer poses a problem.

In WBWRenderer.processContents(...) the menubar of the Shell is set with a standard main menu. I would like to omit this code since I created my custom Menu. However WBWRenderer.processContents() calls its parent with super. I would like to have that super call as well since the SWTPartRenderer.processContents is doing (at least I understand it that way) the main work. But I cannot omit the WBWRenderer and use the SWTPartRenderer. Duplicating the SWT code is also not possible, since the attribute 'context' is not accessible for me. So my only way out is to replace the WBWRenderer completely which sounds like a lot of work. 

Is there an easier way I didn't see?