18.5.2 Listing presentations
There are three ListingPresentations available: List, Tree and Table. Each of these expects the result of evaluating the transformation on a given input entity (by using display:
) to be a list.
In the case of the ListPresentation, this list is then mapped on the elements in the list widget to be displayed. For example, to display the namespaces from a MooseModel in a list you can use:
browser transmit to: #namespaces; andShow: [ :a |
a list
display: [ :model | model allNamespaces ] ].
A TablePresentation goes along the same line, only it adds the possibility to also add columns using column:evaluated:
. For example, if we want to display the number of classes in each namespace, we can do it like:
browser transmit to: #namespaces; andShow: [ :a |
a table
display: [ :model | model allNamespaces ];
column: 'Namespaces' evaluated: [ :each | each mooseName ];
column: 'NOCls' evaluated: [ :each | each classes size asString ] ].
A TreePresentation is slightly different. The list to be displayed will appear as root elements in the tree. Thus, if we want to show the tree of all namespaces, in the display block we have to select only the root ones and then specify the children (using children:
) for each of the namespaces:
browser transmit to: #namespaces; andShow: [ :a |
a tree
display: [ :model | model allNamespaces select: [ :each | each isRoot ] ];
children: [ :namespace | namespace childScopes ] ].
The ListingPresentations also offer further options. First, we can specify how to deal with the selection. In this area we can say if we want the selection to beSingle
(the default option) or to beMultiple
. When multiple selection is wanted, the result of populating the #selection
port is a collection. Yet another selection related issue is to allowDeselection
of the current selection. If the listing is set to allow deselection, when deselecting the #selection
port is set to nil
.
Second, we have the possibility to ask for an input box that acts as a filter (using filterOn:
) or as a search box (using searchOn:
). Both accept as parameter a block that takes each element of the list as input and returns a true or false. The effect of the filter box is to trim the visible items based on the selection. The effect of the search box is to select the desired item and to populate the #selection
port. For example, in the Moose Finder (see Section 5.2) the group view offers a search box with which we can select the wanted elements in the group. Once selected, the #selection
port is populated appropriately.
Third, it is sometimes impractical to show an entire list, especially when we deal with very large lists. In such situations it is better to show only a limited amount of items by using showOnly:
. For example, this can be seen in the Moose Finder where we typically do not show more than 50 elements by default.
Finally, we also have the possibility to add tags to the items of a list by using tags:
.
icon
input and output ports: #selection, #strongSelection, #selectedPath