Using context pattern in tables
When you create a TableLayout, you can have each row represent a single element in the model, with each column displaying additional information about that element. Alternatively, you can have a row of data represent a hierarchy of elements in the model. For example, you could have the first column represent high-level packages in the model, the second column represent the classes in those packages, and the third column represent the operations that are contained in those classes.
To use context patterns in tables, you must carry out two steps:
- Use the Context pattern field (reached via the Advanced Options… button on the Columns tab) to determine what types of information should be displayed in the table. (The value entered in this field is copied to the property Model::TableLayout::ContextPattern.)
- Use the Features window for TableLayouts to determine how the information should be displayed.
The ContextPattern property
The property Model::TableLayout::ContextPattern is used to determine what hierarchical data from your model should be displayed in the table. The property uses a powerful syntax, which is explained in detail in Context patterns
A
simple example of this feature would be to show packages (all levels recursively), followed by the
classes in each package, followed by the operations that are defined in each class. To display this
information in a table, you would set the value of the ContextPattern property to:
{pkg}Package*,{cls}Class,{op}Operation
. (Note that in this example, the text inside
the brackets serves as category labels and can be any text you like.)
Define the columns for the TableLayout
Once you have provided a value for the ContextPattern property to determine the content of the table, you use the Columns tab of the Features window for your TableLayout element to configure the exact appearance of the table.
On the Columns tab, the simplest way to specify the layout of the data is to use the Fill Defaults button. This option creates columns automatically based on the syntax you used for the ContextPattern property, including the order of the elements that you specified.
If you used the sample property value given previously and then click the Fill Defaults button, your TableLayout will look as follows:
If you want greater control over the columns of the table, you can use the regular controls to add one column at a time. For each column that you add, you then use the drop-down list in the Context column of the tab to select the type of information to display in that column. The labels that are displayed in the Context drop-down list are the labels that you specified in the value that you gave to the ContextPattern property. In the example that is used here, the labels are pkg, cls, and op.
The following screen captures show an example of packages in a model, and the resulting table for the TableLayout defined previously.
For more information, see the video Context patterns in Rhapsody tables.