Spec TreeModel dynamic contents

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

Spec TreeModel dynamic contents

webwarrior
I want to make a tree using TreeModel that reacts to changes in underlying data - when an item changes, tree node for that item should update its state (recompute its children, etc.).

Rebuilding the whole tree is ok, as long as selections and collapsed/expanded state of nodes are preserved.

Using #updateTree however resets all these things. And there is no easy way to save/load them either - #selectedItems/#selectedItems: work with TreeNode instances that get reset, and collapsed/expanded states of nodes are simply unaccessible from TreeModel.

I also tried subclassing TreeNodeModel. But I found no way to update underlying UI widget. There is a huge mess involving TreeNodeModel, MorphicTreeNodeAdapter, SpecTreeNodeModel, and MorphTreeNodeMorph.

The only option left is to extract all needed information from TreeNodeModel hierarchy (preserving the tree structure) before update, and then try to reapply it to newly created hierarchy.

Or is there an easier way?
Reply | Threaded
Open this post in threaded view
|

Re: Spec TreeModel dynamic contents

Nicolai Hess


2015-05-19 18:04 GMT+02:00 webwarrior <[hidden email]>:
I want to make a tree using TreeModel that reacts to changes in underlying
data - when an item changes, tree node for that item should update its state
(recompute its children, etc.).

Rebuilding the whole tree is ok, as long as selections and
collapsed/expanded state of nodes are preserved.

Using #updateTree however resets all these things. And there is no easy way
to save/load them either - #selectedItems/#selectedItems: work with TreeNode
instances that get reset, and collapsed/expanded states of nodes are simply
unaccessible from TreeModel.

I also tried subclassing TreeNodeModel. But I found no way to update
underlying UI widget. There is a huge mess involving TreeNodeModel,
MorphicTreeNodeAdapter, SpecTreeNodeModel, and MorphTreeNodeMorph.

The only option left is to extract all needed information from TreeNodeModel
hierarchy (preserving the tree structure) before update, and then try to
reapply it to newly created hierarchy.

Or is there an easier way?


