Search in sources :

Example 51 with ExpressionCellValue

use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.

the class SetKindCommand method newCanvasCommand.

@Override
protected Command<AbstractCanvasHandler, CanvasViolation> newCanvasCommand(final AbstractCanvasHandler handler) {
    return new AbstractCanvasCommand() {

        @Override
        public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler handler) {
            if (!editor.isPresent()) {
                editor = editorSupplier.get();
            }
            final ExpressionCellValue value = new ExpressionCellValue(editor);
            final GridData gridData = cellTuple.getGridWidget().getModel();
            gridData.setCellValue(cellTuple.getRowIndex(), cellTuple.getColumnIndex(), value);
            executeCanvasOperation.execute(editor);
            return CanvasCommandResultBuilder.SUCCESS;
        }

        @Override
        public CommandResult<CanvasViolation> undo(final AbstractCanvasHandler handler) {
            if (oldCellValue.isPresent()) {
                cellTuple.getGridWidget().getModel().setCellValue(cellTuple.getRowIndex(), cellTuple.getColumnIndex(), oldCellValue.get());
            } else {
                cellTuple.getGridWidget().getModel().deleteCell(cellTuple.getRowIndex(), cellTuple.getColumnIndex());
            }
            undoCanvasOperation.execute();
            return CanvasCommandResultBuilder.SUCCESS;
        }
    };
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) AbstractCanvasCommand(org.kie.workbench.common.stunner.core.client.canvas.command.AbstractCanvasCommand)

Example 52 with ExpressionCellValue

use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.

the class AddListRowCommandTest method testCanvasCommandUndoRedoReuseEditor.

@Test
public void testCanvasCommandUndoRedoReuseEditor() {
    makeCommand();
    // Add Graph row first as ContextUIModelMapper relies on the model being first updated
    command.newGraphCommand(handler).execute(gce);
    // Add row and assert editor instance
    final Command<AbstractCanvasHandler, CanvasViolation> cc = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.execute(handler));
    verify(uiModelMapper).fromDMNModel(0, ListUIModelMapperHelper.EXPRESSION_COLUMN_INDEX);
    final GridCellValue<?> originalCellValue = uiModel.getCell(0, EXPRESSION_COLUMN_INDEX).getValue();
    assertTrue(originalCellValue instanceof ExpressionCellValue);
    final BaseExpressionGrid originalEditor = ((ExpressionCellValue) originalCellValue).getValue().get();
    assertEquals(literalExpressionEditor, originalEditor);
    // Undo addition
    reset(command, canvasOperation);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.undo(handler));
    // Redo addition and assert the same editor instance was reused
    reset(command, canvasOperation);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, cc.execute(handler));
    verify(uiModelMapper).fromDMNModel(0, ListUIModelMapperHelper.EXPRESSION_COLUMN_INDEX);
    final GridCellValue<?> redoCellValue = uiModel.getCell(0, EXPRESSION_COLUMN_INDEX).getValue();
    assertTrue(redoCellValue instanceof ExpressionCellValue);
    final BaseExpressionGrid redoEditor = ((ExpressionCellValue) redoCellValue).getValue().get();
    assertEquals(literalExpressionEditor, redoEditor);
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) Test(org.junit.Test)

Example 53 with ExpressionCellValue

use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.

the class InvocationUIModelMapperTest method assertFromDMNModelBindingExpression.

