Search in sources :

Example 1 with ClearExpressionTypeCommand

use of org.kie.workbench.common.dmn.client.commands.expressions.types.invocation.ClearExpressionTypeCommand in project kie-wb-common by kiegroup.

the class InvocationGrid method clearExpressionType.

void clearExpressionType(final int uiRowIndex) {
    final GridCellTuple gc = new GridCellTuple(uiRowIndex, InvocationUIModelMapper.BINDING_EXPRESSION_COLUMN_INDEX, this);
    getExpression().get().ifPresent(invocation -> {
        final HasExpression hasExpression = invocation.getBinding().get(uiRowIndex);
        sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new ClearExpressionTypeCommand(gc, hasExpression, uiModelMapper, () -> {
            resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
            selectExpressionEditorFirstCell(uiRowIndex, InvocationUIModelMapper.BINDING_EXPRESSION_COLUMN_INDEX);
        }, () -> {
            resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
            selectExpressionEditorFirstCell(uiRowIndex, InvocationUIModelMapper.BINDING_EXPRESSION_COLUMN_INDEX);
        }));
    });
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) ClearExpressionTypeCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.invocation.ClearExpressionTypeCommand)

Example 2 with ClearExpressionTypeCommand

use of org.kie.workbench.common.dmn.client.commands.expressions.types.invocation.ClearExpressionTypeCommand in project kie-wb-common by kiegroup.

the class InvocationGridTest method testClearExpressionType.

@Test
public void testClearExpressionType() {
    setupGrid(0);
    grid.clearExpressionType(0);
    verify(sessionCommandManager).execute(eq(canvasHandler), clearExpressionTypeCommandCaptor.capture());
    final ClearExpressionTypeCommand clearExpressionTypeCommand = clearExpressionTypeCommandCaptor.getValue();
    clearExpressionTypeCommand.execute(canvasHandler);
    verify(grid).resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
    verify(gridLayer).select(undefinedExpressionEditor);
    verify(undefinedExpressionEditor).selectFirstCell();
    verify(gridLayer).batch(redrawCommandCaptor.capture());
    redrawCommandCaptor.getValue().execute();
    verify(gridLayer).draw();
    // Check undo operation
    reset(grid, gridLayer);
    clearExpressionTypeCommand.undo(canvasHandler);
    // Verify Expression has been restored and UndefinedExpressionEditor resized
    assertThat(grid.getModel().getColumns().get(2).getWidth()).isEqualTo(UndefinedExpressionColumn.DEFAULT_WIDTH);
    verify(grid).resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
    verify(grid).selectExpressionEditorFirstCell(eq(0), eq(InvocationUIModelMapper.BINDING_EXPRESSION_COLUMN_INDEX));
    verify(gridLayer).select(undefinedExpressionEditor);
    verify(undefinedExpressionEditor, times(2)).selectFirstCell();
    verify(gridLayer).batch(redrawCommandCaptor.capture());
    assertThat(redrawCommandCaptor.getAllValues()).hasSize(2);
    redrawCommandCaptor.getAllValues().get(1).execute();
    verify(gridLayer).draw();
}
Also used : ClearExpressionTypeCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.invocation.ClearExpressionTypeCommand) Test(org.junit.Test)

Aggregations

ClearExpressionTypeCommand (org.kie.workbench.common.dmn.client.commands.expressions.types.invocation.ClearExpressionTypeCommand)2 Test (org.junit.Test)1 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)1 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)1