Not that I know of. I tried to change PharoLauncher to reselect the current item if you rename or recreate
an image. But I could not find a way :(

 


--
View this message in context: http://forum.world.st/Spec-TreeModel-dynamic-contents-tp4827440.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Spec TreeModel dynamic contents

Thierry Goubier
Hi,

I believe that you need to work a bit more at the Morphic level;
MorphTreeMorph and MorphTreeNodeMorph have everything you need. The
problem seems to be in the way Spec provides an API for those features
(or does not provide an API).

Regards,

Thierry

Le 20/05/2015 20:28, Nicolai Hess a écrit :

>
>
> 2015-05-19 18:04 GMT+02:00 webwarrior <[hidden email]
> <mailto:[hidden email]>>:
>
>     I want to make a tree using TreeModel that reacts to changes in
>     underlying
>     data - when an item changes, tree node for that item should update
>     its state
>     (recompute its children, etc.).
>
>     Rebuilding the whole tree is ok, as long as selections and
>     collapsed/expanded state of nodes are preserved.
>
>     Using #updateTree however resets all these things. And there is no
>     easy way
>     to save/load them either - #selectedItems/#selectedItems: work with
>     TreeNode
>     instances that get reset, and collapsed/expanded states of nodes are
>     simply
>     unaccessible from TreeModel.
>
>     I also tried subclassing TreeNodeModel. But I found no way to update
>     underlying UI widget. There is a huge mess involving TreeNodeModel,
>     MorphicTreeNodeAdapter, SpecTreeNodeModel, and MorphTreeNodeMorph.
>
>     The only option left is to extract all needed information from
>     TreeNodeModel
>     hierarchy (preserving the tree structure) before update, and then try to
>     reapply it to newly created hierarchy.
>
>     Or is there an easier way?
>
>
> Not that I know of. I tried to change PharoLauncher to reselect the
> current item if you rename or recreate
> an image. But I could not find a way :(
>
>
>
>     --
>     View this message in context:
>     http://forum.world.st/Spec-TreeModel-dynamic-contents-tp4827440.html
>     Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>


Reply | Threaded
Open this post in threaded view
|

Re: Spec TreeModel dynamic contents

demarey
In reply to this post by webwarrior

Le 19 mai 2015 à 18:04, webwarrior a écrit :

> I want to make a tree using TreeModel that reacts to changes in underlying
> data - when an item changes, tree node for that item should update its state
> (recompute its children, etc.).
>
> Rebuilding the whole tree is ok, as long as selections and
> collapsed/expanded state of nodes are preserved.

yes but not very efficient if you have a big tree

> Using #updateTree however resets all these things. And there is no easy way
> to save/load them either - #selectedItems/#selectedItems: work with TreeNode
> instances that get reset, and collapsed/expanded states of nodes are simply
> unaccessible from TreeModel.

did you check the implementation of Komitter?
It keeps the state of your tree (selected items, collapsed/expanded).  So maybe it is doable.

> I also tried subclassing TreeNodeModel. But I found no way to update
> underlying UI widget. There is a huge mess involving TreeNodeModel,
> MorphicTreeNodeAdapter, SpecTreeNodeModel, and MorphTreeNodeMorph.
>
> The only option left is to extract all needed information from TreeNodeModel
> hierarchy (preserving the tree structure) before update, and then try to
> reapply it to newly created hierarchy.
>
> Or is there an easier way?
>
>
>
> --
> View this message in context: http://forum.world.st/Spec-TreeModel-dynamic-contents-tp4827440.html
> Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>


smime.p7s (5K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Spec TreeModel dynamic contents

webwarrior
In reply to this post by Nicolai Hess
Using lots of trial and error, I finally found a solution. Or, rather a hack.

In Pharo 3:
Just set autoRefreshOnExpand to true, and then when there is need for update, do:

self widget treeModel updateList

In Pharo 4:
For some reason autoRefreshOnExpand was removed, and now we also have to manually reset children of all (at least all affected nodes). Something like this:

node widget widget setChildren: node widget childrenBlock

(where node is instance of TreeNodeModel; root nodes can be obtained by calling self widget treeModel rootNodes collect: #nodeModel)

However as this solution uses some implementation details, expect it to break at any time. Hey, they even change public API without warning (like mentioned autoRefreshOnExpand).
Reply | Threaded
Open this post in threaded view
|

Re: Spec TreeModel dynamic contents

Nicolai Hess


2015-05-21 13:05 GMT+02:00 webwarrior <[hidden email]>:
Using lots of trial and error, I finally found a solution. Or, rather a hack.

In Pharo 3:
Just set autoRefreshOnExpand to true, and then when there is need for
update, do:


I can not find autoRefreshOnExpand anywhere in Pharo3.0. What version?
(I have 30645)

 
self widget treeModel updateList

In Pharo 4:
For some reason autoRefreshOnExpand was removed, and now we also have to
manually reset children of all (at least all affected nodes). Something like
this:

node widget widget setChildren: node widget childrenBlock

(where node is instance of TreeNodeModel; root nodes can be obtained by
calling self widget treeModel rootNodes collect: #nodeModel)

However as this solution uses some implementation details, expect it to
break at any time. Hey, they even change public API without warning (like
mentioned autoRefreshOnExpand).



--
View this message in context: http://forum.world.st/Spec-TreeModel-dynamic-contents-tp4827440p4827812.html
Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.


Reply | Threaded
Open this post in threaded view
|

Re: Spec TreeModel dynamic contents

webwarrior
version 30854

On 21.05.2015 14:16, Nicolai Hess [via Smalltalk] wrote:

>
>
> 2015-05-21 13:05 GMT+02:00 webwarrior <[hidden email]
> </user/SendEmail.jtp?type=node&node=4827816&i=0>>:
>
>     Using lots of trial and error, I finally found a solution. Or,
>     rather a hack.
>
>     In Pharo 3:
>     Just set autoRefreshOnExpand to true, and then when there is need for
>     update, do:
>
>
> I can not find autoRefreshOnExpand anywhere in Pharo3.0. What version?
> (I have 30645)
>
>     self widget treeModel updateList
>
>     In Pharo 4:
>     For some reason autoRefreshOnExpand was removed, and now we also have to
>     manually reset children of all (at least all affected nodes).
>     Something like
>     this:
>
>     node widget widget setChildren: node widget childrenBlock
>
>     (where node is instance of TreeNodeModel; root nodes can be obtained by
>     calling self widget treeModel rootNodes collect: #nodeModel)
>
>     However as this solution uses some implementation details, expect it to
>     break at any time. Hey, they even change public API without warning
>     (like
>     mentioned autoRefreshOnExpand).
>
>
>
>     --
>     View this message in context:
>     http://forum.world.st/Spec-TreeModel-dynamic-contents-tp4827440p4827812.html
>     Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
>
>
>
>
> ------------------------------------------------------------------------
> If you reply to this email, your message will be added to the discussion
> below:
> http://forum.world.st/Spec-TreeModel-dynamic-contents-tp4827440p4827816.html
>
> To unsubscribe from Spec TreeModel dynamic contents, click here
> <
> NAML
> <
http://forum.world.st/template/NamlServlet.jtp?macro=macro_viewer&id=instant_html%21nabble%3Aemail.naml&base=nabble.naml.namespaces.BasicNamespace-nabble.view.web.template.NabbleNamespace-nabble.view.web.template.NodeNamespace&breadcrumbs=notify_subscribers%21nabble%3Aemail.naml-instant_emails%21nabble%3Aemail.naml-send_instant_email%21nabble%3Aemail.naml>
>
Reply | Threaded
Open this post in threaded view
|

Re: Spec TreeModel dynamic contents

webwarrior
Actually, I may be using slightly newer version of Spec straight from github repository