Getting the correct object from event.getItem()

Using a Tree. I am placing a structure of objects in the tree by using a HierarchicalContainer and then making the HierarchicalContainer the dataSource of the tree. When building the HierarchicalContainer I am placing objects of different classes (for instance car, motorcycle, etc).

At some point I am retrieving the object as an Item in a ItemClickListener:

protected ItemClickListener treeItemClicked() { return new ItemClickEvent.ItemClickListener(){ private static final long serialVersionUID = 6707040832557468915L; @Override public void itemClick(ItemClickEvent event) { Object item = event.getItem(); if(item != null){ // Determine item class type and do something useful with it. // If car then show car info // if motorcycle then display motorcycle info // Etc. } } }; } I want to get the object and display different information depending upon what kind of object was clicked. My issue is no matter what I try I cannot get the Item retrieved from event.getItem() to cast to the class that it started as.

How can I retrieve the original object (class) out of the event?

If you mean the thing you put in addItem(yourObject) that’s not the item, that’s itemId. So event.getItemId() might be what you actually want :slight_smile: