Summary: | No way to specify main menu as SWT widget | ||
---|---|---|---|
Product: | [Eclipse Project] Platform | Reporter: | Joachim Leiser <jleiser> |
Component: | UI | Assignee: | Platform-UI-Inbox <Platform-UI-Inbox> |
Status: | NEW --- | QA Contact: | |
Severity: | normal | ||
Priority: | P3 | CC: | rolf.theunissen, tom.schindl, wim.jongman |
Version: | 4.21 | ||
Target Milestone: | --- | ||
Hardware: | PC | ||
OS: | Windows 10 | ||
Whiteboard: |
Description
Joachim Leiser
2021-05-10 04:17:10 EDT
You can choose not to have the main menu and use the toolbar with toolcontrol to create your own button-based menu. 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. 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 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? |