Search in sources :

Example 31 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression 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 32 with Expression

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

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

the class DecisionNavigatorObserverTest method testSelectItemWhenExpressionIsNotNull.

@Test
public void testSelectItemWhenExpressionIsNotNull() {
    final EditExpressionEvent event = makeEditExpressionEvent();
    final Expression expression = mock(Expression.class);
    final Id id = mock(Id.class);
    when(hasExpression.getExpression()).thenReturn(expression);
    when(expression.getId()).thenReturn(id);
    when(id.getValue()).thenReturn(uuid);
    observer.init(presenter);
    observer.selectItem(event.getHasExpression());
    verify(treePresenter).selectItem(uuid);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) Test(org.junit.Test)

Example 34 with Expression

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

the class RegisterNodeCommandTest method testExecuteWithBusinessKnowledgeModelNodeWhenNodeIsNotNew.

@Test
public void testExecuteWithBusinessKnowledgeModelNodeWhenNodeIsNotNew() {
    final FunctionDefinition functionDefinition = new FunctionDefinition();
    final LiteralExpression literalExpression = makeLiteralExpression("123");
    when(candidateContent.getDefinition()).thenReturn(businessKnowledgeModel);
    doReturn(functionDefinition).when(businessKnowledgeModel).getEncapsulatedLogic();
    functionDefinition.setExpression(literalExpression);
    literalExpression.setParent(functionDefinition);
    assertThat(command.execute(graphCommandExecutionContext).getType()).isEqualTo(CommandResult.Type.INFO);
    final FunctionDefinition encapsulatedLogic = businessKnowledgeModel.getEncapsulatedLogic();
    final Expression expression = encapsulatedLogic.getExpression();
    assertThat(expression).isEqualTo(makeLiteralExpression("123"));
    assertThat(expression.getParent()).isEqualTo(encapsulatedLogic);
    assertThat(KindUtilities.getKind(encapsulatedLogic)).isEqualTo(FunctionDefinition.Kind.FEEL);
}
Also used : LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) Test(org.junit.Test) AbstractGraphCommandTest(org.kie.workbench.common.stunner.core.graph.command.impl.AbstractGraphCommandTest)

Example 35 with Expression

use of org.kie.workbench.common.dmn.api.definition.model.Expression 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)

Aggregations

Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)75 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)41 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)29 Test (org.junit.Test)27 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)26 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)26 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)25 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)14 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)14 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)12 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)11 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)10 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)9 ArrayList (java.util.ArrayList)8 Context (org.kie.workbench.common.dmn.api.definition.model.Context)8 FunctionDefinition (org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition)8 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)7 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)7 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)7