12.7. Responding to User Actions in a Plug-in

Problem

You want to let your plug-in respond to user actions in the Eclipse IDE.

Solution

Create an action set, and support it in your plug-in’s code. You can do this with the New Extension wizard.

Discussion

An action represents an action the user can perform; for example, you can connect actions to elements such as menus and toolbars. To specify what happens when an action is activated, you extend the Action class. After you’ve created an action, you can use it in a variety of places, such as menu item selections or toolbar button clicks; the same action object will make the same thing happen in either case. An action set is, as the name implies, a set of actions. You connect actions to items such as menus and toolbars using an action set.

To develop action sets, you use extension points. An extension point lets one plug-in build on what another plug-in exports. Action sets such as those that enable you to implement menu and toolbar actions are extensions of the org.eclipse.ui.actionSets extension point.

Tip

Plug-ins can use only those classes that are exported by other plug-ins, which makes extension points especially important. Much support for custom plug-ins is already built into several standard plug-ins that come with Eclipse. To let a plug-in use your Java code, you can put that code in a .jar file; then you can wrap the .jar file inside a plug-in so that other plug-ins can access your code.

To create an action set which ties a menu ...

Get Eclipse Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.