Skip navigation.
 
mlRe: advice on filtering TreeNode objects
FROM : Alex Rice
DATE : Sun Nov 03 22:48:24 2002

On Sunday, November 3, 2002, at 05:33  AM, Andreas Mayer wrote:

> Am Sonntag, 03.11.02 um 09:42 Uhr schrieb Alex Rice:
>

>> I need to apply a filter to the root treenode and have it filter all
>> the children on some condition, like hiding todo items that are
>> completed, for example. I'm sure I can code it for that particular
>> case, but I would rather implement a general-purpose filtering
>> scheme, so I can expand it to keyword searching or other filters
>> later on. I just can't conceptualize how to do it. Seems like there
>> must be a design pattern here. Any suggestions?

>
> IMHO filtering is not a feature of a tree data structure but one of
> your particular data stored inside that tree. So I wouldn't build it
> into the TreeNode class but in the data source of your outline view.
>
> If filtering is a common task in your app a filter protocol seems the
> way to go.


Thanks for responding, but I'm not really understanding you. Here are
some more relevant details.

The data class is a Todo item class, with accessors for it's state,
notes, due date, etc. The data class inherits from TreeNode. It's class
signature is:
@interface ToDoItem : TreeNode <NSCoding>

Any filtering of the content shown by the NSOutlineView would
necessarily have to override the behavior of the TreeNode class,
especially these methods, right?

- (int) numberOfChildren;
- (NSArray*) children;

It's likely that all of the methods in the TreeNode interface would
have to be changed to correctly handle filtering. So if all methods
need to be overridden, it may as well be a feature of the TreeNode
interface, or as you say, a protocol which TreeNode could implement.

The ToDoItem class itself does not have any knowledge of parent/child
relationships- that's all inherited from the TreeNode class. My
implementation of NSOutlineViewDataSource just calls methods in the
TreeNode interface to return the correct item the NSOutlineView.

Also what is a filter protocol? It's not in my Design Patterns book,
unless it's called by another name. Do you have any examples you can
point me to?

Alex Rice <<email_removed>>
Mindlube Software
http://mindlube.com/
_______________________________________________
cocoa-dev mailing list | <email_removed>
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

Related mailsAuthorDate
mladvice on filtering TreeNode objects Alex Rice Nov 3, 09:42
mlRe: advice on filtering TreeNode objects Andreas Mayer Nov 3, 13:33
mlRe: advice on filtering TreeNode objects Alex Rice Nov 3, 22:48
mlRe: advice on filtering TreeNode objects Mike Shields Nov 3, 23:28
mlRe: advice on filtering TreeNode objects Chris Giordano Nov 4, 18:16
mlRe: advice on filtering TreeNode objects Andreas Mayer Nov 5, 05:38
mlRe: advice on filtering TreeNode objects Alex Rice Nov 5, 18:57