简体   繁体   中英

The submenu is present in the UI (I'm able to see it). But, when I try to access it programmatically, I'm not getting that submenu

We are having a view, with pulldownmenu items (Group by, Grouped by). 'Group by' has sub-menu which are the columns in the views. When any of the submenu is selected, THe view entries will be grouped with the column and also there will be a entry added to 'Group by' Menu.

We are having a util method of signature:

public static void clickPullDownMenuItem(String viewID, String menu){
display.asyncExec(new Runnable() {

  @Override
  public void run() {
    IViewPart viewPart = getView(viewID);
    MenuManager mainMenuManager = (MenuManager) viewPart.getViewSite().getActionBars().getMenuManager();
    IContributionItem[] items = mainMenuManager.getItems();
    //iterate to through the items and invoke the action of the item.
  }
  Thread.sleep(2000);
}

I use the below calls to simulate the same.

1. clickPullDownMenuItem(viewID, "Group by/Resource")
2. clickPullDownMenuItem(viewID, "Grouped by/Resource")

After the first statement is executed I am able to see the 'Resource' entry in the 'Grouped by' menu. But, when the second statement is being executed, I'm getting no items under 'Grouped by' in the above method.

The thing I don't understand is the submenu is present in the UI (I'm able to see it). But, when I try to access it programmatically, I'm not getting that submenu.

Use the findUsingPath to find a contribution item matching a path - particularly one containing a '/':

IMenuManager manager = viewPart.getViewSite().getActionBars().getMenuManager();

IContributionItem item = manager.findUsingPath(menu);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM