< Day Day Up > |
Recipe 12.7 Responding to User Actions in a Plug-in12.7.1 ProblemYou want to let your plug-in respond to user actions in the Eclipse IDE. 12.7.2 SolutionCreate an action set, and support it in your plug-in's code. You can do this with the New Extension wizard. 12.7.3 DiscussionAn 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.
To create an action set which ties a menu and toolbar button to an action, click the Extension tab in the MenuPlugInFromScratch project's plug-in manifest editor, and click Add to open the New Extension wizard shown in Figure 12-15. Select Generic Wizards in the left box, select Schema-based Extension in the right box, and click Next. Figure 12-15. Using the New Extension wizardThe next dialog enables you to select the extension point on which you want to build, as shown in Figure 12-16. Because we want to create an action set to support toolbar buttons and menu items, we'll use the org.eclipse.ui.actionSets extension point. Select it, as shown in the figure, and click Finish. Figure 12-16. Selecting an extension pointWhen you click Finish, an entry for the org.eclipse.ui.actionSets extension point is added to the Extensions pane in the Eclipse manifest editor, as shown in Figure 12-17. To create a new action set, right-click org.eclipse.ui.actionSets in the All Extensions box and select New actionSet, creating a new action set, as shown in the figure. Figure 12-17. A new action setTo set the properties of this new action set, select it and, in the Properties view at the bottom of the Eclipse window, set the label property to Action Set 1 and the visible property to true, as shown in Figure 12-18. Figure 12-18. Configuring the action setThat creates the new action set. |
< Day Day Up > |