use of org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper in project kie-wb-common by kiegroup.
the class LiteralExpressionEditorDefinitionTest method testEditor.
@Test
public void testEditor() {
when(hasExpression.getExpression()).thenReturn(definition.getModelClass().get());
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> oEditor = definition.getEditor(parent, Optional.empty(), hasExpression, hasName, false, 0);
assertThat(oEditor).isPresent();
final GridWidget editor = oEditor.get();
assertThat(editor).isInstanceOf(LiteralExpressionGrid.class);
}
use of org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper 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.client.widgets.grid.model.BaseUIModelMapper in project kie-wb-common by kiegroup.
the class ExpressionContainerGrid method getExistingEditor.
Optional<BaseExpressionGrid> getExistingEditor() {
Optional<BaseExpressionGrid> beg = Optional.empty();
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()) {
beg = Optional.of(editor.get());
}
}
}
return beg;
}
use of org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper in project kie-wb-common by kiegroup.
the class ExpressionContainerUIModelMapper method fromDMNModel.
@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
final String uuid = nodeUUID.get();
final GridData uiModel = this.uiModel.get();
final Optional<Expression> expression = dmnModel.get();
final Optional<HasName> hasName = this.hasName.get();
final boolean isOnlyVisualChangeAllowed = this.isOnlyVisualChangeAllowedSupplier.get();
final HasExpression hasExpression = this.hasExpression.get();
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitions.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(definition -> {
Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = expressionGridCache.get().getExpressionGrid(uuid);
if (!editor.isPresent()) {
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> oEditor = definition.getEditor(parent, Optional.of(uuid), hasExpression, hasName, isOnlyVisualChangeAllowed, 0);
expressionGridCache.get().putExpressionGrid(uuid, oEditor);
editor = oEditor;
}
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> _editor = editor;
uiModel.setCell(0, 0, () -> new ContextGridCell<>(new ExpressionCellValue(_editor), listSelector));
});
}
use of org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper in project kie-wb-common by kiegroup.
the class ExpressionContainerUIModelMapperTest method assertEditorType.
private void assertEditorType(final Class<?> clazz) {
final GridCell<?> gridCell = uiModel.getCell(0, 0);
assertThat(gridCell).isNotNull();
assertThat(gridCell).isInstanceOf(ContextGridCell.class);
final GridCellValue<?> gridCellValue = gridCell.getValue();
assertThat(gridCellValue).isNotNull();
assertThat(gridCellValue).isInstanceOf(ExpressionCellValue.class);
final ExpressionCellValue ecv = (ExpressionCellValue) gridCellValue;
final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> editor = ecv.getValue();
assertThat(editor.isPresent()).isTrue();
assertThat(editor.get()).isInstanceOf(clazz);
}
Aggregations