This post originated from an RSS feed registered with Agile Buzz
by James Robertson.
Original Post: Customizing the VW Tree Widget
Feed Title: Cincom Smalltalk Blog - Smalltalk with Rants
Feed URL: http://www.cincomsmalltalk.com/rssBlog/rssBlogView.xml
Feed Description: James Robertson comments on Cincom Smalltalk, the Smalltalk development community, and IT trends and issues in general.
Supporting the new in tree view in BottomFeeder, I had to get the tree widget - the one holding the feeds and folders - to dynamically change based on attributes of the contained items. As it turns out, the tree widget already supports that quite easily - Have a look at class TreeModel. From the class comment:
childrenBlock: block with one argument. Is evaluated to get an
object's children. The result is expected to be a
SequenceableCollection. Defaults to: [:ea | ea children].
So the childrenBlock is what determines what the tree shows. Change the block, and you change the items displayed. In my case, I simply had to add query methods to the folder and feed objects. These methods look like this:
RSSFeed>>displayChildren
"custom display of items"
^#()
RSSFolder>>displayChildren
"custom display of items"
^self children select: [:each | each hasUnreadItems]
Feeds have no children; they are nodes. Folders, on the other hand have to be tested. The #hasUnreadItems method actually does the work of drilling all the way to the bottom of a given folder, in search of unread items. The main point is though - in order to change the way the tree displays, all I had to do is send this message in response to a user request:
self feedTree list childrenBlock: [:each | each displayChildren].
which replaces the default block of:
self feedTree list childrenBlock: [:each | each children]
And that's all there is to it. Modify the block that determines children to display, and create any necessary support protocol in the objects you put in the tree. I had been resisting looking at this, as I somehow convinced myself that doing this would be hard. I got constant prodding from Micahel Lucas-Smith though, and - as a result - got a new feature added to BottomFeeder