[Prev][Next][Index][Thread]
Re: <tree-node> in DUIM
oodl@my-deja.com writes:
> The <tree-node> class is listed in the DUIM documentation as being
> an "Open abstract instantiable class". I should be able to call
> make on it, right?
I'm not sure about this as I've never created a <tree-node>. Perhaps
the documentation is just wrong.
> I am not sure how to populate a <tree-control> with children so I
> would appreciate having an example showing how to populate the
> control with pre-existing children, not only with children generated
> from a method like this: method (x) vector(x * 2, 1 + (x * 2)) end
> as they do in the sample code.
Here is an example cut from a program I did. I don't know if it is the
best way but it's the way I did it as a <tree-control> newbie. The
programs displays details on horse races and results in a race
meeting. The tree control displays something like:
- Meeting
|--- + Race 1
|--- + Race 2
|--- - Race 3
|----|--- + Horse 1
|--- + Horse 2
|--- + Horse 3
|--- - Horse 4
|-------- Various Horse details
These are all existing classes modelled like:
define class <meeting> (<object>)
slot meeting-races;
end;
define class <race> (<object>)
slot race-horses;
end;
define class <horse> (<object>)
slot horse-details;
end;
The classes are populated from database queries in a lazy manner
(ie. They are virtual slots, making the queries if the results have
not been retrieved yet).
The table-control was created as:
make(<tree-control>,
roots: all-meetings,
label-key: race-view-label-generator,
children-generator: race-view-child-generator);
all-meetings contains a list of <meeting> classes.
There were methods specialised on the different types:
define method race-view-child-generator(object :: <object>)
#[]
end method race-view-child-generator;
define method race-view-child-generator(meeting :: <meeting>)
sort(meeting.meeting-races,
test: method(a, b)
a.race-track < b.race-track
end method;
end;
define method race-view-child-generator(r :: <race>)
r.race-horses
end;
define method race-view-child-generator(h :: <horse>)
h.horse-details;
end;
define method race-view-child-generator(hd :: <horse-details>)
#[];
end;
define method race-view-label-generator(s :: <string>)
s
end method race-view-label-generator;
define method race-view-label-generator(m :: <meeting>)
format-to-string("%s - %s", m.meeting-date, m.meeting-title)
end method race-view-label-generator;
define method race-view-label-generator(r :: <race>)
// Extract and return race name
end method race-view-label-generator;
define method race-view-label-generator(h :: <horse>)
// Extract and return horse name
end method race-view-label-generator;
define method race-view-label-generator(hd :: <horse-details>)
// Extract and return horse details name
end method race-view-label-generator;
Typed from memory and it's been a while since I've used <tree-control>
but hopefully you get the idea.
Chris.
--
http://www.double.co.nz/dylan
References: