Skip navigation.
 
mlRe: NSTreeController filter contents
FROM : Michael Hanna
DATE : Tue Jun 24 19:33:17 2008

So how does your tree controller know how to return FilteredItem
instead of Item? I thought you have to return the model class for the
object controller that you set in the nib file. Also, how did you
manage to avoid duplicating subclasses of Item?

I tried a very simple form of filtering on the children method:

- (NSMutableArray *)children
{
    NSAssert( m_guid != nil, @"unexpected nil value for m_children" );

    NSLog(@"m_children %@", m_children);
    NSMutableArray* filteredChildren = [NSMutableArray array];

    NSEnumerator* en = [m_children objectEnumerator];

    MFST_TreeElement* element = nil;
    while ( element = [en nextObject] )
    {
        if( [element enabled] )
        {
            [filteredChildren addObject:element];
        }

    }

    NSLog(@"filteredChildren %@", filteredChildren);

    //return filteredChildren;

    return m_children;
}

TreeElement is a superclass of RuleGroups and RuleElement. RuleGroups
is a non-leaf node, and RuleElement is a leaf node.

So in the code above if I comment-out "return m_children" and
un-comment filteredChildren, the NSTreeController doesn't draw
anything! Both arrays are empty. I find this bizarre behavior. But
running the code as it is returns the unfiltered array(which, in the
end isn't what I want). So I'm a bit unclear as to what to do next.
You used proxies to avoid this problem?

Michael

On Mon, Jun 23, 2008 at 6:09 PM, Jens Alfke <<email_removed>> wrote:
>
> On 23 Jun '08, at 5:10 PM, Michael Hanna wrote:
>

>> How do I filter-out the contents of an NSTreeController? I saw an
>> example with NSArrayController by overriding the [NSArrayController
>> -arrangeObjects] method, but NSTreeController doesn't have this
>> method.

>
> I asked about this a month or two ago, and the consensus seemed to be that
> there isn't any built-in way to filter the contents of the tree.
>
> I've ended up doing the filtering myself. If we call my regular tree model
> class Item, then I've created a class FilteredItem. This acts as a proxy for
> an Item, but its -children method filters out the children I don't want to
> display, and returns FilteredItem proxies for those I do.
>
> —Jens

Related mailsAuthorDate
mlNSTreeController filter contents Michael Hanna Jun 24, 02:10
mlRe: NSTreeController filter contents Jens Alfke Jun 24, 03:09
mlRe: NSTreeController filter contents Michael Hanna Jun 24, 19:33
mlRe: NSTreeController filter contents Jens Alfke Jun 24, 20:18