TreeGrid Icon rendering

Hello,

I’ve created some new Components that extend Component

@Tag("BroadworksComponent")
public class BroadworksComponent extends Component {

    private String name;

 public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
	
	
    public Icon getIcon() {
        return VaadinIcon.BUILDILNG.create();
    }

I have a TreeGrid of type BroadworksComponent and a DataProvider that provides objects derived from BroadworksComponent

TreeGrid<BroadworksComponent> grid = new TreeGrid<>(BroadworksComponent.class);

     grid.setDataProvider(dataProvider);

     grid.removeAllColumns();;
     grid.addColumn("icon");
     grid.addColumn("name").setHeader("");
     grid.setHierarchyColumn("name");

My TreeGrid is displayed as

com.vaadin.flow.component.icon.Icon@3cea4917 Customer Name

How do I get the TreeGrid to render the icon as the icon and not the ‘toString()’ of the class?

Icon is a component.
You need to use either ComponentRenderer or Grid::addComponentColumn which internally uses ComponentRenderer.
By default toString is used to render any object.

I’m trying this and it doesn’t work, I get a blank TreeGrid

 grid.addComponentColumn((ValueProvider<BroadworksComponent, Icon>) b -> b.getIcon())
 grid.setHierarchyColumn("text", (ValueProvider<BroadworksComponent, BroadworksComponent>) b -> b.getThis());

getIcon() & getThis() is defined as:

 public Icon getIcon() {
        return VaadinIcon.BUILDING_O.create();
    }

    public BroadworksComponent getThis() { return this; }

BroadworksComponent extends Label

I would like to have the Label display as text in the grid WITH a ContextMenu attached that is class centric. Every class that extends BroadworksComponent will create a new ContextMenu

example

public class Customer extends BroadworksComponent {
    String serviceProviderId;
    String address1;
    String address2;
    String city;
    String state;
    String zip;
    String country;
    String domain;


    public Customer(String text) {
        super(text);

        ContextMenu contextMenu = new ContextMenu();
        contextMenu.setTarget(this);
        contextMenu.addItem("Edit", e -> editDialog(e));
        contextMenu.addItem("Add Location", e -> addLocation(e));
        contextMenu.addItem("Add NG911 database record", e -> addNG911DatabaseRecord(e));
    }

Hard to say what’s wrong without a complete code sample.

I recommend to look at https://github.com/vaadin/vaadin-grid-flow/blob/master/vaadin-grid-flow-integration-tests/src/main/java/com/vaadin/flow/component/treegrid/it/TreeGridComponentRendererPage.java

This example works for sure since it’s used in our IT tests.
You may start from it and modify for your purpose.