子菜单出现在UI中(我能够看到它)。但是,当我尝试以编程方式访问它时,我没有得到该子菜单

时间:2015-06-12 08:58:12

标签: java eclipse-plugin

我们有一个视图,有pulldownmenu项目(Group by,Grouped by)。 '分组依据'有子菜单,它们是视图中的列。当选择任何子菜单时,视图条目将与列分组,并且还会在“分组依据”菜单中添加一个条目。

我们有一个签名的util方法:

import matplotlib.pyplot as plt
import numpy as np

parameters = [2, 3]
t = np.linspace(0, 5, 501)

f_all = plt.figure()
a_all = f_all.add_subplot(111)

for p in parameters:
    fig = plt.figure()
    ax = fig.add_subplot(111)
    l, = ax.plot(t, np.sin(p*t)/p,
                 label='$\\omega=%d,\\quad{p}_0=%5.3f$'%(p,1./p))
    ax.legend()
    fig.savefig('pippo_%d.png'%p)
    a_all.add_line(l)

[newline.set_transform(a_all.transData) for newline in a_all.lines]

a_all.set_xlim(0,5)
a_all.set_ylim(-1,1)

a_all.legend()
f_all.savefig('pippo_a.png')

我使用以下调用来模拟相同的操作。

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);
}

执行第一个语句后,我可以在'Grouped by'菜单中看到'Resource'条目。 但是,当第二个语句被执行时,我在上面的方法中没有得到“Grouped by”下的项目。

我不明白的是UI中存在子菜单(我能够看到它)。但是,当我尝试以编程方式访问它时,我没有得到该子菜单。

1 个答案:

答案 0 :(得分:0)

使用findUsingPath查找与路径匹配的贡献项 - 尤其是包含' /':

的项目
IMenuManager manager = viewPart.getViewSite().getActionBars().getMenuManager();

IContributionItem item = manager.findUsingPath(menu);