Table column generation based on metapropertypath - cuba migration

This is in scope of migration from cuba to jmix

I have a lot of entities extending other entities.
For each I need a browser and editor window, for editors I use fragments to promote reuse.

For the browsers I have a utility class that adds columns for common properties based on MetaPropertyPath. I don’t see a direct replacement for this in jmix.

I would assume something with a EntityValueSource, but I don’t find a way to create instances given an entity…

cuba (not supported in jmix) code :

   private void someFunctionThatWillAddTheInvididualColumns() {
        properties.put("Status", "status");
        properties.put("Series Identifier", "series.identifier");
        properties.put("Series", "series.description");
        properties.forEach(this::addColumn);
    }

    private void addColumn(String caption, String path) {
            MetaClass abstractPartMeta = metadata.getClass(AbstractPart.class);
            MetaPropertyPath propertyPath = abstractPartMeta.getPropertyPath(path);
            getTable().addColumn(new Table.Column<>(propertyPath, caption), 0);
    }

Hi,

in Jmix you can simple use the Table#addColumn(java.lang.Object, int) method and pass MetaPropertyPath as id, e.g.:

private void addColumn(String caption, String path) {
    MetaClass metaClass = metadata.getClass(Product.class);
    MetaPropertyPath propertyPath = metaClass.getPropertyPath(path);
    if (propertyPath != null) {
        Table.Column<Product> column = productsTable.addColumn(propertyPath, 0);
        column.setCaption(caption);
    } else {
        // ...
    }
}

Regards,
Gleb

1 Like