Search in sources :

Example 6 with ExpressionCellValue

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());
}
Also used : BaseGridCell(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCell) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) LiteralExpressionGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.literal.LiteralExpressionGrid) GridCell(org.uberfire.ext.wires.core.grids.client.model.GridCell) BaseGridCell(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCell) Test(org.junit.Test)

Example 7 with ExpressionCellValue

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;
}
Also used : BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) DMNGridData(org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Example 8 with ExpressionCellValue

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;
}
Also used : BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) UndefinedExpressionGrid(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionGrid) ArrayList(java.util.ArrayList) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Example 9 with ExpressionCellValue

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;
}
Also used : BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow)

Example 10 with ExpressionCellValue

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();
}
Also used : SetKindCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.function.SetKindCommand) Optional(java.util.Optional) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

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