Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Seaside Tutorial - queries

44 views
Skip to first unread message

Sanjay Minni

unread,
Apr 29, 2012, 8:27:59 AM4/29/12
to
Hi - Pls help on Seaside Todo Tutorial, I am stuck on the piece of code below.

The tutorial is designed for Pharo - Please help me with the correct understanding and approach for the equivalent piece of code on D6

Pg 4 - Components - page link:
http://www.hpi.uni-potsdam.de/hirschfeld/seaside/tutorial?_s=TN41Dn8nJg7w9byo&_k=FX9H1Vx-6lQacdtl

Piece of code where I am stuck

StRootComponent>>#initializeListComponent
...
self listComponent
sortBlock: [:items |
items sortBy: [:a :b | a deadline < b deadline]];...
...

items is an OrderedCollection of StTasks which has a message deadline
Other relevant code done before:

... items:= OrderedCollection
with: (StTask new
deadline: Date yesterday)
with: (StTask new
deadline: Date today)
with: (StTasks ....)

Question:
Should I be using SortedCollection here ? what is the correct approach / equivalent under D6

Thanks
Sanjay

john c

unread,
Apr 29, 2012, 10:18:02 AM4/29/12
to
On Apr 29, 8:27 am, Sanjay Minni <sanjay.mi...@gmail.com> wrote:
> Hi - Pls help on Seaside Todo Tutorial, I am stuck on the piece of code below.
>
> The tutorial is designed for Pharo - Please help me with the correct understanding and approach for the equivalent piece of code on D6
>
> Pg 4 - Components - page link:http://www.hpi.uni-potsdam.de/hirschfeld/seaside/tutorial?_s=TN41Dn8n...
>
> Piece of code where I am stuck
>
> StRootComponent>>#initializeListComponent
> ...
> self listComponent
>   sortBlock: [:items |
>    items sortBy: [:a :b | a deadline < b deadline]];...
> ...
>
> items is an OrderedCollection of StTasks which has a message deadline
> Other relevant code done before:
>
> ... items:= OrderedCollection
>                with: (StTask new
>                        deadline: Date yesterday)
>                with: (StTask new
>                        deadline: Date today)
>                with: (StTasks ....)
>
> Question:
> Should I be using SortedCollection here ? what is the correct approach / equivalent under D6
>
> Thanks
> Sanjay

sanjay,

i think D6 would be aNewSortedCollection := items asSortedCollection:
[:a :b | a deadline < b deadline]. you can also define a SortAlgorithm
as an argument and then items asSortedCollectionUsing: the
sortAlgorithm instance.

i'm a relative newbie so there maybe other options.

john

Chris Uppal

unread,
May 1, 2012, 3:33:25 AM5/1/12
to
Sanjay Minni wrote:

> self listComponent
> sortBlock: [:items |
> items sortBy: [:a :b | a deadline < b deadline]];...

If you add a loose method something like:

sortBy: a2Block
^ (self asSortedCollection: a2Block]) asOrderedCollection.

to class SequencableCollection then you'll get the behaviour of the
Pharo/Squeak #sortBy:

FWIW, in Pharo Collection>>sortBy: has been deprecated for some time (I think
replaced by Collection<<sorted:), and of course it doesn't exist in Dolphin at
all, so you may be better off chosing your own idiom and using that.

Anyway, the idea is to get a new collection which is sorted, but isn't actually
a SortedCollection. The difference (which may or may not be important for your
code, or for Seaside) is that adding new elements won't automatically sort them
into the correct position.

-- chris


0 new messages