Hi !
I've been playing with Pharo again. In the application I'm building, I need to load a file from disk, and depending on what is inside this file, select an item in a tree that is displayed on the main window. The SearchableTree subclass I use is copied at the end of the email. It is nothing fancy, just creating the nodes from a fixed tree structure. The method selectedItemFRomPathArray (e.g. #('a' 'a1')) is the one that should be responsible for selecting the node, but for now it just returns the array of TreeNodeModel that correspond to the strings in the 'PathArray' given in argument. I tried the following in a PlayGround : w := CRPJCategories2 new. w openWithSpec. "Taken from packageRemotesManager without understanding it." w tree selectedItem:( (w roots) first "This line can also be : ((w selectedItemFromPathArray:#('a')) last)" selected:true; takeHighlight; yourself). Which works, but when I try to select something that is not a root node, then it does not work, and I've been pulling my hair trying to understand why. w := CRPJCategories2 new. w openWithSpec. "Taken from packageRemotesManager without understanding it." w tree selectedItem:( ((w selectedItemFromPathArray:#('a' 'a1')) last) "<- DOES NOT WORK" selected:true; takeHighlight; yourself). Any pointer would be very much appreciated. Thenks in advance. Edouard. ------------------------------------------------------- 'From Pharo4.0 of 18 March 2013 [Latest update: #40623] on 23 October 2015 at 4:55:07.823126 pm'! SearchableTree subclass: #CRPJCategories2 instanceVariableNames: 'structure' classVariableNames: '' poolDictionaries: '' category: 'CRPJ'! !CRPJCategories2 methodsFor: 'as yet unclassified' stamp: 'EdouardKlein 10/23/2015 15:29'! nodeFromTreeStructure: anArray ^ (anArray collect:[:x| TreeNodeModel new content: (x at:1); children: [((x size = 1) ifTrue:[#()] ifFalse:[self nodeFromTreeStructure:(x at:2)])]; hasChildren:[x size > 1]]) asOrderedCollection.! ! !CRPJCategories2 methodsFor: 'as yet unclassified' stamp: 'EdouardKlein 10/23/2015 15:10'! initialize | | super initialize. structure := { {'a' . { {'a1'}. {'a2'}}}. {'b' . { {'b1' . { {'b1A'}. {'b1B'}}}. {'b2'}. {'b3' . { {'b3A'}. {'b3B'}}}}}. {'c' . { {'c1'}. {'c2'}. {'c3'}}}}. self roots:(self nodeFromTreeStructure: structure).! ! !CRPJCategories2 methodsFor: 'as yet unclassified' stamp: 'EdouardKlein 10/23/2015 16:54'! selectedItemFromPathArray:aPathArray "a string description of the currently selected item" | recurse | recurse := [:path :nodes| |nextNode| nextNode := (nodes select:[:n| n content = path first]) first. (path size = 1) ifTrue:[{nextNode}] ifFalse:[ {nextNode},(recurse value:(path allButFirst)value:(nextNode children value))]]. ^(recurse value: aPathArray value:(self roots)).! ! !CRPJCategories2 methodsFor: 'as yet unclassified' stamp: 'EdouardKlein 10/23/2015 16:53'! selectedItemAsPathArray "an array of the path to the currently selected item" | recurse | recurse := [:node| node ifNil:[{}] ifNotNil:[(recurse value:(node parentNode)),{node}]]. ^(recurse value:self selectedItem) collect:[:node| node content].! ! |
It's also possible that it is simply bugged. PackageRemotesManager doesn't use TreeModel, it uses different widget (whose API looks cleaner). I'll try to look at this tomorrow (unless someone else beats me to it) how this could be done (and maybe even take a stab at cleaning the API a bit...). Peter On Fri, Oct 23, 2015 at 5:17 PM, Edouard KLEIN <[hidden email]> wrote: Hi ! |
Le 23/10/2015 21:01, Peter Uhnák a écrit :
> It's also possible that it is simply bugged. > > PackageRemotesManager doesn't use TreeModel, it uses different widget > (whose API looks cleaner). > > I'll try to look at this tomorrow (unless someone else beats me to it) > how this could be done (and maybe even take a stab at cleaning the API a > bit...). I wrote my own API to be able to that properly with MorphTreeMorph. Fastest/easiest way to do that is to directly get the items morphs inside the tree and select them. Cleaning that up is ... well, good luck with that. I wouldn't bother. Waiting for the FT-based rewrite is the thing to do. Will make the application code dealing with that a lot leaner and cleaner to boot. Thierry > Peter > > On Fri, Oct 23, 2015 at 5:17 PM, Edouard KLEIN <[hidden email] > <mailto:[hidden email]>> wrote: > > Hi ! > > I've been playing with Pharo again. In the application I'm building, I > need to load a file from disk, and depending on what is inside this > file, select an item in a tree that is displayed on the main window. > > The SearchableTree subclass I use is copied at the end of the email. It > is nothing fancy, just creating the nodes from a fixed tree structure. > > The method selectedItemFRomPathArray (e.g. #('a' 'a1')) is the one that > should be responsible for selecting the node, but for now it just > returns the array of TreeNodeModel that correspond to the strings in the > 'PathArray' given in argument. > > I tried the following in a PlayGround : > > w := CRPJCategories2 new. w openWithSpec. > "Taken from packageRemotesManager without understanding it." > w tree selectedItem:( > (w roots) first "This line can also be : > ((w selectedItemFromPathArray:#('a')) last)" > selected:true; > takeHighlight; > yourself). > > Which works, but when I try to select something that is not a root node, > then it does not work, and I've been pulling my hair trying to > understand why. > > w := CRPJCategories2 new. w openWithSpec. > "Taken from packageRemotesManager without understanding it." > w tree selectedItem:( > ((w selectedItemFromPathArray:#('a' 'a1')) last) "<- DOES NOT WORK" > selected:true; > takeHighlight; > yourself). > > > Any pointer would be very much appreciated. > > Thenks in advance. > > Edouard. > > > > > ------------------------------------------------------- > 'From Pharo4.0 of 18 March 2013 [Latest update: #40623] on 23 October > 2015 at 4:55:07.823126 pm'! > SearchableTree subclass: #CRPJCategories2 > instanceVariableNames: 'structure' > classVariableNames: '' > poolDictionaries: '' > category: 'CRPJ'! > > !CRPJCategories2 methodsFor: 'as yet unclassified' stamp: 'EdouardKlein > 10/23/2015 15:29'! > nodeFromTreeStructure: anArray > ^ (anArray collect:[:x| TreeNodeModel new > content: (x at:1); > children: [((x size = 1) ifTrue:[#()] ifFalse:[self > nodeFromTreeStructure:(x at:2)])]; > hasChildren:[x size > 1]]) asOrderedCollection.! ! > > !CRPJCategories2 methodsFor: 'as yet unclassified' stamp: 'EdouardKlein > 10/23/2015 15:10'! > initialize > | | > super initialize. > structure := { > {'a' . { > {'a1'}. > {'a2'}}}. > {'b' . { > {'b1' . { > {'b1A'}. > {'b1B'}}}. > {'b2'}. > {'b3' . { > {'b3A'}. > {'b3B'}}}}}. > {'c' . { > {'c1'}. > {'c2'}. > {'c3'}}}}. > self roots:(self nodeFromTreeStructure: structure).! ! > > !CRPJCategories2 methodsFor: 'as yet unclassified' stamp: 'EdouardKlein > 10/23/2015 16:54'! > selectedItemFromPathArray:aPathArray > "a string description of the currently selected item" > | recurse | > recurse := [:path :nodes| > |nextNode| > nextNode := (nodes select:[:n| n content = path > first]) first. > (path size = 1) ifTrue:[{nextNode}] ifFalse:[ > {nextNode},(recurse value:(path > allButFirst)value:(nextNode children > value))]]. > ^(recurse value: aPathArray value:(self roots)).! ! > > !CRPJCategories2 methodsFor: 'as yet unclassified' stamp: 'EdouardKlein > 10/23/2015 16:53'! > selectedItemAsPathArray > "an array of the path to the currently selected item" > | recurse | > recurse := [:node| node ifNil:[{}] > ifNotNil:[(recurse value:(node > parentNode)),{node}]]. > ^(recurse value:self selectedItem) collect:[:node| node > content].! ! > > |
Waiting for the FT-based rewrite is the thing to do. If by waiting you mean doing FT-based rewrite, then sure. :) Unless Cyril is going to do the rewrite himself. P |
Ah, you want to do it? ;) > Unless Cyril is going to do the rewrite himself. Wasn't that the plan? I'm confused :) Thierry > P |
In reply to this post by Peter Uhnak
Thank you very much ! Le ven. 23 oct. 2015 à 21:03, Peter Uhnák <[hidden email]> a écrit :
|
> Unless Cyril is going to do the rewrite himself. Oh? I do not remember anyone mentioning on the mailing list that someone will change Spec to use FT. Or was this from some internal discussion at Inria/Synectique? Peter |
Well, given FT, then Spec will change to use it. You don't want to keep two widly different implementations of the same widget. Now, there was talk of a FT-based tree widget, and, IMO, this is the way to go. Thierry > Peter |
In reply to this post by Peter Uhnak
Le 24/10/2015 08:11, Peter Uhnák a écrit :
> Waiting for the FT-based rewrite is the thing to do. > > > If by waiting you mean doing FT-based rewrite, then sure. :) > > Unless Cyril is going to do the rewrite himself. > > P > Hi, Create a FTTree should be my next work :) I already begun a FTTree with one sublevel but this is only a first shot. I think it's possible to do cleaner and faster. -- Cyril Ferlicot http://www.synectique.eu 165 Avenue Bretagne Lille 59000 France signature.asc (836 bytes) Download Attachment |
Le 24/10/2015 13:20, Ferlicot D. Cyril a écrit :
> Le 24/10/2015 08:11, Peter Uhnák a écrit : >> Waiting for the FT-based rewrite is the thing to do. >> >> >> If by waiting you mean doing FT-based rewrite, then sure. :) >> >> Unless Cyril is going to do the rewrite himself. >> >> P >> > Hi, > > Create a FTTree should be my next work :) > I already begun a FTTree with one sublevel but this is only a first > shot. I think it's possible to do cleaner and faster. With the FT core code, I'm having success mapping the tree to an array (i.e. providing an #at: anIndex) for the tree. But then, need to optimise #at: (or the FT code iterating over the tree with #at:). Note that the widget should not have a knowledge of the tree depth (or the depth of an item of the tree). Otherwise the code becomes very complex (i.e. PluggableTreeMorph and MorphTreeMorph), for no good reason at all. Enjoy your design ;) Thierry |
What is FT ? I did some debugging. When I send the selected:#true message to a root node, it goes down to the Morphic classes, and everything is fine, when I send it to a child node, the dependents array of the TreeNodeModel is nil, so nobody gets the message. I don't know enough about Spec yet to understand what dependents are and why there are none on a child node.On Sun, 25 Oct 2015 at 09:10 Thierry Goubier <[hidden email]> wrote: Le 24/10/2015 13:20, Ferlicot D. Cyril a écrit : |
Le 26/10/2015 10:38, Edouard KLEIN a écrit :
> What is FT ? > FT is FastTable. This is a project begun by Esteban to replace the old slow list on Pharo. Pharo 5 uses FastTable now. > I did some debugging. When I send the selected:#true message to a root > node, it goes down to the Morphic classes, and everything is fine, when > I send it to a child node, the dependents array of the TreeNodeModel is > nil, so nobody gets the message. I don't know enough about Spec yet to > understand what dependents are and why there are none on a child node. > > Because I really need to get this done quickly, I will try to write a > quick and dirty fix in a subclass that will directly talk to the morphic > objects underneath. > > Now, with some guidance from you guys, I would be really happy to take > some time and write some useful code that could solve this problem > correctly, and have it commited for anyone to use. But first, in order > to justify to my employer that coding with Pharo was a good choice, I > need to make my application work. > > I'll update here as I go. > > Cyril Ferlicot http://www.synectique.eu 165 Avenue Bretagne Lille 59000 France signature.asc (836 bytes) Download Attachment |
> FT is FastTable. This is a project begun by Esteban to replace the old Thanks for the details. Should I update to Pharo5 tu use FT ?slow list on Pharo. > Pharo 5 uses FastTable now. Children nodes can be seen in the inspector without a hitch. Also, root nodes know their widget (a MorphicTreeNodeAdapter) whereas the children return nil. Any help, even just a reference at someplace to look, would be appreciated. On Mon, 26 Oct 2015 at 11:49 Ferlicot D. Cyril <[hidden email]> wrote: Le 26/10/2015 10:38, Edouard KLEIN a écrit : |
We should make sure that we can use FT instead of NewList (this is
on my todo since ages).
Stef Le 26/10/15 08:27, Edouard KLEIN a
écrit :
|
In reply to this post by Peter Uhnak
Le 24/10/15 06:06, Peter Uhnák a
écrit :
It is the plan since FT was introduced. The problem was that NewList API and FT were not compatible. So we should check but no reason to keep NewList (bad design) and also if we could kill PluggableListMorph use. Stef
|
Free forum by Nabble | Edit this page |