CoreData and NSTreeController
CoreData and NSTreeController
- Subject: CoreData and NSTreeController
- From: Duncan Wilcox <email@hidden>
- Date: Tue, 7 Jun 2005 09:27:30 +0200
Hi, I'm trying to grok coredata. Given a two level hierarchy model like:
Workspace:
- selection ->> Page
Page:
- parent <<-> Page (inverse with children)
- children <->> Page
- figures <->> Figure (inverse with Figure.page)
Figure:
- parent <<-> Figure (inverse with children)
- children <->> Figure
- page <<-> Page
I have a NSArrayController hooked up to the Workspace entity, and I'm
trying to persistently store the current selection of the
NSTreeController that's hooked up to the page entity, by binding an
NSOutlineView's selectionIndexPaths to the Workspace.selection
relationship. If I interpret the error messages I see correctly, it
looks like the Workspace.selection relationship is instantiated as a
NSCFArray, whereas the selectionIndexPaths wants an NSSet. Do I fix
this with a value transformer, or by modeling the relationship
differently, or what else?
I'd also like to only allow adding page children to a "page folder"
entity, I guess I should be able to do this through a
NSValueTransformer that transforms the current page selection into a
bool, and binding it to the "add" button's enabled property. A better
solution, which I guess can be implemented only in code, is to add
the new page to the parent folder.
Another issue, the Figure entity should be viewable both as a
hierarchy and as a bitmap rendering of the various Figure sub-entities.
For the hierarchy, I tentatively instantiated another
NSTreeController, but I don't see an obvious way to hook it up to the
first NSTreeController's selection, and I'm unsure about what
predicate I should set (aside from parent == nil) to ensure that only
Figures that point to the currently selected page are visible to the
controller. What I think I want is a way to reference the other
NSTreeController in the predicate, though I realize it's a different
context and it makes no sense.
Do I need some code for hooking up the Figure.page relationship? I
guess I'm looking for a parametric predicate setup, that the
controller class would use both for filtering entities and setting up
the correct attribute values so that the newly created instance
matches the filter.
For the bitmap, looking at mmalc's GraphicsBindings I think I have to
observe every Figure's attribute. Does this play well with undo/redo?
(GraphicsBindings doesn't have undo).
Assuming I can't ask an NSTreeController to instantiate different
kinds of Figures (circle, square, text, etc), should I manually
instantiate them via initWithEntity:insertIntoManagedObjectContext:
and somehow hand it over to the NSTreeController? In the
NSTreeController docs I also see an insert: operation, documented as
"Creates a new object of the class specified by objectClass and
inserts it into the receiver’s content". What objectClass?
Finally, I suppose that to setup bindings in IB for my own custom
views the only possibility is to create an IB palette for my views?
Thanks,
Duncan
_______________________________________________
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