Proper way to add a child node to a TreeView in 7.7

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

Proper way to add a child node to a TreeView in 7.7

Rob Rothwell
Can anyone point me in the right direction to properly add a a new node to a TreeView interactively in 7.7 and refresh the view so the results are visible?

Basically all I wanted to be able to do was interactively edit the tree--add/remove/cut/paste/etc...

I thought I would start with "add"...!

From the TreeView-Example package, I was able to quickly add a new menu item to the tree so that when I right click on a node I can do something like this:

addChildNode
        | sel newName |
        (sel := self treeView selection) isNil ifTrue: [^Dialog warn: 'Nothing selected.'].
        newName := Dialog request: 'Name of new node:' initialAnswer: ''.
        sel children add: (sel class subAccountExample name: newName).

Where the subAccountExample method just returns an object that responds to #children with some more nodes for testing, like this:

subAccountExample
        | x |

        "self subAccountExample"

        x := OrderedCollection new.
        x add: (self new name: 'Level 2'; children: (OrderedCollection new add: (self new name: 'Level 3'); yourself)).
        x add: (self new name: 'Level 2').
        ^self new name: 'Level 1'; children: x.

This WORKS, but...if the node is expanded I have to manually contract and expand it to see the new node.  I am very inexperienced with VisualWorks, and keep expecting to find something like a #refresh message that will just tell the control to redraw itself.

I tried using pieces of the code in an old post:

"addChild
        | newNode |
        newNode := (HierarchyTreeNode new)
                                name: 'New Item';
                                proj_id: self selection proj_id.
        newNode id: parent newArtificialIndex.
        self selection children add: newNode.
        self selection parent isNil
                ifTrue: [pane tree refreshRoot]
                ifFalse: [pane tree refresh: self selection].
        pane tree expandRootFully.
        self selection: newNode.
        self editSelection
        "super halt."
"

but my TreeView does not seem to respond to refreshRoot, refresh:, or expandRootFully.

Thank you for your patience with my beginner questions...

Rob

Reply | Threaded
Open this post in threaded view
|

Re: Proper way to add a child node to a TreeView in 7.7

Maarten Mostert-2
You can try using bits of the enclosed method which is for a MultiSelectionTreeView. This code does not use the
refreshRoot, and refresh:methods you are complaining about however you should read over the Glorp specific items.

Notice that the trickier part comes when you want to remove your node interactively, as you probably want your
treeview to remain exapanded in a similar way.

Regards,

@+Maarten,



addChildComponent

| newNode selectedNode currentTreeIndex thisNode |
newNode := HierarchyTreeNode new name: (Dialog request: 'Name').
self getGlorpSession
inUnitOfWorkDo: [self getGlorpSession register: newNode].
self getGlorpSession inUnitOfWorkDo:
[selectedNode := self getGlorpSession readOneOf: HierarchyTreeNode
where: [:each | each id = components selections last key].
thisNode := self getGlorpSession readOneOf: HierarchyTreeNode
where: [:each | each id = newNode id].
selectedNode children isEmpty
ifFalse: [thisNode financial: selectedNode children first financial].
selectedNode children add: thisNode].
currentTreeIndex := components tree indexOf: components selection.
newNode id isNil
ifFalse:
[components selection children size > 0
ifFalse: [components selection addChild: newNode asHierarchyNode]
ifTrue:
[components selection addChild: newNode asHierarchyNode
after: components selection children last]].
components tree contractFully: currentTreeIndex.
components tree expand: currentTreeIndex.
self updateHierarchyIndex




