Code example
This model implementation differs somewhat from the other ULC model classes in that it assumes the domain object is an adapter for the tree displayed: UlcTreeModel expects its domain instance to represent the entire tree. Model attributes must be set to selectors implemented in the domain model rather than to a node directly. The node is passed as a parameter with each of the selectors. Example code follows:
|treeModel box| (treeModel := UlcTreeModel new) childCountSelector: #numberOfSubclassesOf:; childrenSelector: #subclassesOf:; iconSelector: #iconOf:; labelSelector: #labelFor:; model: someObject. (box := UlcBox new) add: (UlcTree new treeModel: treeModel; yourself). UlcShell new add: box
The following attributes of UlcTreeModel must be configured:
The values are all selectors that take one parameter. They are sent to the UlcTreeModel domain model with the object for which the information is required.
To display the Smalltalk class hierarchy, the model representing the entire hierarchy implements the following:
#numberOfSubclassesOf: aClass "attribute <childCountSelector>" "answer the number of direct subclasses of aClass" ^aClass subclasses size #subclassesOf: aClass "attribute <childrenSelector>" "answer the collection of aClass' subclasses" ^aClass subclasses #hierarchyRootOf: aClass "attribute <rootSelector>" "answer the root class of aClass" |theClass| theClass := aClass. [theClass superclass notNil] whileTrue: [theClass := theClass superclass]. ^theClass
For an example of using this part in the Composition Editor, see Working with Tree Model parts.