Bug 365724 - Hide a MainMenu MMenu from a handler at runtime
Summary: Hide a MainMenu MMenu from a handler at runtime
Status: REOPENED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: UI (show other bugs)
Version: 4.22   Edit
Hardware: PC All
: P3 normal (vote)
Target Milestone: ---   Edit
Assignee: Platform-UI-Inbox CLA
QA Contact:
URL:
Whiteboard: stalebug
Keywords:
Depends on:
Blocks:
 
Reported: 2011-12-06 08:21 EST by Thomas Kölling CLA
Modified: 2021-10-20 07:33 EDT (History)
6 users (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Kölling CLA 2011-12-06 08:21:46 EST
Build Identifier: I20111201-2015

I develop a small (and later big) eclipse rcp application. currently i try to hide/disable the MainMenu for a special key shortcut. i got the TrimmedWindow via the ModelService and from there, i got the MainMenu. if setting this instance visible = false and/or enabled = false, doesn't work. no exception, no behavior. it just do nothing. Here the sample code:

@Execute
	public void execute(MApplication application, EModelService service){
		List<MTrimmedWindow> findElements = service.findElements(application, "myTrimmedWindow",
				MTrimmedWindow.class, null);
		findElements.get(0).getMainMenu().setVisible(false);
		findElements.get(0).getMainMenu().setEnabled(false);
	}

Reproducible: Always

Steps to Reproduce:
1.see code
Comment 1 Paul Webster CLA 2011-12-06 08:26:39 EST
You currently can't hide the main menu bar at all (and probably not like that).

Setting an MMenu to visible=false should work for submenus however.

PW
Comment 2 Thomas Schindl CLA 2011-12-06 08:47:16 EST
Hm at the SWT-Level this is certainly possible so I think all we need is to make the renderer smarter:

Here's a pure SWT/JFace snippet to toggle menubar:

package test;

import org.eclipse.jface.action.Action;
import org.eclipse.jface.action.MenuManager;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Decorations;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;

public class Testmenu {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		Display d = new Display();
		final Shell s = new Shell(d);
		s.setLayout(new GridLayout());
		
		final MenuManager mgr = new MenuManager();
		MenuManager submenu = new MenuManager("Menu");
		submenu.add(new Action("Test") {
			
		});
		mgr.add(submenu);
		
		mgr.createMenuBar((Decorations)s);
		s.setMenuBar(mgr.getMenu());
		
		Button b = new Button(s, SWT.PUSH);
		b.setText("Toggle");
		b.addSelectionListener(new SelectionAdapter() {
			@Override
			public void widgetSelected(SelectionEvent e) {
				if( s.getMenuBar() == null ) {
					s.setMenuBar(mgr.getMenu());
				} else {
					s.setMenuBar(null);
				}
			}
		});
		
		s.open();
		
		while( ! s.isDisposed() ) {
			if( ! d.readAndDispatch() ) {
				d.sleep();
			}
		}
		
		d.dispose();
	}

}
Comment 3 Brian de Alwis CLA 2011-12-06 10:59:28 EST
ThomasK, are you by chance contributing menus through a MMenuContribution?  There's a bug I uncovered as part of bug 359778  where the menu manager is disconnected from menus coming from MMenuContributions.  You could try applying that patch and see if it makes a difference.
Comment 4 Thomas Schindl CLA 2011-12-06 11:04:16 EST
(In reply to comment #3)
> ThomasK, are you by chance contributing menus through a MMenuContribution? 
> There's a bug I uncovered as part of bug 359778  where the menu manager is
> disconnected from menus coming from MMenuContributions.  You could try applying
> that patch and see if it makes a difference.

The problem is clearly seen in the renderer which doesn't handle the visible change on root menu where it has to remove the menubar from the decoration-instance.
Comment 5 Brian de Alwis CLA 2011-12-06 12:31:13 EST
(In reply to comment #4)
> The problem is clearly seen in the renderer which doesn't handle the visible
> change on root menu where it has to remove the menubar from the
> decoration-instance.

That's actually the exact scenario where I discovered the issue with contributed menus.  I was trying to implement activities support to hide/show a top-level menu using setVisible().
Comment 6 Thomas Schindl CLA 2011-12-06 12:51:56 EST
(In reply to comment #5)
> (In reply to comment #4)
> > The problem is clearly seen in the renderer which doesn't handle the visible
> > change on root menu where it has to remove the menubar from the
> > decoration-instance.
> 
> That's actually the exact scenario where I discovered the issue with
> contributed menus.  I was trying to implement activities support to hide/show a
> top-level menu using setVisible().


I'm not sure what capabilities have to do with the Windows-Main-Menu-Bar I can't believe this has something to do with it. We are talking here about Decoration#setMenuBar() and not something like the File, ... Menu
Comment 7 Thomas Kölling CLA 2011-12-06 13:00:19 EST
(In reply to comment #6)
> (In reply to comment #5)
> > (In reply to comment #4)
> > > The problem is clearly seen in the renderer which doesn't handle the visible
> > > change on root menu where it has to remove the menubar from the
> > > decoration-instance.
> > 
> > That's actually the exact scenario where I discovered the issue with
> > contributed menus.  I was trying to implement activities support to hide/show a
> > top-level menu using setVisible().
> 
> 
> I'm not sure what capabilities have to do with the Windows-Main-Menu-Bar I
> can't believe this has something to do with it. We are talking here about
> Decoration#setMenuBar() and not something like the File, ... Menu

exactly
Comment 8 Brian de Alwis CLA 2011-12-06 15:16:57 EST
(In reply to comment #6)
> I'm not sure what capabilities have to do with the Windows-Main-Menu-Bar I
> can't believe this has something to do with it. We are talking here about
> Decoration#setMenuBar() and not something like the File, ... Menu

Oops sorry, my fault: I failed to read the original code snippet deeply enough and was interpreting the bug title "Hide a MainMenu MMenu at from a handler hat runtime" as indicating problems hiding *a* MMenu defined from the main menu.
Comment 9 Micha El CLA 2015-04-27 05:33:20 EDT
I've facing the same problem. A possible workaround is to get the MenuManager and force an update of the modified main menu structure.

MMenu mainMenu = window.getMainMenu();
org.eclipse.e4.ui.workbench.renderers.swt.MenuManagerRenderer renderer = (MenuManagerRenderer)mainMenu.getRenderer();

mainMenu.getChildren().get(0).setVisible(true);

renderer.getManager(mainMenu).update(true);
Comment 10 Eclipse Genie CLA 2019-01-22 12:20:06 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.
Comment 11 Lars Vogel CLA 2019-06-05 07:29:14 EDT
This is a mass change to close all e4 bugs marked with "stalebug" whiteboard.

If this bug is still valid, please reopen and remove the "stalebug" keyword.
Comment 12 Lars Vogel CLA 2021-10-20 05:49:31 EDT
Still relevant. Can also be triggered by the model spy (trigger visible true/false) which also crashes the application.