> Message du 11/08/10 13:42
> De : "Rob Rothwell"
> A : [hidden email]
> Copie à :
> Objet : [vwnc] Proper way to add a child node to a TreeView in 7.7
>
>
>
> Can anyone point me in the right direction to properly add a a new node to a
> TreeView interactively in 7.7 and refresh the view so the results are
> visible?
>
> Basically all I wanted to be able to do was interactively edit the
> tree--add/remove/cut/paste/etc...
>
> I thought I would start with "add"...!
>
> >From the TreeView-Example package, I was able to quickly add a new menu item
> to the tree so that when I right click on a node I can do something like
> this:
>
> addChildNode
> | sel newName |
> (sel := self treeView selection) isNil ifTrue: [^Dialog warn: 'Nothing
> selected.'].
> newName := Dialog request: 'Name of new node:' initialAnswer: ''.
> sel children add: (sel class subAccountExample name: newName).
>
> Where the subAccountExample method just returns an object that responds to
> #children with some more nodes for testing, like this:
>
> subAccountExample
> | x |
>
> "self subAccountExample"
>
> x := OrderedCollection new.
> x add: (self new name: 'Level 2'; children: (OrderedCollection new add:
> (self new name: 'Level 3'); yourself)).
> x add: (self new name: 'Level 2').
> ^self new name: 'Level 1'; children: x.
>
> This WORKS, but...if the node is expanded I have to manually contract and
> expand it to see the new node. I am very inexperienced with VisualWorks,
> and keep expecting to find something like a #refresh message that will just
> tell the control to redraw itself.
>
> I tried using pieces of the code in an old post:
>
> "addChild
> | newNode |
> newNode := (HierarchyTreeNode new)
> name: 'New Item';
> proj_id: self selection proj_id.
> newNode id: parent newArtificialIndex.
> self selection children add: newNode.
> self selection parent isNil
> ifTrue: [pane tree refreshRoot]
> ifFalse: [pane tree refresh: self selection].
> pane tree expandRootFully.
> self selection: newNode.
> self editSelection
> "super halt."
> "
>
> but my TreeView does not seem to respond to refreshRoot, refresh:, or
> expandRootFully.
>
> Thank you for your patience with my beginner questions...
>
> Rob
>
>
> --
> View this message in context: http://forum.world.st/Proper-way-to-add-a-child-node-to-a-TreeView-in-7-7-
tp2320720p2320720.html
> Sent from the VisualWorks mailing list archive at Nabble.com.
> _______________________________________________
> vwnc mailing list
> [hidden email]
> http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
>
>

_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Proper way to add a child node to a TreeView in 7.7

Rob Rothwell
Thanks Maarten...I'll give this a try.  I am just trying to create something for myself right now, so I don't care if it is a TreeView or a MultiSelectionTreeView.

And yes, you are right that I would probably want the same behavior when I delete as well.  You sure would think there would just be and addItem:, insertItem: removeItem:, etc...!

Thank you,

Rob

On Thu, Aug 12, 2010 at 3:20 AM, Maarten Mostert [via Smalltalk] <[hidden email]> wrote:
You can try using bits of the enclosed method which is for a MultiSelectionTreeView. This code does not use the
refreshRoot, and refresh:methods you are complaining about however you should read over the Glorp specific items.

Notice that the trickier part comes when you want to remove your node interactively, as you probably want your
treeview to remain exapanded in a similar way.

Regards,

@+Maarten,



addChildComponent

| newNode selectedNode currentTreeIndex thisNode |
newNode := HierarchyTreeNode new name: (Dialog request: 'Name').
self getGlorpSession
inUnitOfWorkDo: [self getGlorpSession register: newNode].
self getGlorpSession inUnitOfWorkDo:
[selectedNode := self getGlorpSession readOneOf: HierarchyTreeNode
where: [:each | each id = components selections last key].
thisNode := self getGlorpSession readOneOf: HierarchyTreeNode
where: [:each | each id = newNode id].
selectedNode children isEmpty
ifFalse: [thisNode financial: selectedNode children first financial].
selectedNode children add: thisNode].
currentTreeIndex := components tree indexOf: components selection.
newNode id isNil
ifFalse:
[components selection children size > 0
ifFalse: [components selection addChild: newNode asHierarchyNode]
ifTrue:
[components selection addChild: newNode asHierarchyNode
after: components selection children last]].
components tree contractFully: currentTreeIndex.
components tree expand: currentTreeIndex.
self updateHierarchyIndex




> Message du 11/08/10 13:42
> De : "Rob Rothwell"
> A : [hidden email]
> Copie à :

> Objet : [vwnc] Proper way to add a child node to a TreeView in 7.7
>
>
>
> Can anyone point me in the right direction to properly add a a new node to a
> TreeView interactively in 7.7 and refresh the view so the results are
> visible?
>
> Basically all I wanted to be able to do was interactively edit the
> tree--add/remove/cut/paste/etc...
>
> I thought I would start with "add"...!
>
> >From the TreeView-Example package, I was able to quickly add a new menu item
> to the tree so that when I right click on a node I can do something like
> this:
>
> addChildNode
> | sel newName |
> (sel := self treeView selection) isNil ifTrue: [^Dialog warn: 'Nothing
> selected.'].
> newName := Dialog request: 'Name of new node:' initialAnswer: ''.
> sel children add: (sel class subAccountExample name: newName).
>
> Where the subAccountExample method just returns an object that responds to
> #children with some more nodes for testing, like this:
>
> subAccountExample
> | x |
>
> "self subAccountExample"
>
> x := OrderedCollection new.
> x add: (self new name: 'Level 2'; children: (OrderedCollection new add:
> (self new name: 'Level 3'); yourself)).
> x add: (self new name: 'Level 2').
> ^self new name: 'Level 1'; children: x.
>
> This WORKS, but...if the node is expanded I have to manually contract and
> expand it to see the new node. I am very inexperienced with VisualWorks,
> and keep expecting to find something like a #refresh message that will just
> tell the control to redraw itself.
>
> I tried using pieces of the code in an old post:
>
> "addChild
> | newNode |
> newNode := (HierarchyTreeNode new)
> name: 'New Item';
> proj_id: self selection proj_id.
> newNode id: parent newArtificialIndex.
> self selection children add: newNode.
> self selection parent isNil
> ifTrue: [pane tree refreshRoot]
> ifFalse: [pane tree refresh: self selection].
> pane tree expandRootFully.
> self selection: newNode.
> self editSelection
> "super halt."
> "
>
> but my TreeView does not seem to respond to refreshRoot, refresh:, or
> expandRootFully.
>
> Thank you for your patience with my beginner questions...
>
> Rob
>
>
> --
> View this message in context: http://forum.world.st/Proper-way-to-add-a-child-node-to-a-TreeView-in-7-7-
tp2320720p2320720.html
> Sent from the VisualWorks mailing list archive at Nabble.com.
> _______________________________________________
> vwnc mailing list
> [hidden email]
_______________________________________________
vwnc mailing list
[hidden email]

View message @ http://forum.world.st/Proper-way-to-add-a-child-node-to-a-TreeView-in-7-7-tp2320720p2322299.html
To unsubscribe from Proper way to add a child node to a TreeView in 7.7, click here.