drop-down-menuradio-buttontoolbarrcpe4

E4 RCP How to set selection of ToolBarItem that contains Radio Buttons


In Eclipse E4 (Luna), using the application model to create parts, handlers, commands, handled menu items etc, (these are not created programatically). I have a toolbar. This contains a sub-Menu item called "Filter" that contains another sub-menu of two filters. The two filters are two Handled Menu Items which are set up as "Radio" Buttons.

When I select the appropriate in the UI of my running app from the selection, the Radio button switches just fine to the selected Item. However I would like this selection to update (deselecting one Radio button and selecting the appropriate radio button of the handled menu item) when my ViewPart changes through other UI selection. Currently my ViewPart updates, but the Radio buttons are on the same previous selection through the UI.

Is there a way in which I get access both Handled Menu Item's IDs and set the selection (one to false, the other to true) when the viewer is updated.

Image of design is attached below: Toolbar item containing handled menu items

Hierarchy of the application model is as follows: hierarchy

Thanks in advance,

Marv


Solution

  • I solved this by starting with MPart PartID and drilling down to the HandledMenuItems on which I wanted to set the Radio Button selections, then setting the selection property for each individual HandledMenuItem.

    This can probably be refactored to be more concise, but I've left the code with each step to have the solution easier to read.

    BTW, in every instance / combination of the EModelService methods, the list returned a size of 0. So I'm not certain if that will work for what I'm trying to achieve. The following does work, although I'm not certain it is the most efficient means.

    I hope this helps others.

        // Get view part
        MPart viewPart = _partService.findPart("part_id");
    
        //  get list of all menu items from the Part
        List<MMenu> viewPartMenu = viewPart.getMenus();
    
        // Get list of ViewMenus from viewPartMenu there is only one View Menu so it will be index 0
        MMenu viewMenu = viewPartMenu .get(0);
    
        // Get list of MMenuElements from the viewMenu - the children in the view menu
        List<MMenuElement> viewMenuElements = viewMenu.getChildren();
    
        // This gets me to the 2 HandledMenuItems 
        // Upper Most HandledMenuItem Radio Button is at viewMenuElements index 0.  This is cast to MHandledMenuItem
        MHandledMenuItem upperHandledMenuItem = (MHandledMenuItem) viewMenuElements.get(0);
    
        // Set Selection 
        upperHandledMenuItem.setSelected(false);
    
        // Lower Most HandledMenuItem Radio Button is at viewMenuElements index 1.  This is cast to MHandledMenuItem
        MHandledMenuItem lowerHandledMenuItem = (MHandledMenuItem) viewMenuElements.get(1);
    
        // Set selection 
        lowerHandledMenuItem.setSelected(true);