use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class ListGrid method addRow.
void addRow(final int index) {
getExpression().get().ifPresent(list -> {
final GridRow listRow = new ExpressionEditorGridRow();
final HasExpression hasExpression = HasExpression.wrap(list, new LiteralExpression());
sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new AddListRowCommand(list, hasExpression, model, listRow, index, uiModelMapper, () -> resize(BaseExpressionGrid.RESIZE_EXISTING)));
});
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.
the class RelationUIModelMapper method fromDMNModel.
@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
dmnModel.get().ifPresent(relation -> {
final RelationUIModelMapperHelper.RelationSection section = RelationUIModelMapperHelper.getSection(relation, columnIndex);
switch(section) {
case ROW_INDEX:
uiModel.get().setCell(rowIndex, columnIndex, () -> new RelationGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector, lineHeight));
uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
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;
uiModel.get().setCell(rowIndex, columnIndex, () -> new RelationGridCell<>(new BaseGridCellValue<>(le.getText().getValue()), listSelector, lineHeight));
});
}
});
}
use of org.kie.workbench.common.dmn.api.definition.HasExpression 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.HasExpression 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.HasExpression in project kie-wb-common by kiegroup.
the class AddListRowCommandTest method testGraphCommandExecuteMultipleEntriesPresent.
@Test
public void testGraphCommandExecuteMultipleEntriesPresent() {
final HasExpression firstEntry = HasExpression.wrap(list, new LiteralExpression());
list.getExpression().add(0, firstEntry);
makeCommand();
final Command<GraphCommandExecutionContext, RuleViolation> c = command.newGraphCommand(handler);
assertEquals(GraphCommandResultBuilder.SUCCESS, c.execute(gce));
assertEquals(2, list.getExpression().size());
assertEquals(firstEntry, list.getExpression().get(0));
assertEquals(hasExpression, list.getExpression().get(1));
assertEquals(list, hasExpression.asDMNModelInstrumentedBase().getParent());
}
Aggregations