Anyone got a cleverer idea for a tree view protocol?
Anyone got a cleverer idea for a tree view protocol?
- Subject: Anyone got a cleverer idea for a tree view protocol?
- From: Graham Cox <email@hidden>
- Date: Wed, 27 Aug 2008 13:58:12 +1000
Hi all,
Not directly a Cocoa question, so forgive me for the noise, but before
I commit to the following design I wonder if anyone is able to suggest
something cleverer/cleaner. This is the best I've come up with but it
seems a bit clunky in some ways.
I have a general purpose view class that is able to generate a diagram
from any tree-structure. It's somewhat like NSTableView in that it has
a datasource that supplies it, on demand, with both structural
information and content for each cell. The data source protocol
consists of two compulsory methods:
- (unsigned) numberOfNodesInTreeLayoutView:(GCTreeLayoutView*) aView
forNodeAtIndexPath:(unsigned[]) nodeIndex indexLength:(unsigned)
indexLength;
- (id) treeLayoutView:(GCTreeLayoutView*) aView
objectValueForNodeAtIndexPath:(unsigned[]) nodeIndex indexLength:
(unsigned) indexLength;
In order to identify a specific node anywhere in the client tree
without having intimate knowledge of how that tree is really built, or
from what objects, these methods pass a list of integers which are a
"path" to a specific node. Thus, the 'nodeIndex' is really a list
'indexLength' elements long, e.g.
0,3,2,1
would mean from the root, take the zeroth subitem, then the third,
then the 2nd, then the 1st to arrive at the node at that point. An
empty list (0 length) addresses the root node itself.
If the real tree is implemented with arrays, these are simply the
array indexes at each level. If some other data structure, the
datasource would need to interpret them. While this handles any tree
with any number of nodes and subnodes, I can't help feeling that there
must be an easier or more straightforward way to specify a given node
without having to use a list. This also has the disadvantage that the
datasource needs to traverse the tree from the root to the addressed
node each time data is requested.
Any thoughts or comments?
tia,
cheers, Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden