You can use the Alf editor to create an Alf body for the effect Behavior of a Transition in a State Machine or to edit the existing Alf body of an effect Behavior.
To create an Alf body for an effect Behavior
- Open the Specification window for the Transition (from the Model Browser or as represented on a State Machine diagram).
In the Effect section, click on the Behavior Type property and select Activity or Opaque Behavior. Enter a name for the new Behavior into the Name field for it.
It is actually optional to enter a name for the new Behavior. If the Behavior is an Opaque Behavior, and the Opaque Behavior Display Mode symbol property of the Transition is set to Body, then the Alf code will be displayed for the Behavior in the label of the owning Transition on a State Machine diagram. However, if the Behavior is an Activity, this symbol property does not apply, and it is always the Activity name that is displayed. Therefore, if you use an Activity for an effect Behavior, you should always give it a name, so that this can be shown in its representation on a State Machine diagram.- Close the Specification window.
- Select the Transition (either in the Model Browser or as it appears on a State Machine diagram) and open the Alf editor window (select Windows > Alf), if it isn't already open.
Enter the Alf code for the effect Behavior and press Save to compile and save it.
The Alf code for an effect Behavior can access attribute values of the context Classifier of the State Machine containing its Transition (using Alf this expressions). It can also access the data in the Event occurrence that triggered its execution (e.g., the attribute data of a received Signal).
To edit the Alf code for an effect Behavior
- Select the Transition (in the Model Browser or as represented on a State Machine diagram) and open the Alf editor window (select Windows > Alf), if it isn't already open. The Alf code will appear in the window.
If you create an effect Behavior as an Opaque Behavior, then Alf code for it can also be entered or edited directly in the Body and Language property for it in the Specification window for the Transition. If you open the Edit Body and Language window, then the Alf code may be edited just as in the Alf editor window. However, instead of Save and Revert buttons, this window has OK and Cancel buttons, either of which will close it. If you press OK, then the text is saved, and, if it has no errors, compiled. If you press Cancel, the Alf text is not saved.
Editing Alf code for a Transition effect Behavior in an Opaque Behavior body
To be recognized as Alf code, the Body of an Opaque Behavior must have the Language Alf. If your project was created using the Alf project template, then Alf will be the default language. Otherwise, select Alf from the Language menu (you may have to scroll upwards in the menu to find the selection for Alf).
To make Alf the default language for Opaque Behaviors
- Select Options > Project.
- On the left, under Default model properties, select Opaque Behavior.
- Click on the Language field and then on the small + button on the right.
- Enter Alf (spelled and capitalized in exactly that way) and click on OK.
- Click on OK to close the options window.