Sunday, October 25, 2009

Section 17.1.  Overview










17.1. Overview


Before introducing declarative actions, let's take a step back and look at what an action is all about. The primary role of actions is to expose application behavior to the user. When you click on a menu item or toolbar item or invoke a key sequence, an action is run. Further, you can set up a system such that the same action is placed in a menu, a toolbar, and bound to a key sequenceactions allow you to separate behavior from placement. Actions also determine if they are enabled, figure out what elements to work on, run the work, and display the results.


Below is a list of the basic responsibilities of actions. As you explore the various ways of defining and using actions, remember that these responsibilities apply regardless of how or where they are defined and usedonly the syntax is different.


Placement Actions can be placed in many areas of the Workbench: in views, editors, context menus, and in top-level menus and toolbars. When they are created, they are given a reference to the container in which they are placed, allowing them to query for selection or access other information.

Rendering There are several types of actions, for example, menus, toolbar buttons, radio buttons, drop-down menu buttons, and so on. When you create an action, you have to decide what type of action it is and how it will be rendered in the UI. Actions also contain basic information, such as a label, an icon, and a tool tip, which is used in displaying and describing the action to the user.

Input and enablement Actions usually perform work on a set of objects. The input to an action is defined by the selection in the related UI part. For example, if an action is in a view, then the related selection is that of the widgets in the view. An action in the Workbench window uses the selection that comes from the active view or editor. As an action's context changes (e.g., its input changes or its container state changes), the action must update its enablement state.

Behavior When an action is eventually run, it performs some operation on its input. If the action is long-running, it should show progress to the user.

Binding An action can be controlled by the keyboard instead of by its explicit UI element. Actions can also be bound to other mechanisms that control when they are run.


When you add an action, you have to implement each of these responsibilities. Figure 17-1 shows how the "Build" action from the IDE product implements these responsibilities.



Figure 17-1. Action responsibilities

[View full size image]




The Build action is placed in the top-level toolbar and menu, it is rendered as a push button with a name and image, it's enabled when at least one project is selected, and its input is the selected project. Its behavior is to build the selected project.












No comments:

Post a Comment