Search in sources :

Example 16 with Binding

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

the class InvocationGrid method addParameterBinding.

void addParameterBinding(final int index) {
    getExpression().get().ifPresent(invocation -> {
        final Binding binding = new Binding();
        final InformationItem parameter = new InformationItem();
        parameter.setName(new Name());
        binding.setParameter(parameter);
        final CommandResult<CanvasViolation> result = sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new AddParameterBindingCommand(invocation, binding, model, new ExpressionEditorGridRow(), index, uiModelMapper, () -> resize(BaseExpressionGrid.RESIZE_EXISTING)));
        if (!CommandUtils.isError(result)) {
            selectCell(index, InvocationUIModelMapper.BINDING_PARAMETER_COLUMN_INDEX, false, false);
            startEditingCell(index, InvocationUIModelMapper.BINDING_PARAMETER_COLUMN_INDEX);
        }
    });
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) AddParameterBindingCommand(org.kie.workbench.common.dmn.client.commands.expressions.types.invocation.AddParameterBindingCommand) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) ExpressionEditorGridRow(org.kie.workbench.common.dmn.client.widgets.grid.model.ExpressionEditorGridRow) HasName(org.kie.workbench.common.dmn.api.definition.HasName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 17 with Binding

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

the class BindingPropertyConverter method wbFromDMN.

public static Binding wbFromDMN(final org.kie.dmn.model.api.Binding dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    if (dmn == null) {
        return null;
    }
    final InformationItem convertedParameter = InformationItemPropertyConverter.wbFromDMN(dmn.getParameter());
    final Expression convertedExpression = ExpressionPropertyConverter.wbFromDMN(dmn.getExpression(), hasComponentWidthsConsumer);
    final Binding result = new Binding();
    if (convertedParameter != null) {
        convertedParameter.setParent(result);
    }
    result.setParameter(convertedParameter);
    if (convertedExpression != null) {
        convertedExpression.setParent(result);
    }
    result.setExpression(convertedExpression);
    return result;
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem)

Example 18 with Binding

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

the class InvocationUIModelMapperTest method setup.

@SuppressWarnings("unchecked")
public void setup(final boolean isOnlyVisualChangeAllowedSupplier) {
    this.uiModel = new BaseGridData();
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiNameColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    when(uiRowNumberColumn.getIndex()).thenReturn(0);
    when(uiNameColumn.getIndex()).thenReturn(1);
    when(uiExpressionEditorColumn.getIndex()).thenReturn(2);
    when(gridWidget.getModel()).thenReturn(uiModel);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
    when(literalExpressionEditor.getExpression()).thenReturn(() -> Optional.of(literalExpression));
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    final LiteralExpression invocationExpression = new LiteralExpression();
    invocationExpression.getText().setValue("invocation-expression");
    final LiteralExpression bindingExpression = new LiteralExpression();
    bindingExpression.getText().setValue("binding-expression");
    final Binding binding = new Binding();
    final InformationItem parameter = new InformationItem();
    parameter.setName(new Name("p0"));
    binding.setParameter(parameter);
    binding.setExpression(bindingExpression);
    this.invocation = new Invocation();
    this.invocation.setExpression(invocationExpression);
    this.invocation.getBinding().add(binding);
    this.mapper = new InvocationUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(invocation), () -> isOnlyVisualChangeAllowedSupplier, expressionEditorDefinitionsSupplier, listSelector, 0);
    this.cellValueSupplier = Optional::empty;
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) 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) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 19 with Binding

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

the class InvocationDefaultValueUtilitiesTest method testGetNewParameterName.

@Test
public void testGetNewParameterName() {
    final Binding binding1 = new Binding() {

        {
            setParameter(new InformationItem());
        }
    };
    invocation.getBinding().add(binding1);
    binding1.getParameter().getName().setValue(InvocationDefaultValueUtilities.getNewParameterName(invocation));
    assertThat(binding1.getParameter().getName().getValue()).isEqualTo(InvocationDefaultValueUtilities.PREFIX + "1");
    final Binding binding2 = new Binding() {

        {
            setParameter(new InformationItem());
        }
    };
    invocation.getBinding().add(binding2);
    binding2.getParameter().getName().setValue(InvocationDefaultValueUtilities.getNewParameterName(invocation));
    assertThat(binding2.getParameter().getName().getValue()).isEqualTo(InvocationDefaultValueUtilities.PREFIX + "2");
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Test(org.junit.Test)

Example 20 with Binding

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

the class InvocationDefaultValueUtilitiesTest method testGetNewParameterNameWithExistingParameters.

@Test
public void testGetNewParameterNameWithExistingParameters() {
    final Binding binding1 = new Binding() {

        {
            setParameter(new InformationItem());
        }
    };
    invocation.getBinding().add(binding1);
    binding1.getParameter().getName().setValue("binding");
    final Binding binding2 = new Binding() {

        {
            setParameter(new InformationItem());
        }
    };
    invocation.getBinding().add(binding2);
    binding2.getParameter().getName().setValue(InvocationDefaultValueUtilities.getNewParameterName(invocation));
    assertThat(binding2.getParameter().getName().getValue()).isEqualTo(InvocationDefaultValueUtilities.PREFIX + "1");
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) Test(org.junit.Test)

Aggregations

Binding (org.kie.workbench.common.dmn.api.definition.model.Binding)26 Test (org.junit.Test)13 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)13 GraphCommandExecutionContext (org.kie.workbench.common.stunner.core.graph.command.GraphCommandExecutionContext)7 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)7 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)5 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)5 Invocation (org.kie.workbench.common.dmn.api.definition.model.Invocation)4 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)4 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)3 JSITBinding (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITBinding)3 JSITExpression (org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)3 Optional (java.util.Optional)2 TBinding (org.kie.dmn.model.v1_2.TBinding)2 TInformationItem (org.kie.dmn.model.v1_2.TInformationItem)2 TLiteralExpression (org.kie.dmn.model.v1_2.TLiteralExpression)2 HasComponentWidths (org.kie.workbench.common.dmn.api.definition.HasComponentWidths)2 Description (org.kie.workbench.common.dmn.api.property.dmn.Description)2 Id (org.kie.workbench.common.dmn.api.property.dmn.Id)2 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)2