Re: NSPredicateEditorRowTemplate and CoreData
Re: NSPredicateEditorRowTemplate and CoreData
- Subject: Re: NSPredicateEditorRowTemplate and CoreData
- From: Peter Ammon <email@hidden>
- Date: Thu, 16 Oct 2008 12:20:16 -0700
On Oct 16, 2008, at 3:56 AM, Arved von Brasch wrote:
Hello Cocoa Dev List,
I'm loving NSPredicateEditor and what it lets you do. I'm wondering
about the best way to manage what I want to do:
I want a Pop-Up Pop-Up Pop-Up template row, where the last view is
populated by every item of a particular CoreData Entity. The entity
has one attribute, 'name', that should be the display item, but the
objects themselves (or at least their URL ID) should be part of the
predicate, so that the predicate can follow the object should the
name attribute change. I'm expecting to parse the predicate tree
when I want to use it to replace the object instance with its name
attribute.
That part is relatively easy to set up in a
NSPredicateEditorRowTemplate subclass. I'm using an IBOutlet link
to an NSArrayController which has all the items to populate the list
with. Overriding templateViews to populate the last view with the
appropriate values. This seems a little kludgy, but works well
enough. If there's a better solution, I'd love to hear it!
That's a fine approach. You can also just create a new RowTemplate
and set it on the NSPredicateEditor every time your list of items
changes.
What's troubling me is the edge case where there are no objects of
the particular entity in the database. I think the best option
would be to prevent the associated Row Template from being
selectable from the left hand side Pop-Up, but I can't seem to find
any way to do that.
There's no way to, say, disable the item, but you can remove it
entirely by just removing that RowTemplate from the predicate editor's
array of row templates.
There is a potential problem I can see with removing the item from
the left hand side Pop-Up anyway, namely, what happens if a
previously saved predicate is given to the predicate editor. Is
there an elegant solution to this?
What you can do here is have a "fallback" template, that is, another
template capable of showing the predicate. If you load a predicate
that references an item in the database that no longer exists, the
fallback can display something generic instead. You would implement
this by having multiple templates nonzero for matchForPredicate:, with
the fallback returning the smaller value.
You can also just preprocess the predicate to excise or replace
predicates that no longer apply.
If no template claims the ability to show a particular predicate, then
the predicate editor will complain (but does not raise an exception in
Leopard), and then ignore the the predicate.
Hope this helps,
-Peter
_______________________________________________
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