private void assertFromDMNModelBindingExpression(final boolean isOnlyVisualChangeAllowed) {
    mapper.fromDMNModel(0, 2);
    assertNotNull(uiModel.getCell(0, 2));
    assertTrue(uiModel.getCell(0, 2).getValue() instanceof ExpressionCellValue);
    final ExpressionCellValue dcv = (ExpressionCellValue) uiModel.getCell(0, 2).getValue();
    assertEquals(literalExpressionEditor, dcv.getValue().get());
    verify(literalExpressionEditorDefinition).getEditor(parentCaptor.capture(), eq(Optional.empty()), eq(invocation.getBinding().get(0)), eq(Optional.of(invocation.getBinding().get(0).getParameter())), eq(isOnlyVisualChangeAllowed), eq(1));
    final GridCellTuple parent = parentCaptor.getValue();
    assertEquals(0, parent.getRowIndex());
    assertEquals(2, parent.getColumnIndex());
    assertEquals(gridWidget, parent.getGridWidget());
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Example 54 with ExpressionCellValue

use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.

the class FunctionUIModelMapperTest method assertFromDMNModelEditor.

@SuppressWarnings("unchecked")
private void assertFromDMNModelEditor(final BaseExpressionGrid editor, final ExpressionEditorDefinition definition, final boolean isOnlyVisualChangeAllowedSupplier) {
    assertTrue(uiModel.getCell(0, 0).getValue() instanceof ExpressionCellValue);
    final ExpressionCellValue dcv = (ExpressionCellValue) uiModel.getCell(0, 0).getValue();
    assertEquals(editor, dcv.getValue().get());
    verify(definition).getEditor(parentCaptor.capture(), eq(Optional.empty()), eq(function), eq(Optional.empty()), eq(isOnlyVisualChangeAllowedSupplier), eq(1));
    final GridCellTuple parent = parentCaptor.getValue();
    assertEquals(0, parent.getRowIndex());
    assertEquals(0, parent.getColumnIndex());
    assertEquals(gridWidget, parent.getGridWidget());
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Example 55 with ExpressionCellValue

use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.

the class PMMLFunctionSupplementaryGridTest method testInitialSetupFromDefinition.

@Test
public void testInitialSetupFromDefinition() {
    setupGrid(0);
    final GridData uiModel = grid.getModel();
    assertTrue(uiModel instanceof FunctionSupplementaryGridData);
    assertEquals(3, uiModel.getColumnCount());
    assertTrue(uiModel.getColumns().get(0) instanceof ContextGridRowNumberColumn);
    assertTrue(uiModel.getColumns().get(1) instanceof NameColumn);
    assertTrue(uiModel.getColumns().get(2) instanceof ExpressionEditorColumn);
    assertEquals(2, uiModel.getRowCount());
    final String[] expectedNames = getExpectedNames();
    for (int i = 0; i < uiModel.getRowCount(); i++) {
        assertEquals(i + 1, uiModel.getCell(i, 0).getValue().getValue());
        assertEquals(expectedNames[i], ((InformationItemCell.HasNameAndDataTypeCell) uiModel.getCell(i, 1).getValue().getValue()).getName().getValue());
        assertTrue(uiModel.getCell(i, 2).getValue() instanceof ExpressionCellValue);
    }
    final ExpressionCellValue dcv0 = (ExpressionCellValue) uiModel.getCell(0, 2).getValue();
    assertEquals(literalExpressionPMMLDocumentEditor, dcv0.getValue().get());
    final ExpressionCellValue dcv1 = (ExpressionCellValue) uiModel.getCell(1, 2).getValue();
    assertEquals(literalExpressionPMMLDocumentModelEditor, dcv1.getValue().get());
}
Also used : FunctionSupplementaryGridData(org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.FunctionSupplementaryGridData) ExpressionEditorColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionEditorColumn) NameColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.NameColumn) FunctionSupplementaryGridData(org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.FunctionSupplementaryGridData) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) ContextGridRowNumberColumn(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ContextGridRowNumberColumn) Test(org.junit.Test) BaseFunctionSupplementaryGridTest(org.kie.workbench.common.dmn.client.editors.expressions.types.function.supplementary.BaseFunctionSupplementaryGridTest)

Aggregations

ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)63 Test (org.junit.Test)28 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)22 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)21 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)17 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)14 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)12 ExpressionEditorColumn (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionEditorColumn)11 GridCell (org.uberfire.ext.wires.core.grids.client.model.GridCell)10 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)10 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)10 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)9 GridRow (org.uberfire.ext.wires.core.grids.client.model.GridRow)9 Optional (java.util.Optional)8 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)8 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)8 Before (org.junit.Before)6 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)6 CanvasViolation (org.kie.workbench.common.stunner.core.client.command.CanvasViolation)6 GridColumn (org.uberfire.ext.wires.core.grids.client.model.GridColumn)6