use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.
the class ExpressionContainerUIModelMapper method fromDMNModel.
@Override
public void fromDMNModel(final int rowIndex, final int columnIndex) {
final GridData uiModel = this.uiModel.get();
final Optional<Expression> expression = dmnModel.get();
final Optional<HasName> hasName = this.hasName.get();
final HasExpression hasExpression = this.hasExpression.get();
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitions.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(definition -> {
final Optional<BaseExpressionGrid> oEditor = definition.getEditor(parent, Optional.of(nodeUUID.get()), hasExpression, expression, hasName, 0);
uiModel.setCell(0, 0, () -> new ContextGridCell<>(new ExpressionCellValue(oEditor), listSelector));
final GridColumn<?> uiColumn = uiModel.getColumns().get(columnIndex);
uiColumn.setWidth(uiColumn.getMinimumWidth());
});
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.
the class ContextGrid method getItems.
@Override
@SuppressWarnings("unused")
public List<ListSelectorItem> getItems(final int uiRowIndex, final int uiColumnIndex) {
final List<ListSelectorItem> items = new ArrayList<>();
if (uiRowIndex == model.getRowCount() - 1) {
return items;
}
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ContextEditor_InsertContextEntryAbove), true, () -> {
cellEditorControls.hide();
expression.ifPresent(e -> addContextEntry(uiRowIndex));
}));
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ContextEditor_InsertContextEntryBelow), true, () -> {
cellEditorControls.hide();
expression.ifPresent(e -> addContextEntry(uiRowIndex + 1));
}));
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ContextEditor_DeleteContextEntry), model.getRowCount() > 2 && uiRowIndex < model.getRowCount() - 1, () -> {
cellEditorControls.hide();
deleteContextEntry(uiRowIndex);
}));
// If not ExpressionEditor column don't add extra items
if (ContextUIModelMapperHelper.getSection(uiColumnIndex) != ContextUIModelMapperHelper.ContextSection.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;
}
items.add(new ListSelectorDividerItem());
items.add(ListSelectorTextItem.build(translationService.format(DMNEditorConstants.ExpressionEditor_Clear), true, () -> {
cellEditorControls.hide();
clearExpressionType(uiRowIndex);
}));
return items;
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid 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:
if (!isLastRow) {
final InformationItem variable = context.getContextEntry().get(rowIndex).getVariable();
uiModel.get().setCell(rowIndex, columnIndex, () -> new InformationItemNameCell(() -> variable, listSelector));
} else {
uiModel.get().setCell(rowIndex, columnIndex, () -> new DMNGridCell<>(new BaseGridCellValue<>(DEFAULT_ROW_CAPTION)));
}
break;
case EXPRESSION:
final ContextEntry ce = context.getContextEntry().get(rowIndex);
final Optional<Expression> expression = Optional.ofNullable(ce.getExpression());
final Optional<ExpressionEditorDefinition<Expression>> expressionEditorDefinition = expressionEditorDefinitionsSupplier.get().getExpressionEditorDefinition(expression);
expressionEditorDefinition.ifPresent(ed -> {
final Optional<BaseExpressionGrid> editor = ed.getEditor(new GridCellTuple(rowIndex, columnIndex, gridWidget), Optional.empty(), ce, expression, Optional.ofNullable(ce.getVariable()), nesting + 1);
if (!isLastRow) {
uiModel.get().setCell(rowIndex, columnIndex, () -> new ContextGridCell<>(new ExpressionCellValue(editor), listSelector));
} else {
uiModel.get().setCell(rowIndex, columnIndex, () -> new DMNGridCell<>(new ExpressionCellValue(editor)));
}
});
}
});
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.
the class ContextGridTest method testOnItemSelectedExpressionColumnDefinedExpressionType.
@Test
public void testOnItemSelectedExpressionColumnDefinedExpressionType() {
setupGrid(0);
// Set an editor for expression at (0, 2)
final BaseExpressionGrid editor = mock(BaseExpressionGrid.class);
grid.getModel().setCellValue(0, 2, new ExpressionCellValue(Optional.of(editor)));
final List<HasListSelectorControl.ListSelectorItem> items = grid.getItems(0, 2);
assertThat(items.size()).isEqualTo(5);
assertDefaultListItems(items.subList(0, 3));
assertThat(items.get(DIVIDER)).isInstanceOf(HasListSelectorControl.ListSelectorDividerItem.class);
assertListSelectorItem(items.get(CLEAR_EXPRESSION_TYPE), DMNEditorConstants.ExpressionEditor_Clear);
((HasListSelectorControl.ListSelectorTextItem) items.get(CLEAR_EXPRESSION_TYPE)).getCommand().execute();
verify(cellEditorControls).hide();
verify(sessionCommandManager).execute(eq(canvasHandler), any(ClearExpressionTypeCommand.class));
}
use of org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid in project kie-wb-common by kiegroup.
the class ExpressionEditorColumnTest method mockEditor.
@SuppressWarnings("unchecked")
private BaseExpressionGrid mockEditor(final double padding, final double... widthOfCells) {
final GridColumn.HeaderMetaData headerMetaData = mock(GridColumn.HeaderMetaData.class);
final GridColumnRenderer gridColumnRenderer = mock(GridColumnRenderer.class);
final BaseExpressionGrid gridWidget = mock(BaseExpressionGrid.class);
final GridCellTuple parent = new GridCellTuple(0, 0, null);
final HasExpression hasExpression = mock(HasExpression.class);
final Optional<LiteralExpression> expression = Optional.of(mock(LiteralExpression.class));
final Optional<HasName> hasName = Optional.of(mock(HasName.class));
return new BaseExpressionGrid(parent, Optional.empty(), hasExpression, expression, hasName, gridPanel, gridLayer, new GridDataCache.CacheResult(new DMNGridData(), false), renderer, definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, cellEditorControls, listSelector, translationService, 0) {
@Override
protected BaseUIModelMapper makeUiModelMapper() {
return null;
}
@Override
protected void initialiseUiColumns() {
for (double width : widthOfCells) {
model.appendColumn(new DMNGridColumn<GridWidget, Object>(headerMetaData, gridColumnRenderer, gridWidget) {
{
setMinimumWidth(width);
setWidth(width);
}
});
}
}
@Override
protected void initialiseUiModel() {
// Nothing for this test
}
@Override
protected boolean isHeaderHidden() {
return false;
}
@Override
public double getPadding() {
return padding;
}
};
}
Aggregations