Search code examples
eclipseeclipse-pluginswteclipse-rcpjface

How to disable/enable view toolbar menu/action in Eclipse Plugin Development


I have view that extends ViewPart. In this view, I want to add toolbar menu.

What I know, we can add toolbar menu by using ActionContributionItem or Action, and add it to ToolBarMenu from createPartControl method in ViewPart.

But what I don't know is this: How can we disable/enable the toolbar menu programmatically?

So basically, I want to add Play, Stop, and Pause button to toolbar view. So at first, the Play button is on enabled mode, and the others are disabled. When I pressed Play button, it is disabled, and others will be enabled.

For more details, what I want to achieve is something like the following image.

In the red circle are disabled button, and in the blue circle are enabled button.

View


Solution

  • Instead of using Actions, have a look at Eclipse commands (they are the replacement for actions and function in a cleaner way): http://help.eclipse.org/indigo/topic/org.eclipse.platform.doc.isv/guide/workbench_cmd.htm

    You will see in the documentation that you can enable and disable a command and all places where it's used will properly update their state automatically.