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