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? -- 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.
2015-05-19 18:04 GMT+02:00 webwarrior <reg@webwarrior.ws>:
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.
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 <reg@webwarrior.ws <mailto:reg@webwarrior.ws>>:
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.
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). -- 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.
2015-05-21 13:05 GMT+02:00 webwarrior <reg@webwarrior.ws>:
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.
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 <http://forum.world.st/template/NamlServlet.jtp?macro=unsubscribe_by_code&nod...>. NAML <http://forum.world.st/template/NamlServlet.jtp?macro=macro_viewer&id=instant...>
-- View this message in context: http://forum.world.st/Spec-TreeModel-dynamic-contents-tp4827440p4827818.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
Actually, I may be using slightly newer version of Spec straight from github repository -- View this message in context: http://forum.world.st/Spec-TreeModel-dynamic-contents-tp4827440p4827820.html Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com.
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.
participants (4)
-
Christophe Demarey -
Nicolai Hess -
Thierry Goubier -
webwarrior