Notice: this Wiki will be going read only early in 2024 and edits will no longer be possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.
Difference between revisions of "Sirius/Tutorials/Mindstorms/PropertiesViews"
(→Detailed script) |
|||
(7 intermediate revisions by one other user not shown) | |||
Line 19: | Line 19: | ||
== Sirius concepts== | == Sirius concepts== | ||
During this step, you will mainly use these Sirius concepts: | During this step, you will mainly use these Sirius concepts: | ||
− | * Properties Views Description | + | * '''Properties Views Description''' |
** Describes how model element are shown and edited in the Eclipse Properties Views | ** Describes how model element are shown and edited in the Eclipse Properties Views | ||
− | * Page | + | * '''Page''' |
** Corresponds to a tab in the Properties View | ** Corresponds to a tab in the Properties View | ||
− | * Group | + | * '''Group''' |
** Represents a group of widgets in a tab | ** Represents a group of widgets in a tab | ||
− | * Container | + | * '''Container''' |
** Allows to specify alternate layouts | ** Allows to specify alternate layouts | ||
− | * Fill Layout | + | * '''Fill Layout''' |
** Organizes elements inside the container either horizontally or vertically | ** Organizes elements inside the container either horizontally or vertically | ||
− | * Text widget | + | |
+ | * '''Text widget''' | ||
** Represents a single line text | ** Represents a single line text | ||
− | * Checkbox widget | + | * '''Checkbox widget''' |
** Represents a checkbox | ** Represents a checkbox | ||
− | * References widget | + | * '''References widget''' |
** Represents the value of a reference in the model | ** Represents the value of a reference in the model | ||
− | * Property validation | + | |
+ | * '''Property validation''' | ||
** Defines a validation rule linked to a specific widget. | ** Defines a validation rule linked to a specific widget. | ||
− | * Semantic validation | + | * '''Semantic validation''' |
** Define a validation rule linked to a group | ** Define a validation rule linked to a group | ||
− | * Audit | + | * '''Audit''' |
** Evaluates if a validation rule has been broken | ** Evaluates if a validation rule has been broken | ||
− | |||
− | |||
==Video== | ==Video== | ||
Watch the [https://youtu.be/iHtmL-PKT8c video] (16'45) | Watch the [https://youtu.be/iHtmL-PKT8c video] (16'45) | ||
− | [[File:MindstormsVideo5.png|link=https://iHtmL-PKT8c]] | + | [[File:MindstormsVideo5.png|link=https://youtu.be/iHtmL-PKT8c]] |
==Detailed script== | ==Detailed script== | ||
===Create a Properties View for GoForward instructions=== | ===Create a Properties View for GoForward instructions=== | ||
− | * At the root of the modeler definition create a New Properties View to define custom properties views for the instructions | + | * At the root of the modeler definition create a '''New Properties View''' to define custom properties views for the <code>instructions</code> |
− | ** Metamodels = mindstorms | + | ** '''Metamodels''' = <code>mindstorms</code> |
+ | ** Update the '''Page''' named <code>Default Page</code> (already created by default) | ||
+ | *** '''Domain Class''' = <code>mindstorms::Instruction</code> | ||
+ | *** '''Label Expression''' = <code>General</code> | ||
− | + | * Update the '''Group''' named Default Group to display and edit the '''cm''' property of '''GoForward''' | |
− | *** Domain Class = mindstorms:: | + | ** '''Id''' = <code>GoForward</code> |
− | *** Label Expression = | + | ** '''Domain Class''' = <code>mindstorms::GoForward</code> |
+ | ** '''Label Expression''' = <code>Properties</code> | ||
+ | ** Add a '''Text''' for the '''cm''' property | ||
+ | *** '''Id''' = <code>CmText</code> | ||
+ | *** '''Label Expression''' = <code>Cm</code> | ||
+ | *** '''Value Expression''' = <code>feature:cm</code> | ||
+ | *** Under '''Begin''' add a '''Set''' operation (set <code>var:newValue</code> to '''cm''') | ||
+ | ** Create a '''Conditional Style''' for '''CmText''' in order to color the text background when '''cm''' is lower than 0 | ||
+ | *** '''Precondition Expression''' = <code>aql:self.cm<0</code> | ||
+ | *** Update the '''Style''' with '''Background Color''' = <code>MindstormsColor1</code> | ||
− | |||
− | |||
− | |||
− | |||
− | + | Now, if you select a '''GoForward''' instruction and enter a negative '''Cm''' value, you should see: | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | [[File:Mindstorms-5-2.png]] | |
− | + | ||
− | + | ||
− | |||
− | |||
− | |||
+ | * Add a ''' Property Validation Rule''' to warn the user when '''cm''' is null (useless instruction). | ||
+ | ** '''Targets''' = <code>CmText</code> | ||
+ | ** '''Id''' = <code>UselessGoForward</code> | ||
+ | ** '''Level''' = <code>Warning</code> | ||
+ | ** '''Message''' = <code>This instruction is useless</code> | ||
+ | ** Create an '''Audit''' | ||
+ | *** '''Audit Expression''' = <code>aql:self.oclAsType(mindstorms::GoForward).cm<>0</code> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Now, if you select a '''GoForward''' instruction and enter a null '''Cm''' value, you should see: | |
[[File:Mindstorms-5-3.png]] | [[File:Mindstorms-5-3.png]] | ||
− | + | ===Create a Properties View for Rotate instructions=== | |
− | * Create a Group to display and edit the degrees and random properties of Rotate | + | * Create a '''Group''' to display and edit the '''degrees''' and '''random''' properties of '''Rotate''' |
− | ** Id = Rotate | + | ** '''Id''' = <code>Rotate</code> |
− | ** Domain Class = mindstorms::Rotate | + | ** '''Domain Class''' = <code>mindstorms::Rotate</code> |
− | ** Label Expression = Properties | + | ** '''Label Expression''' = <code>Properties</code> |
+ | ** Add this new group to the '''Default page''' ('''Groups''' property on this page) | ||
− | * | + | * Create a '''Container''' to put the widgets in the same line |
+ | ** Create a '''Fill Layout''' with '''Orientation''' = <code>HORIZONTAL</code> | ||
− | * | + | * Add a '''Checkbox''' for the '''random''' property |
− | *** | + | ** '''Id''' = <code>RandomCheckbox</code> |
+ | ** '''Label Expression''' = <code>Random</code> | ||
+ | ** '''Value Expression''' = <code>feature:random</code> | ||
+ | ** Under '''Begin''' create a '''Set''' operation (set <code>var:newValue</code> to '''random''') | ||
− | + | * Add a '''Text''' for the '''degrees''' property | |
− | ** | + | ** '''Id''' = <code>DegreesText</code> |
− | ** | + | ** '''Label Expression''' = <code>Degrees</code> |
− | *** Value Expression = feature: | + | ** '''Is Enabled Expression''' = <code>aql:not self.random</code> |
− | + | ** '''Value Expression''' = <code>feature:degrees</code> | |
+ | ** Under '''Begin''' create a '''Set''' operation (set <code>var:newValue</code> to '''degrees''') | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Now, if you select a '''Rotate''' instruction, the checkbox and the field should be aligned, and the check of '''Random''' should disable the '''Degrees''' field: | |
[[File:Mindstorms-5-4.png]] | [[File:Mindstorms-5-4.png]] | ||
− | |||
− | * | + | * Add a '''Semantic Validation Rule''' to warn the user when '''degrees''' is null and '''random''' is false (useless rotate instruction). |
− | ** | + | ** '''Id''' = <code>UselessRotation</code> |
− | ** | + | ** '''Level''' = <code>Warning</code> |
− | ** | + | ** '''Message''' = <code>This instruction is useless</code> |
+ | ** Create an '''Audit''' | ||
+ | *** '''Audit Expression''' = <code>aql:self.degrees<>0 or self.random</code> | ||
− | + | ==Create a Properties View for Choreographies instructions== | |
− | *** | + | * Create a '''Group''' to display and edit the '''name''' and '''instructions''' properties of '''Choreography''' |
+ | ** '''Id''' = <code>Choreography</code> | ||
+ | ** '''Domain Class''' = <code>mindstorms::Choreography</code> | ||
+ | ** '''Label Expression''' = <code>Properties</code> | ||
+ | * Add this new '''Group''' to the '''Default page''' ('''Groups''' property on this page) | ||
+ | * Add a '''Text''' for the '''name''' property | ||
+ | ** '''Id''' = <code>NameText</code> | ||
+ | ** '''Label Expression''' = <code>Name</code> | ||
+ | ** '''Value Expression''' = <code>feature:name</code> | ||
+ | ** Under '''Begin''' create a '''Set''' operation (set <code>var:newValue</code> to '''name''') | ||
+ | * Add a '''Reference''' for the '''instructions''' property | ||
+ | ** '''Id''' = <code>InstructionsRef</code> | ||
+ | ** '''Label Expression''' = <code>Instructions</code> | ||
+ | ** '''Reference Owner Expression''' = <code>var:self</code> | ||
+ | ** '''Reference Name Expression''' = <code>instructions</code> | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | Now, if you select a '''Choreography''' instruction, the properties view contains a list with action buttons: | |
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
− | + | ||
[[File:Mindstorms-5-5.png]] | [[File:Mindstorms-5-5.png]] | ||
− | + | * Add a '''Property Validation Rule''' to warn the user when the '''name''' is already used by a sibling choreography. | |
− | + | ** '''Targets''' = <code>NameText</code> | |
− | ** | + | ** '''Id''' = <code>UniqueName</code> |
− | + | ** '''Level''' = <code>Error</code> | |
− | * Id = UniqueName | + | ** '''Message''' = <code>Name must be unique</code> |
− | * Level = Error | + | ** Create an '''Audit''' |
− | * Message = Name must be unique | + | *** '''Audit Expression''' = <code>aql:not self.siblings()->filter(mindstorms::Choreography)->collect(i|i.name)->includes(self.name)</code> |
− | + | ||
− | * Create an Audit | + | |
− | ** Audit Expression = <code>aql:not self.siblings() | + | |
− | ->filter(mindstorms::Choreography) | + | |
− | ->collect(i|i.name) | + | |
− | ->includes(self.name)</code> | + | |
− | + | ||
− | + | ||
− | + | ||
==Installing the solution== | ==Installing the solution== | ||
− | The solution of this step is provided in | + | The solution of this step is provided in [https://www.eclipse.org/sirius/resources/mindstorms-tutorial/solution4.zip solution4.zip] |
'''Warning''': If you delete your current design project and load the solution, you should close the sample project and reopen it, in order the new version to be taken into account | '''Warning''': If you delete your current design project and load the solution, you should close the sample project and reopen it, in order the new version to be taken into account |
Latest revision as of 10:30, 17 September 2018
Contents
Properties Views
Objectives
Provide custom properties views for a modeling tool that allows the user to define the choreography of a Mindstorms robot.
- GoForward’s properties view
- Specific background color if Cm value is negative
- Warning if Cm value is null
- Rotate’s properties view
- Random checkbox and Degrees field aligned on the same row
- Degrees field disabled if Random is checked
- Validation rule of type Warning, testing if Degrees is equal to 0 and Random is not checked
- Two quick fixes on this rule to propose solutions
- Choreography’s properties view
- Editable list of instructions
- Validation rule of type Error, testing if Name is already used by another Choreography at the same level
Sirius concepts
During this step, you will mainly use these Sirius concepts:
- Properties Views Description
- Describes how model element are shown and edited in the Eclipse Properties Views
- Page
- Corresponds to a tab in the Properties View
- Group
- Represents a group of widgets in a tab
- Container
- Allows to specify alternate layouts
- Fill Layout
- Organizes elements inside the container either horizontally or vertically
- Text widget
- Represents a single line text
- Checkbox widget
- Represents a checkbox
- References widget
- Represents the value of a reference in the model
- Property validation
- Defines a validation rule linked to a specific widget.
- Semantic validation
- Define a validation rule linked to a group
- Audit
- Evaluates if a validation rule has been broken
Video
Watch the video (16'45)
Detailed script
Create a Properties View for GoForward instructions
- At the root of the modeler definition create a New Properties View to define custom properties views for the
instructions
- Metamodels =
mindstorms
- Update the Page named
Default Page
(already created by default)- Domain Class =
mindstorms::Instruction
- Label Expression =
General
- Domain Class =
- Metamodels =
- Update the Group named Default Group to display and edit the cm property of GoForward
- Id =
GoForward
- Domain Class =
mindstorms::GoForward
- Label Expression =
Properties
- Add a Text for the cm property
- Id =
CmText
- Label Expression =
Cm
- Value Expression =
feature:cm
- Under Begin add a Set operation (set
var:newValue
to cm)
- Id =
- Create a Conditional Style for CmText in order to color the text background when cm is lower than 0
- Precondition Expression =
aql:self.cm<0
- Update the Style with Background Color =
MindstormsColor1
- Precondition Expression =
- Id =
Now, if you select a GoForward instruction and enter a negative Cm value, you should see:
- Add a Property Validation Rule to warn the user when cm is null (useless instruction).
- Targets =
CmText
- Id =
UselessGoForward
- Level =
Warning
- Message =
This instruction is useless
- Create an Audit
- Audit Expression =
aql:self.oclAsType(mindstorms::GoForward).cm<>0
- Audit Expression =
- Targets =
Now, if you select a GoForward instruction and enter a null Cm value, you should see:
Create a Properties View for Rotate instructions
- Create a Group to display and edit the degrees and random properties of Rotate
- Id =
Rotate
- Domain Class =
mindstorms::Rotate
- Label Expression =
Properties
- Add this new group to the Default page (Groups property on this page)
- Id =
- Create a Container to put the widgets in the same line
- Create a Fill Layout with Orientation =
HORIZONTAL
- Create a Fill Layout with Orientation =
- Add a Checkbox for the random property
- Id =
RandomCheckbox
- Label Expression =
Random
- Value Expression =
feature:random
- Under Begin create a Set operation (set
var:newValue
to random)
- Id =
- Add a Text for the degrees property
- Id =
DegreesText
- Label Expression =
Degrees
- Is Enabled Expression =
aql:not self.random
- Value Expression =
feature:degrees
- Under Begin create a Set operation (set
var:newValue
to degrees)
- Id =
Now, if you select a Rotate instruction, the checkbox and the field should be aligned, and the check of Random should disable the Degrees field:
- Add a Semantic Validation Rule to warn the user when degrees is null and random is false (useless rotate instruction).
- Id =
UselessRotation
- Level =
Warning
- Message =
This instruction is useless
- Create an Audit
- Audit Expression =
aql:self.degrees<>0 or self.random
- Audit Expression =
- Id =
Create a Properties View for Choreographies instructions
- Create a Group to display and edit the name and instructions properties of Choreography
- Id =
Choreography
- Domain Class =
mindstorms::Choreography
- Label Expression =
Properties
- Id =
- Add this new Group to the Default page (Groups property on this page)
- Add a Text for the name property
- Id =
NameText
- Label Expression =
Name
- Value Expression =
feature:name
- Under Begin create a Set operation (set
var:newValue
to name)
- Id =
- Add a Reference for the instructions property
- Id =
InstructionsRef
- Label Expression =
Instructions
- Reference Owner Expression =
var:self
- Reference Name Expression =
instructions
- Id =
Now, if you select a Choreography instruction, the properties view contains a list with action buttons:
- Add a Property Validation Rule to warn the user when the name is already used by a sibling choreography.
- Targets =
NameText
- Id =
UniqueName
- Level =
Error
- Message =
Name must be unique
- Create an Audit
- Audit Expression =
aql:not self.siblings()->filter(mindstorms::Choreography)->collect(i|i.name)->includes(self.name)
- Audit Expression =
- Targets =
Installing the solution
The solution of this step is provided in solution4.zip
Warning: If you delete your current design project and load the solution, you should close the sample project and reopen it, in order the new version to be taken into account