use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextUIModelMapper method fromDMNModel.
@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
dmnModel.get().ifPresent(context -> {
final boolean isLastRow = isLastRow(rowIndex);
final ContextUIModelMapperHelper.ContextSection section = ContextUIModelMapperHelper.getSection(columnIndex);
switch(section) {
case ROW_INDEX:
if (!isLastRow) {
uiModel.get().setCell(rowIndex, columnIndex, () -> new ContextGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector));
} else {
uiModel.get().setCell(rowIndex, columnIndex, () -> new DMNGridCell<>(new BaseGridCellValue<>((Integer) null)));
}
uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
break;
case NAME:
final InformationItem variable = context.getContextEntry().get(rowIndex).getVariable();
uiModel.get().setCell(rowIndex, columnIndex, () -> new InformationItemCell(() -> InformationItemCell.HasNameAndDataTypeCell.wrap(variable, DEFAULT_ROW_CAPTION), listSelector));
break;
case EXPRESSION:
final ContextEntry ce = context.getContextEntry().get(rowIndex);
final Optional<Expression> expression = Optional.ofNullable(ce.getExpression());
final boolean isOnlyVisualChangeAllowed = this.isOnlyVisualChangeAllowedSupplier.get();
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitionsSupplier.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(ed -> {
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ed.getEditor(new GridCellTuple(rowIndex, columnIndex, gridWidget), Optional.empty(), ce, Optional.ofNullable(ce.getVariable()), isOnlyVisualChangeAllowed, nesting + 1);
uiModel.get().setCell(rowIndex, columnIndex, () -> new ContextGridCell<>(new ExpressionCellValue(editor), listSelector));
});
}
});
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextEditorDefinition method enrich.
@Override
public void enrich(final Optional<String> nodeUUID, final HasExpression hasExpression, final Optional<Context> expression) {
expression.ifPresent(context -> {
final ContextEntry contextEntry = new ContextEntry();
final InformationItem informationItem = new InformationItem();
informationItem.getName().setValue(ContextEntryDefaultValueUtilities.getNewContextEntryName(context));
contextEntry.setVariable(informationItem);
context.getContextEntry().add(contextEntry);
// Add (default) "result" entry
final ContextEntry resultEntry = new ContextEntry();
context.getContextEntry().add(resultEntry);
// Setup parent relationships
contextEntry.setParent(context);
informationItem.setParent(contextEntry);
resultEntry.setParent(context);
});
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextGrid method addContextEntry.
void addContextEntry(final int index) {
getExpression().get().ifPresent(c -> {
final ContextEntry ce = new ContextEntry();
final InformationItem informationItem = new InformationItem();
informationItem.setName(new Name());
ce.setVariable(informationItem);
final CommandResult<CanvasViolation> result = sessionCommandManager.execute((AbstractCanvasHandler) sessionManager.getCurrentSession().getCanvasHandler(), new AddContextEntryCommand(c, ce, model, new ExpressionEditorGridRow(), index, uiModelMapper, () -> resize(BaseExpressionGrid.RESIZE_EXISTING)));
if (!CommandUtils.isError(result)) {
selectCell(index, ContextUIModelMapperHelper.NAME_COLUMN_INDEX, false, false);
startEditingCell(index, ContextUIModelMapperHelper.NAME_COLUMN_INDEX);
}
});
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class ContextPropertyConverter method wbFromDMN.
public static Context wbFromDMN(final org.kie.dmn.model.api.Context dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
final Id id = new Id(dmn.getId());
final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef(), dmn);
final Context result = new Context(id, description, typeRef);
for (org.kie.dmn.model.api.ContextEntry ce : dmn.getContextEntry()) {
final ContextEntry ceConverted = ContextEntryPropertyConverter.wbFromDMN(ce, hasComponentWidthsConsumer);
if (ceConverted != null) {
ceConverted.setParent(result);
}
result.getContextEntry().add(ceConverted);
}
// No need to append a _default_ row if the Context is part of a JAVA or PMML FunctionDefinition
if (dmn.getParent() instanceof FunctionDefinition) {
final FunctionDefinition functionDefinition = (FunctionDefinition) dmn.getParent();
if (!functionDefinition.getKind().equals(FunctionKind.FEEL)) {
return result;
}
}
// The UI requires a ContextEntry for the _default_ result even if none has been defined
final int contextEntriesCount = result.getContextEntry().size();
if (contextEntriesCount == 0) {
result.getContextEntry().add(new ContextEntry());
} else if (!Objects.isNull(result.getContextEntry().get(contextEntriesCount - 1).getVariable())) {
result.getContextEntry().add(new ContextEntry());
}
return result;
}
use of org.kie.workbench.common.dmn.api.definition.model.ContextEntry in project kie-wb-common by kiegroup.
the class BaseContextUIModelMapperTest 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);
final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
expressionEditorDefinitions.add(literalExpressionEditorDefinition);
expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
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));
when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));
this.context = new Context();
this.context.getContextEntry().add(new ContextEntry() {
{
setVariable(new InformationItem() {
{
setName(new Name("ii1"));
}
});
}
});
this.context.getContextEntry().add(new ContextEntry() {
{
setExpression(new LiteralExpression());
}
});
this.mapper = getMapper(isOnlyVisualChangeAllowedSupplier);
this.cellValueSupplier = Optional::empty;
}
Aggregations