Hide/show toolbar items on perspective switch

There are three alternatives to hide resp. show toolbar items when switching the perspective in Eclipse RCP.

  • Simply using the PerspectiveListener.

  • Using a dummy actionSet. The actionSet will be active if the appropriate perspective is active, too. The actionSet can then be simply used for further expressions.

<visibleWhen>
  <with variable="activeContexts">
    <iterate operator="or">
      <equals value="my.action.set.id"/>
    <iterate>
  </with>
</visibleWhen>
  • Using a source variable of the EvaluatorService.
final IEvaluationService evaluationService = (IEvaluationService) PlatformUI.getWorkbench().getService(IEvaluationService.class);
evaluationService.addSourceProvider(sp);
super.postStartup();