Search in sources :

Example 1 with ExpressionCellValue

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

the class RelationColumn method getMinimumWidthOfPeers.

private double getMinimumWidthOfPeers() {
    final GridCellTuple parent = gridWidget.getParentInformation();
    final GridData parentUiModel = parent.getGridWidget().getModel();
    final int parentUiRowIndex = parent.getRowIndex();
    final int parentUiColumnIndex = parent.getColumnIndex();
    double minimumWidth = super.getMinimumWidth();
    for (int uiRowIndex = 0; uiRowIndex < parentUiModel.getRowCount(); uiRowIndex++) {
        if (uiRowIndex != parentUiRowIndex) {
            final GridRow row = parentUiModel.getRow(uiRowIndex);
            final GridCell<?> cell = row.getCells().get(parentUiColumnIndex);
            if (cell != null) {
                final GridCellValue<?> value = cell.getValue();
                if (value instanceof ExpressionCellValue) {
                    final ExpressionCellValue ecv = (ExpressionCellValue) value;
                    final Optional<BaseExpressionGrid> editor = ecv.getValue();
                    final double padding = editor.map(BaseExpressionGrid::getPadding).get();
                    minimumWidth = Math.max(minimumWidth, ecv.getMinimumWidth().orElse(0.0) + padding * 2);
                }
            }
        }
    }
    return minimumWidth;
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) 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 2 with ExpressionCellValue

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

the class AddContextEntryCommandTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    this.context = new Context();
    this.contextEntry = new ContextEntry() {

        {
            setVariable(new InformationItem() {

                {
                    setName(new Name("variable"));
                }
            });
        }
    };
    this.defaultResultContextEntry = new ContextEntry();
    this.context.getContextEntry().add(defaultResultContextEntry);
    this.uiModel = new BaseGridData();
    this.uiModelRow = new BaseGridRow();
    this.uiDefaultResultModelRow = new BaseGridRow();
    this.uiModel.appendRow(uiDefaultResultModelRow);
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiNameColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    doReturn(uiModel).when(gridWidget).getModel();
    doReturn(ruleManager).when(handler).getRuleManager();
    doReturn(0).when(uiRowNumberColumn).getIndex();
    doReturn(1).when(uiNameColumn).getIndex();
    doReturn(2).when(uiExpressionEditorColumn).getIndex();
    this.uiModel.setCellValue(0, 2, new ExpressionCellValue(Optional.of(undefinedExpressionEditor)));
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    doReturn(parent).when(undefinedExpressionEditor).getParentInformation();
    doReturn(Optional.empty()).when(undefinedExpressionEditorDefinition).getModelClass();
    doReturn(Optional.of(undefinedExpressionEditor)).when(undefinedExpressionEditorDefinition).getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt());
    this.uiModelMapper = new ContextUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(context), () -> false, () -> expressionEditorDefinitions, listSelector, 0);
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) ContextUIModelMapper(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ContextUIModelMapper) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Before(org.junit.Before)

Example 3 with ExpressionCellValue

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

the class AddContextEntryCommandTest method testCanvasCommandExecuteMultipleEntries.

@Test
public void testCanvasCommandExecuteMultipleEntries() {
    makeCommand();
    // first row
    command.newGraphCommand(handler).execute(gce);
    final Command<AbstractCanvasHandler, CanvasViolation> firstEntryCanvasCommand = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, firstEntryCanvasCommand.execute(handler));
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
    // second row
    final ContextEntry secondRowEntry = new ContextEntry() {

        {
            setVariable(new InformationItem());
        }
    };
    final GridRow uiSecondModelRow = new BaseGridRow();
    command = spy(new AddContextEntryCommand(context, secondRowEntry, uiModel, uiSecondModelRow, context.getContextEntry().size() - 1, uiModelMapper, canvasOperation));
    command.newGraphCommand(handler).execute(gce);
    final Command<AbstractCanvasHandler, CanvasViolation> secondEntryCanvasCommand = command.newCanvasCommand(handler);
    assertEquals(CanvasCommandResultBuilder.SUCCESS, secondEntryCanvasCommand.execute(handler));
    verify(command).updateRowNumbers();
    verify(command).updateParentInformation();
    assertEquals(3, uiModel.getRowCount());
    assertEquals(uiModelRow, uiModel.getRows().get(0));
    assertEquals(uiSecondModelRow, uiModel.getRows().get(1));
    assertEquals(uiDefaultResultModelRow, uiModel.getRows().get(2));
    assertEquals(3, uiModel.getColumnCount());
    assertEquals(uiRowNumberColumn, uiModel.getColumns().get(0));
    assertEquals(uiNameColumn, uiModel.getColumns().get(1));
    assertEquals(uiExpressionEditorColumn, uiModel.getColumns().get(2));
    assertEquals(3, uiModel.getRows().get(0).getCells().size());
    assertEquals(1, uiModel.getCell(0, 0).getValue().getValue());
    assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "1", ((InformationItemCell.HasNameAndDataTypeCell) uiModel.getCell(0, 1).getValue().getValue()).getName().getValue());
    assertTrue(uiModel.getCell(0, 2).getValue() instanceof ExpressionCellValue);
    assertEquals(3, uiModel.getRows().get(1).getCells().size());
    assertEquals(2, uiModel.getCell(1, 0).getValue().getValue());
    assertEquals(ContextEntryDefaultValueUtilities.PREFIX + "2", ((InformationItemCell.HasNameAndDataTypeCell) uiModel.getCell(1, 1).getValue().getValue()).getName().getValue());
    assertTrue(uiModel.getCell(1, 2).getValue() instanceof ExpressionCellValue);
    // Default row
    assertEquals(1, uiModel.getRows().get(2).getCells().size());
    assertTrue(uiModel.getCell(2, 2).getValue() instanceof ExpressionCellValue);
    verify(canvasOperation, times(2)).execute();
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Test(org.junit.Test)

Example 4 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 testOnItemSelectedExpressionColumnUndefinedExpressionType.

@Test
public void testOnItemSelectedExpressionColumnUndefinedExpressionType() {
    setupGrid(0);
    // Clear editor for expression at (0, 0)
    grid.getModel().setCellValue(0, 0, new ExpressionCellValue(Optional.empty()));
    assertNoListItems(grid.getItems(0, 0));
}
Also used : ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) Test(org.junit.Test)

Example 5 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 testSetDefinedExpression.

@Test
public void testSetDefinedExpression() {
    when(hasExpression.getExpression()).thenReturn(literalExpression);
    grid.setExpression(NODE_UUID, hasExpression, Optional.of(hasName), false);
    final GridCellValue<?> gridCellValue = grid.getModel().getCell(0, 0).getValue();
    assertThat(gridCellValue).isInstanceOf(ExpressionCellValue.class);
    final ExpressionCellValue expressionCellValue = (ExpressionCellValue) gridCellValue;
    assertThat(expressionCellValue.getValue().isPresent()).isTrue();
    assertThat(expressionCellValue.getValue().get()).isSameAs(literalExpressionEditor);
    assertThat(grid.isOnlyVisualChangeAllowed()).isFalse();
    verify(literalExpressionEditor).selectFirstCell();
    verify(gridLayer).batch();
}
Also used : ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue) Test(org.junit.Test)

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