Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 220
Agung Pratama Avatar asked Jun 04 '26 01:06

Agung Pratama


2 Answers

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.

like image 161
Francis Upton IV Avatar answered Jun 06 '26 03:06

Francis Upton IV


There is another approach which I found by stumbling upon on google. This approach is using ISourceProvider to provide variable state. So we can provide the state of enablement/disablement of command in that class (that implementing ISourceProvider). Here is the detail link http://eclipse-tips.com/tutorials/1-actions-vs-commands?showall=1

like image 22
Agung Pratama Avatar answered Jun 06 '26 04:06

Agung Pratama