use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class ExpressionContainerGridTest method testGetBaseExpressionGrid.
@Test
public void testGetBaseExpressionGrid() {
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> expectedBaseExpressionGrid = Optional.of(mock(LiteralExpressionGrid.class));
final ExpressionCellValue value = mock(ExpressionCellValue.class);
final GridCell<?> cell = new BaseGridCell<>(value);
final Supplier<GridCell<?>> cellSupplier = () -> cell;
when(value.getValue()).thenReturn(expectedBaseExpressionGrid);
grid.getModel().setCell(0, 0, cellSupplier);
assertEquals(expectedBaseExpressionGrid, grid.getBaseExpressionGrid());
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class ExpressionContainerGrid method getExistingEditorWidth.
double getExistingEditorWidth() {
double existingWidth = DMNGridColumn.DEFAULT_WIDTH;
final GridCell<?> cell = model.getRow(0).getCells().get(0);
if (cell != null) {
final GridCellValue<?> value = cell.getValue();
if (value instanceof ExpressionCellValue) {
final ExpressionCellValue ecv = (ExpressionCellValue) value;
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ecv.getValue();
if (editor.isPresent()) {
final BaseExpressionGrid beg = editor.get();
existingWidth = Collections.max(Arrays.asList(existingWidth, beg.getWidth() + beg.getPadding() * 2, beg.getMinimumWidth() + beg.getPadding() * 2));
}
}
}
return existingWidth;
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class FunctionGrid method getItems.
@Override
@SuppressWarnings("unused")
public List<ListSelectorItem> getItems(final int uiRowIndex, final int uiColumnIndex) {
final List<ListSelectorItem> items = new ArrayList<>();
final FunctionDefinition.Kind kind = KindUtilities.getKind(getExpression().get().get());
// If cell editor is UndefinedExpressionGrid don't add extra items
final GridCell<?> cell = model.getCell(uiRowIndex, uiColumnIndex);
final ExpressionCellValue ecv = (ExpressionCellValue) cell.getValue();
if (!ecv.getValue().isPresent()) {
return items;
}
final BaseExpressionGrid grid = ecv.getValue().get();
if (grid instanceof UndefinedExpressionGrid) {
return items;
}
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ExpressionEditor_Clear), true, () -> {
cellEditorControls.hide();
gridPanel.setFocus(true);
clearExpressionType();
}));
return items;
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class GridCellTuple method getRequiredParentColumnWidth.
private double getRequiredParentColumnWidth(final double proposedWidth, final Function<BaseExpressionGrid, Double> requiredWidthSupplier) {
double width = proposedWidth;
final GridData uiModel = gridWidget.getModel();
for (GridRow row : uiModel.getRows()) {
final GridCell<?> cell = row.getCells().get(columnIndex);
if (cell != null) {
final GridCellValue<?> value = cell.getValue();
if (value instanceof ExpressionCellValue) {
final ExpressionCellValue ecv = (ExpressionCellValue) value;
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ecv.getValue();
if (editor.isPresent()) {
final BaseExpressionGrid beg = editor.get();
width = Math.max(width, requiredWidthSupplier.apply(beg));
}
}
}
}
return width;
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class FunctionGridTest method assertSetKind.
@SuppressWarnings("unchecked")
private void assertSetKind(final ExpressionEditorDefinition definition, final BaseExpressionGrid editor, final FunctionDefinition.Kind expectedKind, final Class<?> expectedExpressionType, final Class<?> expectedEditorType) {
verify(grid).doSetKind(eq(expectedKind), eq(expression.get()), expressionDefinitionCaptor.capture());
verify(definition).enrich(any(Optional.class), eq(hasExpression), any(Optional.class));
final ExpressionEditorDefinition<Expression> expressionDefinition = expressionDefinitionCaptor.getValue().get();
assertThat(expectedExpressionType).isAssignableFrom(expressionDefinition.getModelClass().get().getClass());
verify(sessionCommandManager).execute(eq(canvasHandler), setKindCommandCaptor.capture());
final SetKindCommand setKindCommand = setKindCommandCaptor.getValue();
setKindCommand.execute(canvasHandler);
final GridCellValue<?> gcv = grid.getModel().getCell(0, 1).getValue();
assertTrue(gcv instanceof ExpressionCellValue);
final ExpressionCellValue ecv = (ExpressionCellValue) gcv;
assertThat(expectedEditorType).isAssignableFrom(ecv.getValue().get().getClass());
verify(editor).resize(eq(BaseExpressionGrid.RESIZE_EXISTING));
verify(editor).selectFirstCell();
verify(gridLayer).batch(redrawCommandCaptor.capture());
redrawCommandCaptor.getValue().execute();
verify(gridLayer).draw();
// Check undo operation
reset(grid, gridLayer);
setKindCommand.undo(canvasHandler);
verify(grid).resize(BaseExpressionGrid.RESIZE_EXISTING_MINIMUM);
verify(grid).selectFirstCell();
verify(gridLayer).batch(redrawCommandCaptor.capture());
assertThat(redrawCommandCaptor.getAllValues()).hasSize(2);
redrawCommandCaptor.getAllValues().get(1).execute();
verify(gridLayer).draw();
}
Aggregations