ApplicationActionBarAdvisor中列出的RCP应用程序显示菜单

时间:2014-08-01 07:14:42

标签: java eclipse eclipse-plugin eclipse-rcp

我需要一些帮助来显示我的RCP应用程序中的菜单。我知道有两种显示菜单的方法

1. By specifying the <extention point> in plugin.xml
2. By including the menus in the ApplicationActionBarAdvisor.java

我能够查看plugin.xml文件中指定的菜单,但无法查看ApplicationActionBarAdvisor.java类中指定的菜单。我需要在plugin.xml中指定任何设置才能反映出来吗?下面是ApplicationActionBarAdvisor

中的代码
public class ApplicationActionBarAdvisor extends ActionBarAdvisor {


private IWorkbenchAction saveAction ;
private IWorkbenchAction saveAsAction ;



private IWorkbenchAction introAction;
private MenuManager newMenu;
//

// Actions - important to allocate these only in makeActions, and then use
// them
// in the fill methods. This ensures that the actions aren't recreated
// when fillActionBars is called with FILL_PROXY.

public ApplicationActionBarAdvisor(IActionBarConfigurer configurer) {
    super(configurer);
}

public void makeActions(IWorkbenchWindow window)
{

    this.saveAction = ActionFactory.SAVE.create(window) ;
    this.register(this.saveAction) ;
    this.saveAsAction = ActionFactory.SAVE_AS.create(window) ;
    this.register(this.saveAsAction) ;

    //this.introAction = ActionFactory.INTRO.create(window) ;
    //this.register(this.introAction) ;
    newMenu = new MenuManager("&New", "new");

}

 protected void fillMenuBar(IMenuManager menuBar)
 {

     final MenuManager fileMenu = new MenuManager("&File", "fi");
     final MenuManager editMenu = new MenuManager("&Edit", "edit");
     final MenuManager helpMenu = new MenuManager("&Help", "maskithelp");

     fileMenu.add(newMenu) ;
     fileMenu.add(this.saveAction) ;
     fileMenu.add(this.saveAsAction) ;           
 }
}

非常感谢上述任何帮助。在此先感谢

2 个答案:

答案 0 :(得分:0)

您可以通过覆盖

指定ActionBarAdvisor中要使用的WorkbenchWindowAdvisor
public ActionBarAdvisor createActionBarAdvisor(IActionBarConfigurer configurer)

方法

您的WorkbenchWindowAdvisor必须在WorkbenchAdvisor中通过覆盖:

指定
public WorkbenchWindowAdvisor createWorkbenchWindowAdvisor(
        IWorkbenchWindowConfigurer configurer)

必须在

上的WorkbenchAdvisor中指定IApplication
PlatformUI.createAndRunWorkbench(display, advisor);

呼叫。

必须在IApplication扩展点的<run class="application">元素中指定org.eclipse.core.runtime.applications

您必须运行此应用程序或使用org.eclipse.core.runtime.products产品,该产品在<product application="application"元素中指定应用程序。

答案 1 :(得分:0)

好的,这可能有点晚了,但从我看到的你忘记添加新创建的菜单管理器, fileMenu editMenu helpMenu fillMenuBar 方法中的 menuBar 菜单管理器:


protected void fillMenuBar(IMenuManager menuBar) {

     final MenuManager fileMenu = new MenuManager("&File", "fi");
     final MenuManager editMenu = new MenuManager("&Edit", "edit");
     final MenuManager helpMenu = new MenuManager("&Help", "maskithelp");

     fileMenu.add(newMenu);
     fileMenu.add(this.saveAction);
     fileMenu.add(this.saveAsAction);

     // these calls are missing
     menuBar.add(fileMenu);
     menuBar.add(editMenu);
     menuBar.add(helpMenu);
}