## Actions and contributions

The action classes allow you to define user commands independently from their presentation in the UI. This gives you the flexibility to change the presentation of an action in your plug-in without changing the code that actually performs the command once it has been chosen. The contribution classes are used to manage the actual UI items representing the commands. You don't program to the contribution classes, but you will see them in some of the workbench and JFace API.

### Actions

An action (IAction) represents a command that can be triggered by the end user. Actions are typically associated with buttons, menu items, and items in tool bars.

Although actions do not place themselves in the UI, they do have UI oriented properties, such as tool tip text, label text, and an image. This allows other classes to construct widgets for the presentation of the action.

When the user triggers the action in the UI, the action's run method is invoked to do the actual work. A common pattern in the run method is to query the workbench selections and manipulate the objects that are selected. Another common pattern is to launch a wizard or dialog when an action is chosen.

You should not directly implement the IAction interface. Instead, you should subclass the Action class. Browse the subclasses of this class to see many of the common patterns for actions. The code below implements the "About" action. It is one of the simpler actions in the workbench.

       public void run() {
          new AboutDialog(workbenchWindow.getShell()).open();
       }

Earlier we saw the workbench interfaces IViewActionDelegate and IEditorActionDelegate. These interfaces are used when contributing view actions or editor actions to the workbench. The workbench action delegates are initialized with a reference to their associated view or editor. With this knowledge, they can navigate to the workbench page or window, accessing selections or any other information needed to perform the action.

You will implement your own action classes whenever you want to define a command in your plug-in. If you are contributing actions to other views and editors, you will implement action delegates.

### Contribution items

A contribution item (IContributionItem) represents the UI portion of an action. More specifically, it represents an item that is contributed to a shared UI resource such as a menu or tool bar.

Contribution items know how to fill a specific SWT widget with the appropriate SWT item that represents the contribution.

You don't have to worry about creating a contribution item when you are contributing actions to the workbench UI. This is done on your behalf when the workbench creates UI items for the actions that you have defined.

### Contribution managers

A contribution manager (IContributionManager) represents a collection of contribution items that will be presented in the UI. You can add and insert contribution items using named contribution ids to place the items in the appropriate order. You can also find items by id and remove individual items.

Each implementation of IContributionManager knows how to fill a specific SWT widget with its items. JFace provides contribution managers for menus (IMenuManager), tool bars (IToolBarManager), and status lines (IStatusLineManager).

As a plug-in developer, you do not need to implement these interfaces, but you will see references to some of these managers in API methods.