Search in sources :

Example 41 with Expression

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

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

the class PropertiesPanelNotifierTest method testNotifyExpressions.

@Test
public void testNotifyExpressions() {
    final Node node = mock(Node.class);
    final HasExpression hasExpression = mock(HasExpression.class);
    final Expression expression = mock(Expression.class);
    final HasTypeRef hasTypeRef1 = mock(HasTypeRef.class);
    final HasTypeRef hasTypeRef2 = mock(HasTypeRef.class);
    when(expression.getHasTypeRefs()).thenReturn(asList(hasTypeRef1, hasTypeRef2));
    when(hasExpression.getExpression()).thenReturn(expression);
    doNothing().when(notifier).notifyOutdatedElement(any(), any());
    notifier.notifyExpressions(node, hasExpression);
    verify(notifier).notifyOutdatedElement(node, hasTypeRef1);
    verify(notifier).notifyOutdatedElement(node, hasTypeRef2);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) Node(org.kie.workbench.common.stunner.core.graph.Node) Test(org.junit.Test)

Example 43 with Expression

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

the class DMNElementsSynchronizerTest method testSynchronizeDecisionNodeNode.

@Test
public void testSynchronizeDecisionNodeNode() {
    final Decision from = mock(Decision.class);
    final Decision to = mock(Decision.class);
    final Question question = mock(Question.class);
    final AllowedAnswers allowedAnswers = mock(AllowedAnswers.class);
    final Expression expression = mock(Expression.class);
    final InformationItemPrimary variable = mock(InformationItemPrimary.class);
    when(from.getQuestion()).thenReturn(question);
    when(from.getAllowedAnswers()).thenReturn(allowedAnswers);
    when(from.getExpression()).thenReturn(expression);
    when(from.getVariable()).thenReturn(variable);
    synchronizer.synchronizeDecisionNode(from, to);
    verify(to).setQuestion(question);
    verify(to).setAllowedAnswers(allowedAnswers);
    verify(to).setExpression(expression);
    verify(to).setVariable(variable);
}
Also used : InformationItemPrimary(org.kie.workbench.common.dmn.api.definition.model.InformationItemPrimary) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) Question(org.kie.workbench.common.dmn.api.property.dmn.Question) AllowedAnswers(org.kie.workbench.common.dmn.api.property.dmn.AllowedAnswers) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) Test(org.junit.Test)

Example 44 with Expression

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

the class DMNMarshallerStandaloneTest method checkDecisionWithContextWithoutDefaultResult.

private void checkDecisionWithContextWithoutDefaultResult(Graph<?, Node<?, ?>> g) {
    Node<?, ?> decisionNode = g.getNode("_30810b88-8416-4c02-8ed1-8c19b7606243");
    assertNodeContentDefinitionIs(decisionNode, Decision.class);
    Context context = (Context) ((Decision) ((View<?>) decisionNode.getContent()).getDefinition()).getExpression();
    InformationItem defaultResultVariable = context.getContextEntry().get(1).getVariable();
    assertNull("Default result variable", defaultResultVariable);
    Expression defaultResultExpression = context.getContextEntry().get(1).getExpression();
    assertNull("Default result expression", defaultResultExpression);
}
Also used : NamespaceContext(javax.xml.namespace.NamespaceContext) DMNContext(org.kie.dmn.api.core.DMNContext) Context(org.kie.workbench.common.dmn.api.definition.model.Context) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 45 with Expression

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

the class DMNMarshallerStandaloneTest method checkDecisionExpression.

private static void checkDecisionExpression(final Graph<?, Node<View, ?>> unmarshalledGraph, final Expression expression) {
    final Node<View, ?> decisionNode = nodeOfDefinition(unmarshalledGraph.nodes().iterator(), Decision.class);
    final Expression decisionNodeExpression = ((Decision) DefinitionUtils.getElementDefinition(decisionNode)).getExpression();
    // The process of marshalling an Expression that has been programmatically instantiated (vs created in the UI)
    // leads to the _source_ Expression ComponentWidths being initialised. Therefore to ensure a like-for-like equality
    // comparison ensure the unmarshalled _target_ Expression has had it's ComponentWidths initialised too.
    decisionNodeExpression.getComponentWidths();
    ((Context) decisionNodeExpression).getContextEntry().get(0).getExpression().getComponentWidths();
    assertThat(decisionNodeExpression).isEqualTo(expression);
}
Also used : Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) View(org.kie.workbench.common.stunner.core.graph.content.view.View) TDecision(org.kie.dmn.model.v1_2.TDecision) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision)

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