use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class SetCellValueCommand method newCanvasCommand.
@Override
protected Command<AbstractCanvasHandler, CanvasViolation> newCanvasCommand(final AbstractCanvasHandler context) {
return new AbstractCanvasCommand() {
@Override
public CommandResult<CanvasViolation> execute(final AbstractCanvasHandler context) {
if (!editor.isPresent()) {
editor = editorSupplier.get();
}
nodeUUID.ifPresent(uuid -> expressionGridCache.putExpressionGrid(uuid, editor));
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 context) {
nodeUUID.ifPresent(expressionGridCache::removeExpressionGrid);
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 CommandUtils method updateParentInformation.
public static void updateParentInformation(final GridData uiModel) {
final Optional<ExpressionEditorColumn> expressionColumn = uiModel.getColumns().stream().filter(c -> c instanceof ExpressionEditorColumn).map(c -> (ExpressionEditorColumn) c).findFirst();
expressionColumn.ifPresent(c -> {
final int columnIndex = uiModel.getColumns().indexOf(c);
for (int rowIndex = 0; rowIndex < uiModel.getRowCount(); rowIndex++) {
final GridCell<?> cell = uiModel.getCell(rowIndex, columnIndex);
if (cell != null) {
final GridCellValue<?> value = cell.getValue();
if (value instanceof ExpressionCellValue) {
final ExpressionCellValue ecv = (ExpressionCellValue) value;
if (ecv.getValue().isPresent()) {
final BaseExpressionGrid beg = ecv.getValue().get();
beg.getParentInformation().setRowIndex(rowIndex);
beg.getParentInformation().setColumnIndex(columnIndex);
}
}
}
}
});
}
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) {
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.ofNullable(function.getExpression())), eq(Optional.empty()), 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 BaseFunctionSupplementaryGridTest 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 RowNumberColumn);
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], uiModel.getCell(i, 1).getValue().getValue());
assertTrue(uiModel.getCell(i, 2).getValue() instanceof ExpressionCellValue);
final ExpressionCellValue dcv = (ExpressionCellValue) uiModel.getCell(i, 2).getValue();
assertEquals(literalExpressionEditor, dcv.getValue().get());
}
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class InvocationUIModelMapperTest method testFromDMNModelBindingExpression.
@Test
@SuppressWarnings("unchecked")
public void testFromDMNModelBindingExpression() {
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).getExpression())), eq(Optional.of(invocation.getBinding().get(0).getParameter())), eq(1));
final GridCellTuple parent = parentCaptor.getValue();
assertEquals(0, parent.getRowIndex());
assertEquals(2, parent.getColumnIndex());
assertEquals(gridWidget, parent.getGridWidget());
}
Aggregations