Maybe a cleverer/simpler way to do this, but you could try extending
Button to include a reference to the TreeItem it's attached to, say
TreeButton. Then in your ClickListener onClick(Widget sender) {
if (sender instanceof TreeButton) {
TreeItem item = ((TreeButton)sender).getTreeItem();
}
That would save you slogging through the tree searching for an id or
something.
On Feb 20, 11:22 pm, nebs <[email protected]> wrote:
> Hello,
>
> I'm having trouble identifying tree elements. Let me explain with an
> example.
>
> Let's say I have a Tree object which contains a few TreeItem objects.
> Each TreeItem object in turn contains a few TreeItems and a button.
> These buttons are generated via loops and so do not have an object
> name associated (eg. they all must call the same event handler). Each
> button is set to trigger the same function (let's say buttonClicked
> (Widget sender)) when clicked on.
>
> My problem now is that within the buttonClicked(Widget sender) method
> I don't know how to figure out which branch (or TreeItem) that
> particular button belongs to.
>
> Here's a visual example:
> Tree:
> [ -] Fruits
> - Apple
> - Orange
> - [ ADD ] (<--- This is a Button widget)
> [ -] Vegetables
> - Carrot
> - Eggplant
> - Pepper
> - [ ADD ] (<--- This is a Button widget)
> [+] Dairy
>
> All the button click events call this function:
> private void buttonClicked(Widget sender){
> // How can I get the parent tree index via sender?
>
> }
>
> Let's say the user clicks on the "ADD" button which is under the
> "Fruits" subtree. How can I know that the button called belongs to
> "Fruits"?
>
> I would like to have something like:
> int treeindex = sender.getParent().getPositionInTree();
> And have it return for example 0 for fruits, 1 for Vegetables, 2 for
> Dairy, etc.
> I've looked through the JavaDoc but nothing jumped out at me right
> away.
> Maybe I'm missing something obvious.
>
> Thanks in advance for any help.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---