Vaadin Tree "cell renderer"?

Hello everyone,

I’m new to Vaadin. I’ve developed a lot of Swing and SWT applications so it was easy to get used to it.

However, currently I’m facing a certain issue. I have an in-memory representation of a data model and I would like to present this model on the Vaadin UI using a simple Tree, as this component nicely reflects the structure of my model. The problem is that if I just invoke “this.addItem(element)”, then Vaadin will use the “toString” method of the element to display the item in the tree - which in my case really does not make sense at all. However, if I use “this.addItem(calculateName(element))”, then I cannot establish parent-child-relationships on the tree items anymore since my element names are not necessarily unique.

In Swing, the component to change in such a case would be simply the “TreeCellRenderer” component which takes the node data and produces the label for it. But I’ve not seen such a component in Vaadin’s Tree so far - maybe there is such a component and it is called differently?

So the question is: how to change the default labelling algorithm of Vaadin’s tree component?

Thanks,

Martin

Use
setItemCaption(Object itemId, String caption)
or
setItemCaptionPropertyId(Object propertyId)
method. The last one you can use, even if the items has no proper property (;-)): just create method
getCalculatedName()
in your bean and call
setItemCaptionPropertyId(“calculatedName”)
.

Ah okay I see, so instead of defining an object which assigns labels to items, you assign the label to the item directly. I like that approach, it’s just hard to guess that it works like that when you have a Swing/SWT background ^_^’

Thank you,

Martin

The fake property way works but is certainly something of a hack; Vaadin really could use a Renderer concept like that in a multitude of places. It’s an idea that we’ve been entertaining within the R&D team and it just might get implemented at some point.

Hi,

now I came up to the same request and I am using setItemCaptionPropertyId(“myID”). But I always get

com.vaadin.data.util.LegacyPropertyHelper maybeLogLegacyPropertyToStringWarning
WARNING: You are using toString() instead of getValue() to get the value for a Property of type com.vaadin.ui.ComboBox. This is strongly discouraged and only provided for backwards compatibility with Vaadin 6. To disable this warning message and retain the behavior, set the init parameter "legacyPropertyToString" to "true". To disable the legacy functionality, set "legacyPropertyToString" to false. (Note that your debugger might call toString() and trigger this message). To find out who is calling toString(), enable FINE level logging.

So is this workaround obsolete? Is there any new way to do this? And I case I should use .setItemCaption(Object itemId, String caption) what should I use as first parameter? ComboBox? BeanItemContainer? Which Object?

Thx!