Eclipse 4 RCP Application (standalone!): Add “show view” in menu

时光毁灭记忆、已成空白 提交于 2019-12-08 07:45:19

问题


In my standalone RCP Application (which I start using a product configuration) I would like to add a menu entry "show view" that lists all views I have defined in my persistent application model (an application.e4xmi file) being closed. Currently I do not have any Advisor Classes in use.

What I did was to manually add HandledMenuItems for each view and added a CoreExpression as Visible-When Expression.

This expression tests for a special key value pair in the application context. The problem here is that I would need a special expression for each view.

What would be a good pattern to solve this problem? Or is there a way to parametrize the core expression? Could I use any predefined eclipse plugins / commands / handlers?

Update: Instead it would also be okay to have the Window > Show View structure in my standalone RCP application - exactly like it exists in the Eclipse workbench. Is there a way to add this menu (entry) by using any predefined / available means?


回答1:


I'm not sure if this helps you, because it's eclipse 3.7 code, but you can give it a try.

I added a dynamic menu contribution to the View menu like so:

<menu id="x.y.menu.views label="%menu.window.label">
  <dynamic class="x.y.menu.ViewListMenuContribution" id="viewlist" />
</menu>

In that class, I used one of the the eclipse menu factories to actually fill the menu:

@Override
public void fill(Menu menu, int index)
{
    super.fill(menu, index);

    IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
    IContributionItem item = ContributionItemFactory.VIEWS_SHORTLIST.create(window);

    if (item != null)
        item.fill(menu, index);
}

This should show all views that are currently closed.




回答2:


There is currently no way to do that, except keeping track of the parts yourself and reopening them with the EPartService



来源:https://stackoverflow.com/questions/16123345/eclipse-4-rcp-application-standalone-add-show-view-in-menu

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!