Search in sources :

Example 6 with BaseGridCellValue

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.

the class RelationUIModelMapper method fromDMNModel.

@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
    dmnModel.get().ifPresent(relation -> {
        final RelationUIModelMapperHelper.RelationSection section = RelationUIModelMapperHelper.getSection(relation, columnIndex);
        switch(section) {
            case ROW_INDEX:
                uiModel.get().setCell(rowIndex, columnIndex, () -> new RelationGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector, lineHeight));
                uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
                break;
            case INFORMATION_ITEM:
                final org.kie.workbench.common.dmn.api.definition.model.List row = relation.getRow().get(rowIndex);
                final int iiIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, columnIndex);
                final HasExpression hasExpression = row.getExpression().get(iiIndex);
                final Expression e = hasExpression.getExpression();
                final Optional<Expression> expression = Optional.ofNullable(e);
                expression.ifPresent(ex -> {
                    // Whilst the DMN 1.1 specification allows for ANY expression to be used we have made the simplification
                    // to limit ourselves to LiteralExpressions. Our Grid-system supports ANY (nested) expression too; however
                    // the simplification has been made for the benefit of USERS.
                    final LiteralExpression le = (LiteralExpression) ex;
                    uiModel.get().setCell(rowIndex, columnIndex, () -> new RelationGridCell<>(new BaseGridCellValue<>(le.getText().getValue()), listSelector, lineHeight));
                });
        }
    });
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Example 7 with BaseGridCellValue

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.

the class RelationUIModelMapper method toDMNModel.

@Override
public void toDMNModel(final int rowIndex, final int columnIndex, final Supplier<Optional<GridCellValue<?>>> cell) {
    dmnModel.get().ifPresent(relation -> {
        final RelationUIModelMapperHelper.RelationSection section = RelationUIModelMapperHelper.getSection(relation, columnIndex);
        switch(section) {
            case ROW_INDEX:
                break;
            case INFORMATION_ITEM:
                final org.kie.workbench.common.dmn.api.definition.model.List row = relation.getRow().get(rowIndex);
                final int iiIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, columnIndex);
                final HasExpression hasExpression = row.getExpression().get(iiIndex);
                final Expression e = hasExpression.getExpression();
                final Optional<Expression> expression = Optional.ofNullable(e);
                expression.ifPresent(ex -> {
                    // Whilst the DMN 1.1 specification allows for ANY expression to be used we have made the simplification
                    // to limit ourselves to LiteralExpressions. Our Grid-system supports ANY (nested) expression too; however
                    // the simplification has been made for the benefit of USERS.
                    final LiteralExpression le = (LiteralExpression) ex;
                    le.getText().setValue((String) cell.get().orElse(new BaseGridCellValue<>("")).getValue());
                });
        }
    });
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)

Example 8 with BaseGridCellValue

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.

the class RelationGridTest method setUp.

@Before
@SuppressWarnings("unchecked")
public void setUp() {
    when(sessionManager.getCurrentSession()).thenReturn(session);
    when(session.getGridPanel()).thenReturn(gridPanel);
    when(session.getGridLayer()).thenReturn(gridLayer);
    when(session.getCellEditorControls()).thenReturn(cellEditorControls);
    tupleWithoutValue = new GridCellTuple(0, 1, gridWidget);
    tupleWithValue = new GridCellValueTuple<>(0, 1, gridWidget, new BaseGridCellValue<>("value"));
    definition = new RelationEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, headerEditors, readOnlyProvider);
    final Decision decision = new Decision();
    decision.setName(new Name("name"));
    hasName = Optional.of(decision);
    expression = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, expression);
    when(session.getCanvasHandler()).thenReturn(canvasHandler);
    when(parentGridWidget.getModel()).thenReturn(parentGridData);
    when(parentGridData.getColumns()).thenReturn(Collections.singletonList(parentGridColumn));
    parent = spy(new GridCellTuple(0, 0, parentGridWidget));
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(canvasHandler.getGraphExecutionContext()).thenReturn(graphContext);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(Collections.singletonList(node));
    when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
    when(gridLayer.getDomElementContainer()).thenReturn(gridLayerDomElementContainer);
    when(gridLayerDomElementContainer.iterator()).thenReturn(mock(Iterator.class));
    when(gridLayer.getVisibleBounds()).thenReturn(new BaseBounds(0, 0, 200, 200));
    when(gridLayer.getViewport()).thenReturn(viewport);
    when(viewport.getTransform()).thenReturn(transform);
    when(headerEditors.get()).thenReturn(headerEditor);
    when(gridBodyCellEditContext.getRelativeLocation()).thenReturn(Optional.empty());
    doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).format(Mockito.<String>any());
    doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).getTranslation(Mockito.<String>any());
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Iterator(java.util.Iterator) BaseBounds(org.uberfire.ext.wires.core.grids.client.model.impl.BaseBounds) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Before(org.junit.Before)

Example 9 with BaseGridCellValue

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.

the class RelationUIModelMapperTest method testToDMNModelLiteralExpressionsNullValue.

@Test
public void testToDMNModelLiteralExpressionsNullValue() {
    cellValueSupplier = () -> Optional.of(new BaseGridCellValue<>(null));
    for (int uiRowIndex = 0; uiRowIndex < uiModel.getRowCount(); uiRowIndex++) {
        for (int uiColumnIndex = 1; uiColumnIndex < uiModel.getColumnCount(); uiColumnIndex++) {
            mapper.toDMNModel(uiRowIndex, uiColumnIndex, cellValueSupplier);
            final LiteralExpression le = (LiteralExpression) relation.getRow().get(uiRowIndex).getExpression().get(uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT).getExpression();
            assertNull(le.getText().getValue());
        }
    }
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) Test(org.junit.Test)

Example 10 with BaseGridCellValue

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.

the class RelationUIModelMapperTest method testToDMNModelLiteralExpressionsNonEmptyValue.

@Test
public void testToDMNModelLiteralExpressionsNonEmptyValue() {
    for (int uiRowIndex = 0; uiRowIndex < uiModel.getRowCount(); uiRowIndex++) {
        for (int uiColumnIndex = 1; uiColumnIndex < uiModel.getColumnCount(); uiColumnIndex++) {
            final String value = "(" + uiColumnIndex + "," + uiRowIndex + ")";
            cellValueSupplier = () -> Optional.of(new BaseGridCellValue<>(value));
            mapper.toDMNModel(uiRowIndex, uiColumnIndex, cellValueSupplier);
            final LiteralExpression le = (LiteralExpression) relation.getRow().get(uiRowIndex).getExpression().get(uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT).getExpression();
            assertEquals(value, le.getText().getValue());
        }
    }
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) Test(org.junit.Test)

Aggregations

BaseGridCellValue (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)23 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)11 Before (org.junit.Before)7 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)7 Test (org.junit.Test)6 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)5 HasName (org.kie.workbench.common.dmn.api.definition.HasName)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 ExpressionEditorDefinition (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition)5 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)5 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)5 Optional (java.util.Optional)4 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)4 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)4 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)4 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)4 UpdateElementPropertyCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand)4 Element (org.kie.workbench.common.stunner.core.graph.Element)4 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)4 Iterator (java.util.Iterator)3