Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-26 Thread Edouard KLEIN
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.

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.

On Sun, 25 Oct 2015 at 09:10 Thierry Goubier 
wrote:

> 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
>
>


Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-26 Thread Ferlicot D. Cyril
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
Description: OpenPGP digital signature


Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-25 Thread Thierry Goubier

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



Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-24 Thread Peter Uhnák
>
> > Unless Cyril is going to do the rewrite himself.
> Wasn't that the plan? I'm confused :)


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


Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-24 Thread Thierry Goubier
Le 24 oct. 2015 8:12 AM, "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. :)

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
>


Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-24 Thread Edouard KLEIN
Thank you very much !

Le ven. 23 oct. 2015 à 21:03, 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...).
>
> Peter
>
> On Fri, Oct 23, 2015 at 5:17 PM, Edouard KLEIN 
> 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].! !
>>
>>
>


Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-24 Thread Peter Uhnák
>
> 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


Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-24 Thread Thierry Goubier
Le 24 oct. 2015 12:07 PM, "Peter Uhnák"  a écrit :
>>
>> > Unless Cyril is going to do the rewrite himself.
>> Wasn't that the plan? I'm confused :)
>
>
> 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?

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


Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-24 Thread Ferlicot D. Cyril
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
Description: OpenPGP digital signature


Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-23 Thread Peter Uhnák
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 
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].!
> !
>
>


Re: [Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-23 Thread Thierry Goubier

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 > 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

[Pharo-users] How to programatically select an item in a Spec TreeModel ?

2015-10-23 Thread Edouard KLEIN
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].! !