e4 RCP: Manipulating Menu when switching between perspectives

339 views Asked by At

I am looking for a way how to manipulate the main menu of an e4 RCP application. The menu should have different items enabled, depending on the current Perspective.

So far, I came up with the solution to use the @CanExecute annotation for each menu handler to check for the active perspective like so:

@CanExecute
public boolean canExecute(MPerspective activePerspective) {
    return (activePerspective.getElementId().equals("somePerspectiveName"));
}

Is there any better way how to do this?

1

There are 1 answers

0
greg-449 On BEST ANSWER

If you just want to control if the menu item is enabled/disabled what you have is OK.

You can control the visibility of the menu item by specifying a 'Visible-When Expression' in the 'Handled Menu Item' entry in the Application.e4xmi. Here you specify the id of a 'core expression' defined using the org.eclipse.core.expressions.definitions extension point.