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;
}
};
}
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);
}
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());
}
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());
}
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());
}
Aggregations