The Actions Editor is where you configure what users can do in an MDriven application; use it when you need to create, name, place, enable, or define the result of a Global, Class, or ViewModel action.
Open the Actions Editor
In ViewModel Editor, open the Actions area and select the action type you want to work with. The editor shows a list of actions and a rendered preview of the available menu structure.
You can select an action in either of two ways:
- Select it in the action list to edit its settings.
- Select it in the rendered menu preview to find the corresponding action definition.
When an action brings up a ViewModel, the rendered preview can show a ViewModel icon. Select that icon to open the ViewModel selected by the action. This is useful when checking that a navigation action points to the intended form.
Choose the action type
Actions represent user interaction. They are not a replacement for business logic in the model. Put reusable business rules in class functions, then let an action invoke the appropriate behavior or navigate the user to a ViewModel.
| Action type | Use it when | Example |
|---|---|---|
| Global action | The action belongs in the application's global menu. | Create a PersonSeeker action that opens the PersonSeeker ViewModel from the top menu.
|
| Class action | The action applies to objects of a particular class and should be available wherever that type is in context. | Create ShowPerson for Person. It is available when the current context is a Person.
|
| ViewModel action | The action is specific to a ViewModel and its context. | Create ShowDetails for one ViewModel without making it available for every object of the same class elsewhere.
|
For an overview of action scope and execution, see Documentation:Actions.
Configure an action
Select an action and set the properties that describe its presentation and behavior. The exact properties available depend on the action type and what the action does.
Name the action
Give the action a meaningful name. The name is used in the rendered action/menu preview and can also be used to connect a ViewModel action to an action column.
For example, name an action ShowPerson when it opens a person form, rather than using a technical or ambiguous name such as Action1.
Control whether the user can use it
Use the enabled expression to define when an action is available. The expression is evaluated in the action's context.
For example, an action that requires a selected object should only be enabled when its context provides the required object. Test the action in the rendered UI after changing the expression, because a Class action can appear or disappear as the type context changes.
You can also provide hint text for enabled and disabled states. Hint text is presented as additional information to the user, such as a tooltip on a button or in a sidebar. Use it to explain the action's result or why it is unavailable.
Define what happens when the action runs
Under the settings that describe what the action does, configure one of the following behaviors:
- Execute an OCL expression through EAL when the action must perform work in its current context.
- Select a standard framework action such as save, cancel, undo, or redo when that is the required behavior.
- Set Bring Up ViewModel when the action should navigate to a ViewModel.
For example, set Bring Up ViewModel to PersonSeeker on a Global action named PersonSeeker. In the rendered menu, use the ViewModel icon to verify that it opens the PersonSeeker ViewModel definition.
To add the standard Save, Cancel, Refresh, Undo, Redo, and Exit actions, use Ensure Std Actions in the Global actions view. See Documentation:Standard actions for the behavior of each standard action.
Present a ViewModel as a modal window or popup
When an action brings up a ViewModel, its presentation settings can specify a modal window or a popup.
- A modal window presents the ViewModel with actions such as Cancel and OK at the bottom. The user can close it with its close control.
- A popup presents the selected ViewModel as a compact contextual view. It does not provide the same close, Cancel, and OK presentation as a modal window. If the user changes data, the application can request a save-or-cancel decision when the popup is dismissed.
Use a popup for contextual information or an auxiliary task, such as showing a selected person's description from a table. Use a modal window when the task needs explicit confirmation or cancellation.
Global actions appear in the Global menu. Use menu groups to organize them into menu levels, and use sort order to control their order within a group.
- Add or select a Global action.
- Enter the action name.
- Set MenuGroup to place the action in a group.
- To create a submenu below an existing group, use a slash-separated group name. For example,
Views/Submenuplaces the action underSubmenuwithinViews. - Set Sort order in group values to strings that sort in the order you need. For example, assign
AAAtoShowViewAllThingsandBBBtoANameto show the first action before the second. - Check the rendered menu preview, then save and check the running application.
Use DividerGroupWithinMenu to introduce visible sections in a menu. Actions with the same divider-group value belong to the same section. Use sort order, not the action creation order, when a specific order matters.
An action appears in one menu location. For example, moving a Global action into IControlTheMenuGrouping/AtAllLevels removes it from the top level and presents it under that submenu.
Use Class actions in the correct type context
A Class action belongs to a class, so it is available when the current context has that class type. This makes it suitable for behavior that should follow the object rather than one specific ViewModel.
For example, if a nested ViewModel has type Person, the available Person Class actions appear in that context. If you change that nesting's class to Car, Person actions no longer apply and Car actions become available instead. Restore the nesting class before saving if Person is the intended context.
When a grid needs to show objects of type B but expose actions defined for type A, configure Act As For Actions on the nested ViewModel. The expression must navigate from B to zero or one A object. For example, use self.A when B has an association to A. This lets B act as A when MDriven determines which Class actions to expose. See Documentation:Act as For Actions for the full pattern.
Put actions in nested ViewModels and tables
An action column adds a button to a nested ViewModel. You can connect that button to either a Class action or a ViewModel action.
| Approach | When to use it | Key requirement |
|---|---|---|
| Class action | The button should execute behavior defined for the nested object's class. | Create the Class action, then select the action column and link it to that action. |
| ViewModel action | The button should execute behavior specific to the current ViewModel. | The action column name must exactly match the ViewModel action name. Do not link the ViewModel action to the column. |
For example, create an action column named ShowPerson and a ViewModel action also named ShowPerson. The matching names make the column execute that ViewModel action automatically.
See Documentation:Adding Buttons in Nested ViewModels for the complete procedure and Documentation:Web client actions in tables for table-specific web-client behavior.
Check your action before publishing
Before you save the model, verify the following:
- The action type matches its intended scope: global, class, or ViewModel.
- The name describes what the user will do.
- The enabled expression permits the action only in valid contexts.
- The execute expression, standard action, or Bring Up ViewModel setting defines the intended result.
- Menu group, divider group, and sort order produce the intended Global menu layout.
- A navigation action points to the intended ViewModel.
- An action column has the correct Class-action link or the exact matching ViewModel-action name.
