Search in sources :

Example 1 with DMNGridColumn

use of org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn in project kie-wb-common by kiegroup.

the class BaseExpressionGridGeneralTest method testUpdateWidthOfPeers.

/*
     * Test that parent column width is updated to sum of nested columns
     * The update is forced from nested column at position indexOfColumnToUpdate
     * The default width of parent column is 100
     */
private void testUpdateWidthOfPeers(final int indexOfColumnToUpdate, final double... widthsOfNestedColumns) {
    // parent column
    final BaseExpressionGrid parentGrid = mock(BaseExpressionGrid.class);
    final GridData parentGridData = mock(GridData.class);
    final DMNGridColumn parentColumn = mockColumn(100, null);
    doReturn(parentGrid).when(parentCell).getGridWidget();
    doReturn(parentGridData).when(parentGrid).getModel();
    doReturn(Collections.singletonList(parentColumn)).when(parentGridData).getColumns();
    doReturn(Collections.singleton(parentGrid)).when(gridLayer).getGridWidgets();
    // nested columns
    final List<DMNGridColumn> columns = Arrays.stream(widthsOfNestedColumns).mapToObj(width -> mockColumn(width, grid)).collect(Collectors.toList());
    grid.getModel().appendRow(new DMNGridRow());
    columns.stream().forEach(column -> grid.getModel().appendColumn(column));
    // force the peers width update
    columns.get(indexOfColumnToUpdate).updateWidthOfPeers();
    // assert parent width is equal to sum of nested columns widths
    final double padding = BaseExpressionGrid.DEFAULT_PADDING * 2;
    Assertions.assertThat(parentColumn.getWidth()).isEqualTo(Arrays.stream(widthsOfNestedColumns).sum() + padding);
}
Also used : DMNGridColumn(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn) IntStream(java.util.stream.IntStream) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) Arrays(java.util.Arrays) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RunWith(org.junit.runner.RunWith) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) Captor(org.mockito.Captor) GridLayerRedrawManager(org.uberfire.ext.wires.core.grids.client.widget.layer.impl.GridLayerRedrawManager) LienzoMockitoTestRunner(com.ait.lienzo.test.LienzoMockitoTestRunner) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) RowNumberColumn(org.uberfire.ext.wires.core.grids.client.widget.grid.columns.RowNumberColumn) ArgumentCaptor(org.mockito.ArgumentCaptor) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Matchers.eq(org.mockito.Matchers.eq) DMNGridColumn(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn) Assertions(org.assertj.core.api.Assertions) GridColumnRenderer(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.columns.GridColumnRenderer) Mockito.doReturn(org.mockito.Mockito.doReturn) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) GridDataCache(org.kie.workbench.common.dmn.client.widgets.grid.model.GridDataCache) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) Collectors(java.util.stream.Collectors) GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) Mockito.verify(org.mockito.Mockito.verify) Matchers.any(org.mockito.Matchers.any) HasName(org.kie.workbench.common.dmn.api.definition.HasName) List(java.util.List) Mockito.never(org.mockito.Mockito.never) Assert.assertFalse(org.junit.Assert.assertFalse) Optional(java.util.Optional) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) Mockito.mock(org.mockito.Mockito.mock) DMNGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridRow) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData)

Example 2 with DMNGridColumn

use of org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn in project kie-wb-common by kiegroup.

the class BaseExpressionGridGeneralTest method mockColumn.

@SuppressWarnings("unchecked")
private DMNGridColumn mockColumn(final double width, final GridWidget gridWidget) {
    final GridColumn.HeaderMetaData headerMetaData = mock(GridColumn.HeaderMetaData.class);
    final GridColumnRenderer columnRenderer = mock(GridColumnRenderer.class);
    return new DMNGridColumn(headerMetaData, columnRenderer, gridWidget) {

        {
            setWidth(width);
        }
    };
}
Also used : GridColumnRenderer(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.columns.GridColumnRenderer) DMNGridColumn(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) DMNGridColumn(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn)

Example 3 with DMNGridColumn

use of org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn in project kie-wb-common by kiegroup.

the class ExpressionEditorColumnTest method mockEditor.

@SuppressWarnings("unchecked")
private BaseExpressionGrid mockEditor(final double padding, final double... widthOfCells) {
    final GridColumn.HeaderMetaData headerMetaData = mock(GridColumn.HeaderMetaData.class);
    final GridColumnRenderer gridColumnRenderer = mock(GridColumnRenderer.class);
    final BaseExpressionGrid gridWidget = mock(BaseExpressionGrid.class);
    final GridCellTuple parent = new GridCellTuple(0, 0, null);
    final HasExpression hasExpression = mock(HasExpression.class);
    final Optional<LiteralExpression> expression = Optional.of(mock(LiteralExpression.class));
    final Optional<HasName> hasName = Optional.of(mock(HasName.class));
    return new BaseExpressionGrid(parent, Optional.empty(), hasExpression, expression, hasName, gridPanel, gridLayer, new GridDataCache.CacheResult(new DMNGridData(), false), renderer, definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, cellEditorControls, listSelector, translationService, 0) {

        @Override
        protected BaseUIModelMapper makeUiModelMapper() {
            return null;
        }

        @Override
        protected void initialiseUiColumns() {
            for (double width : widthOfCells) {
                model.appendColumn(new DMNGridColumn<GridWidget, Object>(headerMetaData, gridColumnRenderer, gridWidget) {

                    {
                        setMinimumWidth(width);
                        setWidth(width);
                    }
                });
            }
        }

        @Override
        protected void initialiseUiModel() {
        // Nothing for this test
        }

        @Override
        protected boolean isHeaderHidden() {
            return false;
        }

        @Override
        public double getPadding() {
            return padding;
        }
    };
}
Also used : GridColumnRenderer(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.columns.GridColumnRenderer) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) BaseGridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.impl.BaseGridWidget) GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) HasName(org.kie.workbench.common.dmn.api.definition.HasName) LiteralExpression(org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) GridDataCache(org.kie.workbench.common.dmn.client.widgets.grid.model.GridDataCache) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) GridColumn(org.uberfire.ext.wires.core.grids.client.model.GridColumn) DMNGridColumn(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn)

Aggregations

DMNGridColumn (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn)3 GridColumn (org.uberfire.ext.wires.core.grids.client.model.GridColumn)3 GridColumnRenderer (org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.columns.GridColumnRenderer)3 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)2 HasName (org.kie.workbench.common.dmn.api.definition.HasName)2 LiteralExpression (org.kie.workbench.common.dmn.api.definition.v1_1.LiteralExpression)2 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)2 GridDataCache (org.kie.workbench.common.dmn.client.widgets.grid.model.GridDataCache)2 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)2 LienzoMockitoTestRunner (com.ait.lienzo.test.LienzoMockitoTestRunner)1 Arrays (java.util.Arrays)1 Collections (java.util.Collections)1 List (java.util.List)1 Optional (java.util.Optional)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1 Assertions (org.assertj.core.api.Assertions)1 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)1 Assert.assertEquals (org.junit.Assert.assertEquals)1 Assert.assertFalse (org.junit.Assert.assertFalse)1