contents of ListModel´s

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

contents of ListModel´s

marco-2
Hello,

I would like to set an OrderedCollection with objects (see down) into
a ListModel, but i´m only able to put Strings into the
OrderedCollection, which will be shown in the ListBox. Of course i
have to collect the contents of the attributes (name). But what about
the way back, generating new TSDMethod´s???

Object: TSDMethod
attribute: name (aString)

Marco


Reply | Threaded
Open this post in threaded view
|

Re: contents of ListModel´s

Ian Bartholomew-8
Marco,

> I would like to set an OrderedCollection with objects (see down) into
> a ListModel, but i´m only able to put Strings into the
> OrderedCollection, which will be shown in the ListBox.

You can use a collection of any type of object if the object knows how to
display itself using #printOn: Using the Point class as an example -

oc := OrderedCollection
    with: 1@1
    with: 2@2
    with: 3@3
    with: 4@4.
ListPresenter showOn: (ListModel on: oc)

>            Of course i
> have to collect the contents of the attributes (name). But what about
> the way back, generating new TSDMethod´s???
>
> Object: TSDMethod
> attribute: name (aString)

You just have to implement something like the following, which will allow
you to use a collection of TSDMethods directly in the list and not have to
worry about generating new objects.

TSDModel>>printOn: aStream
    aStream nextPutAll: name

An alternative is to change the #getTextBlock for the ListView so that it
accesses the #name aspect of the object.  You should use this method if you
want to dispay the object in different ways.  The following examples are
done programaticallly but you would normally edit the resource the
ViewComposer.

oc := OrderedCollection
    with: 1@11
    with: 2@22
    with: 3@33
    with: 4@44.

Normal - use the default Point>>printOn:

lp := ListPresenter show.
lp model list: oc.

Display the x field in the list

lp := ListPresenter show.
lp view getTextBlock: [:o | o x printString].
lp model list: oc

Display the sum of the two fields

lp := ListPresenter show.
lp view getTextBlock: [:o | (o x + o y) printString].
lp model list: oc

You can manually select something in the list and see that the point is
answered. So the following answers a Point object

lp selection

Therefore, as your TSDModel>>name already answers a String,  you would just
have to do.

lp := ListPresenter show.
lp view getTextBlock: [:o | o name].
lp model list: (ListModel on: aCollection of TSDModels)

Hope that helps
    Ian