NSTreeController: do leaf and non-leaf nodes have to be of the same class?
NSTreeController: do leaf and non-leaf nodes have to be of the same class?
- Subject: NSTreeController: do leaf and non-leaf nodes have to be of the same class?
- From: Greg Hurrell <email@hidden>
- Date: Thu, 18 May 2006 19:18:53 +0200
Hi everyone,
I'm trying using NSTreeController for the first time, and my task is
to show a collection of plug-ins in an NSOutlineView.
I've made a model that consists of two classes: a "group" class and a
"plug-in" class. Groups are non-leaf nodes that can contain plug-ins
or other groups. Plug-ins are leaf nodes and can't contain anything.
This allows me to produce a structure like this:
* Group: Importer-Plugins: (contains plug-ins for importing)
* Group: Exporter-Plugins: (contains plug-ins for exporting)
And if I wish I can further subdivide each group by making it contain
subgroups and so on as many levels deep as I want.
Now, in my user interface I'd like the user to be able to click on
the disclosure triangles to see the contents of the groups. The lines
in the outline view that correspond to groups have no other
functionality. The lines in the outline view that corresponds to plug-
ins *do* have other functionality (I want to have a column with a
checkbox to enable/disable plug-ins, a column to show the plug-in
description etc).
Basically, think of the outline view in the "Key Bindings" preference
pane of Xcode: the groups there are for organizational purposes only:
the real interaction and editing gets done on the leaf nodes. Only
the first column has any many for the group nodes, the other columns
are empty. I have done this kind of thing before without bindings,
but this is my first attempt at doing it with them.
Now, when I try to set this up with NSTreeController I get runtime
errors because (obviously) my "group" class doesn't respond to
messages for things like "isEnabled" and "plugInDescription", whereas
the "plug-in" class does respond to those messages.
So my questions are basically these:
* is it possible to use NSTreeController like this? (ie. with non-
leaf nodes used for grouping purposes only)
* do I have to ditch my two-class design and switch to a design in
which all nodes (leaf and non-leaf) are the same class?
* or at the very least, do I have to put some kludgey methods in my
non-leaf class so that it responds to the expected messages? (I
briefly tried this and got rid of the runtime "valueForUndefinedKey:
this class is not key value coding-compliant for the key
displayName." error message; instead I got the slightly more cryptic
message: "valueForUndefinedKey: this class is not key value coding-
compliant for the key ." <-- not that there's no key there at all! I
tried setting a symbolic breakpoint on -[NSObject
valueForUndefinedKey:] but it doesn't really help me to figure out
what's going on as I have no idea how to interpret the content of the
registers in the debugger...)
* should I just have the non-leaf class return nil values for those
keys and configure things in IB so that the corresponding cells will
be disabled if "isLeafNode" (already implemented) returns NO?
There is very little official Apple sample code for NSTreeController
as far as I can tell. Only the "OutlineEdit" example uses
NSTreeController, and that is a CoreData-based application (mine is
not). This is the only Apple example I've been able to find of a non-
CoreData use of NSTreeController:
http://developer.apple.com/documentation/Cocoa/Conceptual/
NSXML_Concepts/Articles/UsingTreeControllers.html
And even when I start looking for third-party samples on the web, all
I find are examples which show all rows (leaf and non-leaf) returning
values for all columns in the outline view. Thanks for any help you
can give me!
Cheers,
Greg
Attachment:
smime.p7s
Description: S/MIME cryptographic signature
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden