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);
}
});
}
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;
}
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;
}
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");
}
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");
}
Aggregations