Spec ListModel synchronization

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

Spec ListModel synchronization

Rob Rothwell
Hello,

It's been a while since I tried out Pharo.  I always struggled with Morphic UI's, but I noticed Spec and there seemed to be enough examples floating around that I thought I'd give it another try.

Is Spec "here to stay?"  Is it worthwhile to figure it out?  It seems like with the developing possibilities of OSWindow-SDL2, one might use Spec to compose native widgets as well.

My main question is about synchronizing domain changes with a Spec UI.

For example, if I create an empty list of items:

aList := OrderedCollection new.

And create and open a ListModel that uses that list:

aListModel := ListModel new
items: aList;
openWithSpec;
yourself.

I get a nice empty list.

If I add an item to my list:

aList add: 1.

Then I need to update the list with another:

aListModel items: aList.

To see it show up.

Alternatively (this seems wrong), I can add an item to the ListModel listItems directly:

aListModel items: (aListModel listItems add: 1; yourself).

Is that basically what you need to do to maintain synchronization between your domain list and the Spec UI representation of that list, or am I missing something?

Thank you,

Rob
Reply | Threaded
Open this post in threaded view
|

Re: Spec ListModel synchronization

jfabry
Hi Bob,

to answer your 2 questions briefly:

Yes, Spec is here to stay for good, and the idea is that it can compose any kind of widgets, so with a bridge to OSWindow-SDL2 that should work as well.

When changing items in the list, you need to inform the widget of that. To do that you need to call the updateList method on your ListModel instance. So in your example:

aList add: 1.
aListModel updateList.

HTH,

On Mar 30, 2016, at 13:19, Rob Rothwell <[hidden email]> wrote:

Hello,

It's been a while since I tried out Pharo.  I always struggled with Morphic UI's, but I noticed Spec and there seemed to be enough examples floating around that I thought I'd give it another try.

Is Spec "here to stay?"  Is it worthwhile to figure it out?  It seems like with the developing possibilities of OSWindow-SDL2, one might use Spec to compose native widgets as well.

My main question is about synchronizing domain changes with a Spec UI.

For example, if I create an empty list of items:

aList := OrderedCollection new.

And create and open a ListModel that uses that list:

aListModel := ListModel new
items: aList;
openWithSpec;
yourself.

I get a nice empty list.

If I add an item to my list:

aList add: 1.

Then I need to update the list with another:

aListModel items: aList.

To see it show up.

Alternatively (this seems wrong), I can add an item to the ListModel listItems directly:

aListModel items: (aListModel listItems add: 1; yourself).

Is that basically what you need to do to maintain synchronization between your domain list and the Spec UI representation of that list, or am I missing something?

Thank you,

Rob



---> Save our in-boxes! http://emailcharter.org <---

Johan Fabry   -   http://pleiad.cl/~jfabry
PLEIAD and RyCh labs  -  Computer Science Department (DCC)  -  University of Chile

Reply | Threaded
Open this post in threaded view
|

Re: Spec ListModel synchronization

Stephan Eggermont-3
In reply to this post by Rob Rothwell
In Pharo5, you can download Ancestry from the Catalog browser,
that provides an example of this. https://vimeo.com/158063568

Stephan




Reply | Threaded
Open this post in threaded view
|

Re: Spec ListModel synchronization

Rob Rothwell
Thanks Stephan, this is a very nice example of lots of Spec usage that I'm sure I can learn a lot from!

As far as refreshing the list view, you did the same thing that I found to work by using the ListModel>>items: message, which in your case was very natural because you are creating a new, filtered list after a new person has been added.

Thanks again for pointing this out to me,

Rob

On Mar 30, 2016, at 1:42 PM, Stephan Eggermont <[hidden email]> wrote:

In Pharo5, you can download Ancestry from the Catalog browser,
that provides an example of this. https://vimeo.com/158063568

Stephan





Reply | Threaded
Open this post in threaded view
|

Re: Spec ListModel synchronization

Rob Rothwell
In reply to this post by jfabry
Thanks Johan, for your reply.

That's great that there is a path forward with Spec; I think I'll be able to figure it out!

I'll have to dig deeper into updateList, because right now the only thing it seems to do for me is clear any list selections, so I'm not sure if there is supposed to be a relationship between the original collection passed to the ListModel with the items: message or not.

Thanks again,

Rob

On Mar 30, 2016, at 12:34 PM, Johan Fabry <[hidden email]> wrote:

Hi Bob,

to answer your 2 questions briefly:

Yes, Spec is here to stay for good, and the idea is that it can compose any kind of widgets, so with a bridge to OSWindow-SDL2 that should work as well.

When changing items in the list, you need to inform the widget of that. To do that you need to call the updateList method on your ListModel instance. So in your example:

aList add: 1.
aListModel updateList.

HTH,

On Mar 30, 2016, at 13:19, Rob Rothwell <[hidden email]> wrote:

Hello,

It's been a while since I tried out Pharo.  I always struggled with Morphic UI's, but I noticed Spec and there seemed to be enough examples floating around that I thought I'd give it another try.

Is Spec "here to stay?"  Is it worthwhile to figure it out?  It seems like with the developing possibilities of OSWindow-SDL2, one might use Spec to compose native widgets as well.

My main question is about synchronizing domain changes with a Spec UI.

For example, if I create an empty list of items:

aList := OrderedCollection new.

And create and open a ListModel that uses that list:

aListModel := ListModel new
items: aList;
openWithSpec;
yourself.

I get a nice empty list.

If I add an item to my list:

aList add: 1.

Then I need to update the list with another:

aListModel items: aList.

To see it show up.

Alternatively (this seems wrong), I can add an item to the ListModel listItems directly:

aListModel items: (aListModel listItems add: 1; yourself).

Is that basically what you need to do to maintain synchronization between your domain list and the Spec UI representation of that list, or am I missing something?

Thank you,

Rob



---> Save our in-boxes! http://emailcharter.org <---

Johan Fabry   -   http://pleiad.cl/~jfabry
PLEIAD and RyCh labs  -  Computer Science Department (DCC)  -  University of Chile