Skip to main content

Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Eclipse 4 » How "hide" disabled handled menu items in (sub menu of) popup menu?
How "hide" disabled handled menu items in (sub menu of) popup menu? [message #1790742] Fri, 15 June 2018 09:57
Erik  Lundström is currently offline Erik LundströmFriend
Messages: 19
Registered: July 2009
Junior Member
I am facing a problem with managing change of enablement state of modelled handled menu items for the "popup" menu that goes to an MPart. All the involved model elements (part, popup menu, menus, handled menu items) are defined in e4xmi. The popup menu is wired in the POJO backing the MPart by using EMenuService.registerContextMenu(Control, String menuId).

I think it is easiest described by images. This is the original context/popup menu in my part (image1).


The "Create" sub menu contains menu items that enables the user to create different types of objects. It is typically dependent on the current selection : there are underlying rules determining whether a certain handleditem should be enabled or not.

Now, I would really like to be able to hide the handled items that are not enabled. If I in my handler implementation make a slight addition:

public boolean canExecute( ESelectionService selectionService, MPart part, MItem item )
    boolean canExecute = false;

    //...Custom code here to test enablement/executability...
    //The addition: if a menuitem, make it invisible if not executable. (I use the same handler for toolitem, hence the instanceof-test)
   if ( item instanceof MMenuItem ) {
       item.setVisible( canExecute );
   return canExecute;

This seems to work fine at a first glance. When the same object is selected, the set of visible items are narrowed down to the following (image2).
This looks much better in my opinion - the user is presented with the enabled menu items only.

But, setting the visibility explicitly this way has major drawbacks which ultimately corrupts the context menu: when the user selects more than one object, all "Create"-handlers should in my application always be disabled. But, setting the visibility to "false" on *all* menu items below a certain menu one time will remove the very menu itself forever - it can never be made to come back again. So in the end, the context menu itself will be like in this image (image3), even if the selection is really a good one that should "produce" the create sub menu:

I understand that trying to control the situation using the visibility may not be a good option. I have also made some futile attempts to take control of the rendering of my MPopupMenu myself from my renderer factory, but to no avail yet.

Does anyone know how to succeed with hiding menu items according to "executability"?
  • Attachment: image1.png
    (Size: 21.73KB, Downloaded 360 times)
  • Attachment: image2.png
    (Size: 14.90KB, Downloaded 378 times)
  • Attachment: image3.png
    (Size: 12.57KB, Downloaded 396 times)

[Updated on: Fri, 15 June 2018 10:05]

Report message to a moderator

Previous Topic:Checkbox highlight
Next Topic:Top Window Trim
Goto Forum:

Current Time: Mon Apr 19 01:09:19 GMT 2021

Powered by FUDForum. Page generated in 0.02712 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top