J. P. L. Martín wrote:

Hello, I'm having trouble to figure out how to do this, I have a simple
window with 3 buttons, each button should change the content listed on the
list below them but I'm really not sure about how to do it.

This is the code for the window:
---
open
    "Abre la ventana principal del Sistema de Gestion Bibleotecaria"

    | builder contain |
    builder := UITheme builder.
    contain := builder newColumn: {builder newRow: {
            builder newButtonFor: self action: #onPrestamosClick label:
'Prestamos'  help: ''.
            builder newButtonFor: self action: #onMaterialesClick label:
'Materiales'  help: ''.
            builder newButtonFor: self action: #onSociosClick label:
'Socios'  help: ''}.
            builder newColumn: {
            builder newListFor: self list: nil selected: nil
changeSelected: nil  help: '' }.}.

    (contain  openInWindowLabeled: 'Babel') extent: 600@600.
---

How should I define #onLabelClick to set the list to for example: Prestamo
database.

Thanks in advance.

J. P. L. Martín wrote:
Actually the code of the GUI is inspired on the Pharocast video on the
making of a Contact list. I wonder if the list is static since is defined
there as a newListFor and because that you can't send any message to it,
The #changed: method tells the list to get its contents again - see example below.
I'm sure there should be a way to do it so #onPrestamosClick look like:
---
#onPrestamosClick
    listMorph list: Prestamo database.
---
or something like that.


You didn't explicitly state your references, I presume you a referring to http://www.pharocasts.com/2011/02/pharo-gui-with-polymorph.html. Note that ContactManager-LaurentLaffront.1.mcz referred to from this post uses...

|builder newListFor: self list: #contacts
               selected: #contactSelectedIndex
               changeSelected: #contactSelectedIndex:
               help: ''.|

whereas you have...

builder newListFor: self list: nil selected: nil changeSelected: nil help: '' which is the key part you are missing, where the (list: #contacts) defines the method to return the list contents, for example...
---
#contacts
   ^ Contact database collect: [:aContact|
       ', ' join: {aContact lastName.  aContact firstName}
   ].
---


You have defined your list contents as (list: nil), whereas if it was (list: #selectedDatabase) the following might work...
---
#onPrestamosClick

   selectedDatabase := Prestamo database.
   self changed: #selectedDatabase.
---
#selectedDatabase
        ^selectedDatabase.

---

good luck,
cheers -ben


Reply via email to