Search in sources :

Example 31 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class ListGrid method addRow.

void addRow(final int index) {
    getExpression().get().ifPresent(list -> {
        final GridRow listRow = new ExpressionEditorGridRow();
        final HasExpression hasExpression = HasExpression.wrap(list, new LiteralExpression());
        sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new AddListRowCommand(list, hasExpression, model, listRow, index, uiModelMapper, () -> resize(BaseExpressionGrid.RESIZE_EXISTING)));
    });
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) AddListRowCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.list.AddListRowCommand) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) ExpressionEditorGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.ExpressionEditorGridRow) GridRow(org.uberfire.ext.wires.core.grids.client.model.GridRow) ExpressionEditorGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.ExpressionEditorGridRow)

Example 32 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression 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 33 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression 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 34 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class RelationGrid method doAfterSelectionChange.

@Override
public void doAfterSelectionChange(final int uiRowIndex, final int uiColumnIndex) {
    if (hasAnyHeaderCellSelected() || hasMultipleCellsSelected()) {
        super.doAfterSelectionChange(uiRowIndex, uiColumnIndex);
        return;
    }
    if (getExpression().get().isPresent()) {
        final Relation relation = getExpression().get().get();
        final RelationUIModelMapperHelper.RelationSection section = RelationUIModelMapperHelper.getSection(relation, uiColumnIndex);
        if (section == RelationUIModelMapperHelper.RelationSection.INFORMATION_ITEM) {
            final int iiIndex = RelationUIModelMapperHelper.getInformationItemIndex(relation, uiColumnIndex);
            final HasExpression hasExpression = relation.getRow().get(uiRowIndex).getExpression().get(iiIndex);
            final Expression expression = hasExpression.getExpression();
            if (expression instanceof DomainObject) {
                final DomainObject domainObject = (DomainObject) expression;
                fireDomainObjectSelectionEvent(domainObject);
                return;
            }
        }
    }
    super.doAfterSelectionChange(uiRowIndex, uiColumnIndex);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Relation(org.kie.workbench.common.dmn.api.definition.model.Relation) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) DomainObject(org.kie.workbench.common.stunner.core.domainobject.DomainObject)

Example 35 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class AddListRowCommandTest method testGraphCommandExecuteMultipleEntriesPresent.

@Test
public void testGraphCommandExecuteMultipleEntriesPresent() {
    final HasExpression firstEntry = HasExpression.wrap(list, new LiteralExpression());
    list.getExpression().add(0, firstEntry);
    makeCommand();
    final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
    assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
    assertEquals(2, list.getExpression().size());
    assertEquals(firstEntry, list.getExpression().get(0));
    assertEquals(hasExpression, list.getExpression().get(1));
    assertEquals(list, hasExpression.asDMNModelInstrumentedBase().getParent());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) GraphCommandExecutionContext(org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Test(org.junit.Test)

Aggregations

HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)78 Test (org.junit.Test)41 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)30 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)24 HasName (org.kie.workbench.common.dmn.api.definition.HasName)18 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)15 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)15 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)15 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)15 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)13 Optional (java.util.Optional)12 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)12 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)10 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)10 ExpressionEditorDefinition (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition)8 ExpressionEditorDefinitions (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions)8 ArrayList (java.util.ArrayList)7 EditExpressionEvent (org.kie.workbench.common.dmn.client.events.EditExpressionEvent)6 Before (org.junit.Before)5