Building a tree/outliner like graphical interface in Pharo/Smalltalk using Moose Glamorous Toolkit

351 views Asked by At

I'm trying to build a tree/outliner like graphical interface in Pharo/Smalltalk using Moose Glamorous Toolkit. So, far I have got this mockup:

Outliner mockup http://www.enlightenment.org/ss/e-53e3dee6777744.68598023.jpg

For that I'm using the following code:

| browser mainTree |

mainTree := UbakyeNode new.
mainTree becomeDefaultTree.   

browser := GLMTabulator new.
browser
    column: #tree;
    column: [ :c |
                c
                    row: #body;
                    row: #plugins ].
(browser transmit)
    to: #tree;
    andShow: [ :a |
                (a tree)
                    title: mainTree header;
                    children: [ :eachNode |
                                eachNode children. ]    "Children must return a collection" ].
(browser transmit)
    to: #body;
    from: #tree;
    andShow: [ :a | a text title: 'Cuerpo | Body ' ].
(browser transmit)
    to: #plugins;
    from: #tree port: #selectionPath;
    andShow: [ :a | a text title: 'Plugins | Extensiones' ].

browser openOn: mainTree children.

So I have now a browser which shows a tree made of UbakyeNodes (a tree like data structure I defined), but I would like not to show the Ubakye Nodes, but the titles of each node (headers) and the contents (bodies) of them when selected. With the help of the Pharo/Moose community I have understood that I need to pass the collection of all children (not just the headers of them), but I don't know who to sellect something particular in that collection to be shown on the browser, like headers of nodes in the #tree panel or bodies in the #body panel.

I would like to change also the size of each panel to be more like the shown in the screenshot, instead of the default one and be relative to window size. Is this possible?

2

There are 2 answers

0
Offray On BEST ANSWER

Ok, thanks to Peter Kenny in the Pharo-users Community mailing list, now I have the answer. The issue is related with the "format:" keyword message, which was missing. Using it, is possible to tell Moose/Pharo how to display information taken from the children. Here is the modified working code:

| browser mainTree |

mainTree := UbakyeNode new.
mainTree becomeDefaultTree.   

browser := GLMTabulator new.
browser
    column: #tree;
    column: [ :c |
                c
                    row: #body;
                    row: #plugins ].
(browser transmit)
    to: #tree;
    andShow: [ :a |
                (a tree)
                    title: mainTree header;
                    children: [ :eachNode |
                        (eachNode children) isNil
                            ifTrue: [ #() ]
                            ifFalse:[ eachNode children ] ];
                    format:[:eachNode |
                        (eachNode header) isNil
                            ifTrue: [ '' ]
                            ifFalse: [ eachNode header ] ].
                    "Children must return a collection" ].
(browser transmit)
    to: #body;
    from: #tree;
    andShow: [ :a |
                (a text)
                    title: 'Cuerpo | Body ';
                    format:[:eachNode |
                        (eachNode body) isNil
                             ifTrue: [ '' ]
                            ifFalse: [ eachNode body ] ]

                ].
(browser transmit)
    to: #plugins;
    andShow: [ :a | a text title: 'Plugins | Extensiones' ].

browser openOn: mainTree children.  
0
Stephan Eggermont On

And setting the relative width and height you do by using

row: #result span: 2;

for the row/column that should be twice as wide. So something like

browser
    column: #tree;
    column: [ :c |
        c row: #body span: 3;
          row: #plugins ] span: 3.