Re: Bind NSOutlineView to database ( newbie )
Re: Bind NSOutlineView to database ( newbie )
- Subject: Re: Bind NSOutlineView to database ( newbie )
- From: matt neuburg <email@hidden>
- Date: Mon, 10 Feb 2003 08:55:33 -0800
On Mon, 10 Feb 2003 01:49:52 -0500, Alvaro Muir <email@hidden> said:
>
Sorry for the repeat newbie question. I asked this a few
>
weeks ago and
>
seemed to have missed any responses
Typically when no one answers a question it is because the question seems incoherent or too elementary to warrant any response other than "RTFM". Sometimes it's because the question is too hard or outside everyone's experience. Sometimes it's chance.
>
Has anyone ever had
>
success in binding NSOutline View to a database?
Cocoa does not support "binding". If you want to display a database's data in an outline view, load the data from the database, munge it into a form suitable to function as the datasource of the outline, and display it. You may not be able to arrange to get an automatic notification of any kind when the database changes, so you might have to refresh the data manually from time to time.
>
Here's an example DB:
>
>
vehicleID | manufacturer | make | color
>
__________________________________________________________
>
000012 Ford Mustang yellow
>
000013 Ford Mustang white
>
000121 Mercedes C240 green
>
000132 Mercedes E420 silver
>
023202 Honda Civic blue
>
022242 Honda CRV orange
>
032023 Foo Bar purple
>
032023 Foo Bar black
>
023205 Foo Bar neon-green
>
>
>
And I would like NSOutline view to display this information, in the order I
>
specify... I.e.
>
>
>
Ford
>
-> Mustang
>
-> yellow
>
-> Mustang
>
->white
>
Foo
>
-> Bar
>
-> purple
>
-> Bar
>
-> Black
>
-> Bar
>
-> neon-green
>
>
Blah, blah . . . .
What you're trying to do is rather arbitrary; why not, e.g.
Ford
-> Mustang
-> yellow
-> white
However, as I said before, once you've settled on how the rectangular data from the database needs to be transformed into a tree-like structure suitable for an outline, you transform it, and there you are.
If you don't understand how to display an outline at all, look at the documentation, and at the OutlineView example which is on your hard disk. Basically you designate a datasource which is then asked Four Big Questions. Your job is to answer those questions correctly and quickly, so make sure your datasource has access to the data in a form such that you can do this. Also, some of the Big Questions are answered by handing Cocoa a reference to an actual item; this reference will come back to you as part of the posing of other Questions, so make sure the answers are somehow available directly by looking at the item reference you're handed. This is why a tree-like structure is a good thing. By "tree-like" I mean for example an array where each element of the array is some text (to be displayed in the outline) and another array (representing the subheads of that text). Given such a structure, it's easy to answer the Big Questions quickly.
To transform rectangular structure of a database into this tree-like structure, a simple strategy is to sort the rectangular structure and pass down it one line at a time, putting an entry in the appropriate place in the tree depending on what changes.
matt neuburg, phd = email@hidden,
http://www.tidbits.com/matt
pantes anthropoi tou eidenai oregontai phusei
Subscribe to TidBITS! It's free and smart.
http://www.tidbits.com/
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.