use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class ListGrid method getItems.
@Override
public java.util.List<ListSelectorItem> getItems(final int uiRowIndex, final int uiColumnIndex) {
final java.util.List<ListSelectorItem> items = new ArrayList<>();
final boolean isMultiRow = SelectionUtils.isMultiRow(model);
final boolean isMultiSelect = SelectionUtils.isMultiSelect(model);
items.add(ListSelectorHeaderItem.build(translationService.format(DMNEditorConstants.ListEditor_HeaderRows)));
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ListEditor_InsertRowAbove), !isMultiRow, () -> {
cellEditorControls.hide();
getExpression().get().ifPresent(e -> addRow(uiRowIndex));
}));
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ListEditor_InsertRowBelow), !isMultiRow, () -> {
cellEditorControls.hide();
getExpression().get().ifPresent(e -> addRow(uiRowIndex + 1));
}));
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ListEditor_DeleteRow), !isMultiRow && model.getRowCount() > 1, () -> {
cellEditorControls.hide();
getExpression().get().ifPresent(e -> deleteRow(uiRowIndex));
}));
// If not ExpressionEditor column don't add extra items
if (ListUIModelMapperHelper.getSection(uiColumnIndex) != ListUIModelMapperHelper.ListSection.EXPRESSION) {
return items;
}
// If cell editor is UndefinedExpressionGrid don't add extra items
final GridCell<?> cell = model.getCell(uiRowIndex, uiColumnIndex);
final ExpressionCellValue ecv = (ExpressionCellValue) cell.getValue();
if (!ecv.getValue().isPresent()) {
return items;
}
final BaseExpressionGrid grid = ecv.getValue().get();
if (grid instanceof UndefinedExpressionGrid) {
return items;
}
if (items.size() > 0) {
items.add(new ListSelectorDividerItem());
}
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ExpressionEditor_Clear), !isMultiSelect, () -> {
cellEditorControls.hide();
clearExpressionType(uiRowIndex);
}));
return items;
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class ListUIModelMapper method fromDMNModel.
@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
dmnModel.get().ifPresent(list -> {
final ListUIModelMapperHelper.ListSection section = ListUIModelMapperHelper.getSection(columnIndex);
switch(section) {
case ROW_INDEX:
uiModel.get().setCell(rowIndex, columnIndex, () -> new ContextGridCell<>(new BaseGridCellValue<>(rowIndex + 1), listSelector));
uiModel.get().getCell(rowIndex, columnIndex).setSelectionStrategy(RowSelectionStrategy.INSTANCE);
break;
case EXPRESSION:
final HasExpression hasExpression = list.getExpression().get(rowIndex);
final Optional<Expression> expression = Optional.ofNullable(hasExpression.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(), hasExpression, Optional.empty(), isOnlyVisualChangeAllowed, nesting + 1);
uiModel.get().setCell(rowIndex, columnIndex, () -> new ContextGridCell<>(new ExpressionCellValue(editor), listSelector));
});
}
});
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class InvocationGrid method getItems.
@Override
@SuppressWarnings("unused")
public List<ListSelectorItem> getItems(final int uiRowIndex, final int uiColumnIndex) {
final List<ListSelectorItem> items = new ArrayList<>();
final boolean isMultiRow = SelectionUtils.isMultiRow(model);
final boolean isMultiSelect = SelectionUtils.isMultiSelect(model);
items.add(ListSelectorHeaderItem.build(translationService.format(DMNEditorConstants.InvocationEditor_Header)));
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.InvocationEditor_InsertParameterAbove), !isMultiRow, () -> {
cellEditorControls.hide();
getExpression().get().ifPresent(e -> addParameterBinding(uiRowIndex));
}));
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.InvocationEditor_InsertParameterBelow), !isMultiRow, () -> {
cellEditorControls.hide();
getExpression().get().ifPresent(e -> addParameterBinding(uiRowIndex + 1));
}));
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.InvocationEditor_DeleteParameter), !isMultiRow && model.getRowCount() > 1, () -> {
cellEditorControls.hide();
deleteParameterBinding(uiRowIndex);
}));
// If not ExpressionEditor column don't add extra items
if (uiColumnIndex != InvocationUIModelMapper.BINDING_EXPRESSION_COLUMN_INDEX) {
return items;
}
// If cell editor is UndefinedExpressionGrid don't add extra items
final GridCell<?> cell = model.getCell(uiRowIndex, uiColumnIndex);
final ExpressionCellValue ecv = (ExpressionCellValue) cell.getValue();
if (!ecv.getValue().isPresent()) {
return items;
}
final BaseExpressionGrid grid = ecv.getValue().get();
if (grid instanceof UndefinedExpressionGrid) {
return items;
}
items.add(new ListSelectorDividerItem());
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ExpressionEditor_Clear), !isMultiSelect, () -> {
cellEditorControls.hide();
clearExpressionType(uiRowIndex);
}));
return items;
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class InvocationUIModelMapper method toDMNModel.
@Override
@SuppressWarnings("unchecked")
public void toDMNModel(final int rowIndex, final int columnIndex, final Supplier<Optional<GridCellValue<?>>> cell) {
dmnModel.get().ifPresent(invocation -> {
switch(columnIndex) {
case ROW_NUMBER_COLUMN_INDEX:
break;
case BINDING_PARAMETER_COLUMN_INDEX:
invocation.getBinding().get(rowIndex).getParameter().getName().setValue(cell.get().orElse(new BaseGridCellValue<>("")).getValue().toString());
break;
case BINDING_EXPRESSION_COLUMN_INDEX:
cell.get().ifPresent(v -> {
final ExpressionCellValue ecv = (ExpressionCellValue) v;
ecv.getValue().ifPresent(beg -> {
beg.getExpression().get().ifPresent(e -> invocation.getBinding().get(rowIndex).setExpression((Expression) e));
});
});
}
});
}
use of org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue in project kie-wb-common by kiegroup.
the class CommandUtilsTest method testUpdateParentInformation_WithMultipleColumns.
@Test
@SuppressWarnings("unchecked")
public void testUpdateParentInformation_WithMultipleColumns() {
setupUiModel(Pair.newPair(new ExpressionEditorColumn(gridLayer, new BaseHeaderMetaData("column"), ExpressionEditorColumn.DEFAULT_WIDTH, gridWidget), (rowIndex) -> {
final BaseExpressionGrid grid = mock(BaseExpressionGrid.class);
final GridCellTuple gct = new GridCellTuple(rowIndex, 0, mock(GridWidget.class));
when(grid.getParentInformation()).thenReturn(gct);
return new ExpressionCellValue(Optional.of(grid));
}), Pair.newPair(new RowNumberColumn(), (rowIndex) -> new BaseGridCellValue<>(rowIndex + 1)));
assertParentInformationValues(0);
gridData.moveColumnTo(0, gridData.getColumns().get(1));
CommandUtils.updateParentInformation(gridData);
assertParentInformationValues(1);
}
Aggregations