jmix-projects / jmix-old

DEPRECATED. Use https://github.com/jmix-framework/jmix
16 stars 3 forks source link

Get rid of generatedType and type attributes of DataGrid.Column #457

Closed GlebDurygin closed 4 years ago

GlebDurygin commented 4 years ago

Description of the bug or enhancement

Cuba platform issue - cuba-platform/cuba#2898

The generatedType attribute of <column/> element is not used since there are parameterized renderers and install delegates for declarative installation of column generator. The type attribute of DataGrid.Column is only used to check for equality with the Boolean.class and set the CheckBoxRenderer, if this comparison is true. The metaProperty.getJavaType() method call can replace the use of type attribute.

Solution

The type and generatedType attributes of DataGrid.Column have been moved to the cuba module. ColumnGenerator and GenericColumnGenerator interfaces also have been moved to the cuba module.

Now, the jmix-ui module contains two methods for setting the generated column: 1) addGeneratedColumn(String columnId, Function<ColumnGeneratorEvent<E>, ?> generator) Usage example:

    testDataGrid.addGeneratedColumn("generatedColumn1", (columnGeneratorEvent) -> "GeneratedColumn1");

2) addGeneratedColumn(String columnId, Function<ColumnGeneratorEvent<E>, ?> generator, int index) Usage example:

        testDataGrid.addGeneratedColumn("generatedColumn2", (columnGeneratorEvent) -> {
            Label<String> label = uiComponents.create(Label.class);
            label.setValue("GeneratedColumn2");
            return label;
        }, 2).setRenderer(new WebComponentRenderer<>());

The user can also create a generated column using the install delegate:

    @Install(to = "testDataGrid.generatedColumn3", subject = "columnGenerator")
    protected Object testDataGridGeneratedColumn3ColumnGenerator(DataGrid.ColumnGeneratorEvent<Greeting> columnGeneratorEvent) {
        return "GeneratedColumn3";
    }

The layout.xsd file in jmix-ui module does not consist generatedType attribute for DataGrid.Column elemnt.