[Seaside] Generalizing WATree Update--with files selectable.

Tim Murray tmurray at ecsorl.com
Thu Aug 19 14:45:05 UTC 2010


On last update, I had a tree expanding, but only realized after posting
that it only displayed directory names.

This morning, I fixed that. Here is how.

 

First, CFileTreeDirectoryItem has no direct support for displaying file
names. However, when the CFileTreeDirectoryItem is created, a reference
to its FileDirectory object is stored 4 classes up the hierarchy in
CPlayer and is accessible via the 'value' message.

 

With the file names accessible, the problem became how to display them
in the WATree framework and make them selectable. To do this, I modified
the WACfileDirectoryTree subclass I created yesterday and did the
following:

 

I over-rode WATree's renderNode: on: method as follows.

 

renderNode: aNode on: html

 html listItem: [

  self renderNodeButton: aNode on: html.

  self renderNodeLabel: aNode on: html.

  self renderNodeChildren: aNode on: html ].

 self renderNodeFiles: aNode on:html.

 

And created a renderNodeFiles: on: method as such...

 

renderNodeFiles: aNode on: html

"aNode is a directory it has files"

  aNode value fileNames do: [:each |

   html listItem: [ 

      self renderNodeLabelLink: each

            action: (GRDelayedSend 

            receiver: self

            selector: #select:

            argument: each)

text: each

            on: html]]          

 

Then, on the component I use to display this tree to the public, in the
initialize method, I modify the selectBlock and canSelectBlock blocks as
such:

 

initialize

    super initialize.

    filetree:=WACFileDirectoryTree new

        root: (CFileDirectoryTreeItem on: FileDirectory default) ;

        labelBlock:[:cfdti | cfdti  getLabel];

        childrenBlock:[:cfdti | cfdti   getChildren ];

        selectBlock: [ :cfdti | selected := cfdti  ];

       canSelectBlock: [ :cfdti | ((cfdti class)= ByteString)
ifTrue:[true] ifFalse:[false]];

        yourself.

 

 

Which works as intended.

 

In Summary-THIS IS THE WRONG APPROACH and I only did it because I am new
to smalltalk.

 

Some points in no particular order:

1.	I am on Croquet/Squeak  Stanislov's port.
2.	CFileDirectoryTreeItem is a Tweak "thing" it does not exist in
Pharo
3.	There tweak extension was (as I could tell) the only existing
non-visual file tree data structure that  I could use, while there are
plenty of tools in the Files-Directories category for doing it, every
tool I have seen (ZipArchive) tends to roll their own.
4.	In hind-sight, I would duplicate the CFileTreeItem functionality
as a portable class without the tweak-isms rather than implement it this
way
5.	 But, live and learn ! (;

 

Hope it helps somebody.

 

t.

 

 

 

 

 

 

 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/seaside/attachments/20100819/e4f1b74d/attachment.htm


More information about the seaside mailing list