ListPresenter Newbie Help

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

ListPresenter Newbie Help

acg
Hi all -
I'm working thru Dolphin Smalltalk Companion with Release 4.01.
For my own experimentation,
I set have set up a Model (instance variable  'choices' which contains a
SortedCollection, #('a' 'b' 'c'), and a instance variable 'selected' to contain
the chosen member. Also have a Presenter ( under Shell) with a
ListPresenter,combo box which will drop down and show the contents of the
'choices' properly and the INDEX of the chosen member in a TextPresenter
properly with:
  'selectedPresenter selection: self (choicesPresenter selectionByIndex) '

but I can not seem to show the selected member itself, ie.:
   'selectedPresenter selection: self (choicesPresenter selection) '  does NOT
work. But this same code does work for Ver 2.1 !!!

Can anyone suggest something, or should I submit more code ?

Thanks in advance
Andy


Reply | Threaded
Open this post in threaded view
|

Re: ListPresenter Newbie Help

Louis Sumberg-2
Andy,

I think the problem in your code is the use of 'self', in fact I don't see
how either line could ever have worked.  Try taking out 'self'.  Assuming
that selectedPresenter is a TextPresenter, you need to use #value:, not
#selection:.  For fun or other experimentation, going through the following
may help.

"Create shellview with textedit and listview"
shell := Shell show.
shell view extent: 200@200.
shell view layoutManager: BorderLayout new.
textView := shell view addSubView: TextEdit new.
textView arrangement: #north.
textPresenter := TextPresenter new view: textView.
cbView := shell view addSubView: ComboBox new.
cbView arrangement: #center.
choicesPresenter := ListPresenter new.
choicesPresenter list: #('a' 'b' 'c').
choicesPresenter view: cbView.
"Setup event handling"
block := [textPresenter value: (choicesPresenter selection, choicesPresenter
selectionByIndex displayString)].
choicesPresenter when: #selectionChanged send: #value to: block.

-- Louis

"AndrewGinMD" <[hidden email]> wrote in message
news:[hidden email]...
> Hi all -
> I'm working thru Dolphin Smalltalk Companion with Release 4.01.
> For my own experimentation,
> I set have set up a Model (instance variable  'choices' which contains a
> SortedCollection, #('a' 'b' 'c'), and a instance variable 'selected' to
contain
> the chosen member. Also have a Presenter ( under Shell) with a
> ListPresenter,combo box which will drop down and show the contents of the
> 'choices' properly and the INDEX of the chosen member in a TextPresenter
> properly with:
>   'selectedPresenter selection: self (choicesPresenter selectionByIndex) '
>
> but I can not seem to show the selected member itself, ie.:
>    'selectedPresenter selection: self (choicesPresenter selection) '  does
NOT
> work. But this same code does work for Ver 2.1 !!!
>
> Can anyone suggest something, or should I submit more code ?
>
> Thanks in advance
> Andy


Reply | Threaded
Open this post in threaded view
|

Re: ListPresenter Newbie Help

Ian Bartholomew-6
In reply to this post by acg
Andy,

[..]
> but I can not seem to show the selected member itself, ie.:
>    'selectedPresenter selection: self (choicesPresenter selection) '  does
> NOT work. But this same code does work for Ver 2.1 !!!
>
> Can anyone suggest something, or should I submit more code ?

I'm not 100% sure what you are trying to do (and the code fragments you
posted weren't quite right - typos?) so we might need some more code, but
one possibility it that you may be having a problem with the default search
policy used for ListModels. To demonstrate try the following in a
workspace -

list := #('a' 'b' 'c').
lp := ListPresenter show.
lp model list: list.
lp selection: (list at: 2)

That works as expected, the second item in the list is selected. Now try the
following, which looks very similar -

list := #('a' 'b' 'c').
lp := ListPresenter show.
lp model list: list.
lp selection: 'b'

This time you get a walkback saying the object, 'b', cannot be found in the
list.

The difference is caused by the default search policy for a ListModel -
#identity. This means that to match an item in the list the item you must
compare it with another item that is identical (answers true to #==). In the
first example this works, you are searching for the String object that was
in the original list. In the second case this does not work as you are
searching for a String object that is equal (#= answers true) but not
identical (#== answers false).

list := Array with: 'a' with: (b := 'b') with: 'c'.
(list at: 2) == b.  --> true
(list at: 2) == 'b'  --> false

How to fix it?. You could either change both lists (I think you have two
lists in your example??) to contain the same collection or change the search
policy for the ListModel to #equality, as below. The ListModel now just
checks for items that answer true to #= so locates the required entry in the
list without error.

list := #('a' 'b' 'c').
lp := ListPresenter show.
lp model list: list.
lp model searchPolicy: SearchPolicy equality.
lp selection: 'b'

or

list := #('a' 'b' 'c').
lp := ListPresenter showOn: EqualityListModel new.
lp model list: list.
lp selection: 'b'

Regards
    Ian


acg
Reply | Threaded
Open this post in threaded view
|

Re: ListPresenter Newbie Help

acg
In reply to this post by Louis Sumberg-2
Louis-
Thanks for suggestions on ListPresenter,
I'll try
Andry


acg
Reply | Threaded
Open this post in threaded view
|

Re: ListPresenter Newbie Help

acg
In reply to this post by Ian Bartholomew-6
Ian
Thanks for suggestions on my ListPresenter quesiton.I'' try your suggestions.
Andy


acg
Reply | Threaded
Open this post in threaded view
|

Re: ListPresenter Newbie Help

acg
In reply to this post by Ian Bartholomew-6
>
>I'm not 100% sure what you are trying to do (and the code fragments you
>posted weren't quite right - typos?) so we might need some more code, but
>one possibility it that you may be having a problem with the defaul

Sorry for the typos.. late night..I submitted the code. And your suggestions
have help
get me past the problem.


acg
Reply | Threaded
Open this post in threaded view
|

Re: ListPresenter Newbie Help

acg
In reply to this post by Louis Sumberg-2
>
>I think the problem in your code is the use of 'self', in fact I don't see
>how either line could ever have worked.  Try taking out 'self'.  Assuming
>that selectedPresenter is a TextPresenter, you need to use #value:, not
>#selection:.  For fun or other experimentation, going through the following
>may help.
>
>"Create shellview with textedit and listview"
>shell := Shell show.
>shell view extent: 200@200.
>shell view layoutManager: BorderLayout new.
>textView := shell view addSubView: TextEdit new.
>textView arrangement: #north.
>textPresenter := TextPresenter new view: textView.
>cbView := shell view addSubView: ComboBox new.
>cbView arrangement: #center.
>choicesPresenter := ListPresenter new.
>choicesPresenter list: #('a' 'b' 'c').
>choicesPresenter view: cbView.
>"Setup event handling"
>block := [textPresenter value: (choicesPresenter selection, choicesPresenter
>selectionByIndex displayString)].
>choicesPresenter when: #selectionChanged send: #value to: block.

Louis-- sorry about the typos.. I did submitt the code later, and tried your
suggestions. Yours and Ian's have gotten me to understand the issues better
Thanks for your time,
Andy