Search in sources :

Example 6 with BaseGrid

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

the class ExpressionEditorColumnTest method mockEditor.

@SuppressWarnings("unchecked")
private BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper> 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);
    when(gridWidget.getExpression()).thenReturn(Optional::empty);
    final GridCellTuple parent = new GridCellTuple(0, 0, null);
    final Optional<HasName> hasName = Optional.of(mock(HasName.class));
    return new BaseExpressionGrid(parent, Optional.empty(), HasExpression.NOP, hasName, gridPanel, gridLayer, new DMNGridData(), renderer, definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, cellEditorControls, listSelector, translationService, false, 0, readOnlyProvider) {

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

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

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

        @Override
        public void initialiseUiRows() {
        // Nothing for this test
        }

        @Override
        public void initialiseUiCells() {
        // Nothing for this test
        }

        @Override
        public double getPadding() {
            return padding;
        }
    };
}
Also used : GridColumnRenderer(org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.columns.GridColumnRenderer) Optional(java.util.Optional) HasName(org.kie.workbench.common.dmn.api.definition.HasName) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) BaseGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) 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)

Example 7 with BaseGrid

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

the class DMNGridPanelContextMenuHandlerTest method onContextMenu_WithGridWidget_EventOutsideGridBounds.

@Test
public void onContextMenu_WithGridWidget_EventOutsideGridBounds() {
    when(nativeEvent.getClientX()).thenReturn((int) (COLUMN0_WIDTH + COLUMN1_WIDTH + 50));
    when(nativeEvent.getClientY()).thenReturn((int) ROW_HEIGHT + 50);
    final BaseGrid gridWidget = mockGridWidget();
    when(gridLayer.getGridWidgets()).thenReturn(Collections.singleton(gridWidget));
    handler.onContextMenu(event);
    verify(cellEditorControls, never()).show(any(HasCellEditorControls.Editor.class), anyInt(), anyInt());
}
Also used : BaseGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid) Test(org.junit.Test)

Example 8 with BaseGrid

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

the class DMNGridPanelContextMenuHandlerTest method onContextMenu_WithMultipleOverlappingGridWidgets.

@Test
@SuppressWarnings("unchecked")
public void onContextMenu_WithMultipleOverlappingGridWidgets() {
    final int EVENT_X = (int) (COLUMN0_WIDTH / 2);
    final int EVENT_Y = (int) (HEADER_HEIGHT + ROW_HEIGHT + ROW_HEIGHT / 2);
    when(nativeEvent.getClientX()).thenReturn(EVENT_X);
    when(nativeEvent.getClientY()).thenReturn(EVENT_Y);
    final BaseGrid gridWidget1 = mockGridWidget();
    final BaseGrid gridWidget2 = mockGridWidget();
    // Without stubbing mocks to death this requires some knowledge of the internals of
    // DefaultGridLayer that maintains a LinkedHashSet of GridWidgets added to the Layer.
    // LinkedHashSet returns items in the order in which they were added.
    final Set<GridWidget> gridWidgets = new LinkedHashSet<>();
    gridWidgets.add(gridWidget1);
    gridWidgets.add(gridWidget2);
    when(gridLayer.getGridWidgets()).thenReturn(gridWidgets);
    final MockCell cell1 = mock(MockCell.class);
    gridWidget1.getModel().setCell(1, 0, () -> cell1);
    when(cell1.getEditor()).thenReturn(Optional.of(editor));
    final MockCell cell2 = mock(MockCell.class);
    gridWidget2.getModel().setCell(1, 0, () -> cell2);
    when(cell2.getEditor()).thenReturn(Optional.of(editor));
    handler.onContextMenu(event);
    // gridWidget2 was added second and is therefore considered "on top of" gridWidget1
    verify(editor).bind(eq(gridWidget2), eq(1), eq(0));
    verify(cellEditorControls).show(eq(editor), eq(EVENT_X), eq(EVENT_Y));
}
Also used : LinkedHashSet(java.util.LinkedHashSet) GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) BaseGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid) Test(org.junit.Test)

Example 9 with BaseGrid

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

the class DMNGridPanelContextMenuHandlerTest method onContextMenu_WithGridWidget_WithCellValue_WithOnlyVisualChangeAllowed.

@Test
public void onContextMenu_WithGridWidget_WithCellValue_WithOnlyVisualChangeAllowed() {
    final int EVENT_X = (int) (COLUMN0_WIDTH / 2);
    final int EVENT_Y = (int) (ROW_HEIGHT + ROW_HEIGHT / 2);
    when(nativeEvent.getClientX()).thenReturn(EVENT_X);
    when(nativeEvent.getClientY()).thenReturn(EVENT_Y);
    final BaseGrid gridWidget = mockGridWidget();
    doReturn(true).when(gridWidget).isOnlyVisualChangeAllowed();
    when(gridLayer.getGridWidgets()).thenReturn(Collections.singleton(gridWidget));
    handler.onContextMenu(event);
    verify(cellEditorControls, never()).show(any(HasCellEditorControls.Editor.class), anyInt(), anyInt());
}
Also used : BaseGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid) Test(org.junit.Test)

Example 10 with BaseGrid

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

the class DMNGridPanelContextMenuHandlerTest method onContextMenu_WithGridWidget_WithCellSelectionStrategy_CellNotSelected.

@Test
public void onContextMenu_WithGridWidget_WithCellSelectionStrategy_CellNotSelected() {
    when(nativeEvent.getClientX()).thenReturn((int) (COLUMN0_WIDTH / 2));
    when(nativeEvent.getClientY()).thenReturn((int) (HEADER_HEIGHT + ROW_HEIGHT + ROW_HEIGHT / 2));
    final BaseGrid gridWidget = mockGridWidget();
    when(gridLayer.getGridWidgets()).thenReturn(Collections.singleton(gridWidget));
    final MockCell cell = mock(MockCell.class);
    final CellSelectionStrategy selectionStrategy = mock(CellSelectionStrategy.class);
    gridWidget.getModel().setCell(1, 0, () -> cell);
    when(cell.getEditor()).thenReturn(Optional.of(editor));
    when(cell.getSelectionStrategy()).thenReturn(selectionStrategy);
    handler.onContextMenu(event);
    verify(cellSelectionHandler).selectCellIfRequired(eq(1), eq(0), eq(gridWidget), eq(false), eq(false));
}
Also used : CellSelectionStrategy(org.uberfire.ext.wires.core.grids.client.widget.grid.selections.CellSelectionStrategy) BaseGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid) Test(org.junit.Test)

Aggregations

BaseGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseGrid)12 Test (org.junit.Test)9 DMNGridColumn (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridColumn)2 GridColumn (org.uberfire.ext.wires.core.grids.client.model.GridColumn)2 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)2 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)2 CellSelectionStrategy (org.uberfire.ext.wires.core.grids.client.widget.grid.selections.CellSelectionStrategy)2 Layer (com.ait.lienzo.client.core.shape.Layer)1 LinkedHashSet (java.util.LinkedHashSet)1 Optional (java.util.Optional)1 HasName (org.kie.workbench.common.dmn.api.definition.HasName)1 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)1 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)1 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)1 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)1 DMNGridLayer (org.kie.workbench.common.dmn.client.widgets.layer.DMNGridLayer)1 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)1 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)1 RowNumberColumn (org.uberfire.ext.wires.core.grids.client.widget.grid.columns.RowNumberColumn)1 GridColumnRenderer (org.uberfire.ext.wires.core.grids.client.widget.grid.renderers.columns.GridColumnRenderer)1