mvysny / karibu-dsl

Kotlin Vaadin extensions and DSL
http://www.vaadinonkotlin.eu
MIT License
126 stars 16 forks source link

Create `grid(klass, dataProvider, block)` method #28

Closed vilmosnagy closed 3 years ago

vilmosnagy commented 3 years ago

Hi there,

I'd like to use the grid(){} builder method from somewhere, where the generic class T is not available as a reified class, but I have a klass: KClass<T> variable.

I'd like to add the following methods for the Grid.kt:

@VaadinDsl
public inline fun <T : Any?> (@VaadinDsl HasComponents).grid(
        klass: KClass<T>,
        dataProvider: DataProvider<T, *>? = null,
        noinline block: (@VaadinDsl Grid<T>).() -> Unit = {}
): Grid<T> {
    val grid = Grid<T>(klass.java, false)
    if (dataProvider != null) {
        grid.dataProvider = dataProvider
    }
    grid.hotfixMissingHeaderRow()
    return init(grid, block)
}

And the same one for the treeGrid builder.

Would you merge a PR like this?

Thanks, Vilmos

mvysny commented 3 years ago

Hi Vilmos, sure thing, that looks really useful. However, please make sure that Karibu-DSL doesn't need to depend on kotlin-reflect after this kind of change.