Mic
Mic

Reputation: 61

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

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?

Upvotes: 1

Views: 1051

Answers (2)

Simiil
Simiil

Reputation: 2311

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

Upvotes: 0

msteiger
msteiger

Reputation: 2044

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.

Upvotes: 2

Related Questions