use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue 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.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue 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.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.
the class RelationGridTest method setUp.
@Before
@SuppressWarnings("unchecked")
public void setUp() {
when(sessionManager.getCurrentSession()).thenReturn(session);
when(session.getGridPanel()).thenReturn(gridPanel);
when(session.getGridLayer()).thenReturn(gridLayer);
when(session.getCellEditorControls()).thenReturn(cellEditorControls);
tupleWithoutValue = new GridCellTuple(0, 1, gridWidget);
tupleWithValue = new GridCellValueTuple<>(0, 1, gridWidget, new BaseGridCellValue<>("value"));
definition = new RelationEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, headerEditors, readOnlyProvider);
final Decision decision = new Decision();
decision.setName(new Name("name"));
hasName = Optional.of(decision);
expression = definition.getModelClass();
definition.enrich(Optional.empty(), hasExpression, expression);
when(session.getCanvasHandler()).thenReturn(canvasHandler);
when(parentGridWidget.getModel()).thenReturn(parentGridData);
when(parentGridData.getColumns()).thenReturn(Collections.singletonList(parentGridColumn));
parent = spy(new GridCellTuple(0, 0, parentGridWidget));
when(canvasHandler.getDiagram()).thenReturn(diagram);
when(canvasHandler.getGraphExecutionContext()).thenReturn(graphContext);
when(diagram.getGraph()).thenReturn(graph);
when(graph.nodes()).thenReturn(Collections.singletonList(node));
when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
when(gridLayer.getDomElementContainer()).thenReturn(gridLayerDomElementContainer);
when(gridLayerDomElementContainer.iterator()).thenReturn(mock(Iterator.class));
when(gridLayer.getVisibleBounds()).thenReturn(new BaseBounds(0, 0, 200, 200));
when(gridLayer.getViewport()).thenReturn(viewport);
when(viewport.getTransform()).thenReturn(transform);
when(headerEditors.get()).thenReturn(headerEditor);
when(gridBodyCellEditContext.getRelativeLocation()).thenReturn(Optional.empty());
doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).format(Mockito.<String>any());
doAnswer((i) -> i.getArguments()[0].toString()).when(translationService).getTranslation(Mockito.<String>any());
}
use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.
the class RelationUIModelMapperTest method testToDMNModelLiteralExpressionsNullValue.
@Test
public void testToDMNModelLiteralExpressionsNullValue() {
cellValueSupplier = () -> Optional.of(new BaseGridCellValue<>(null));
for (int uiRowIndex = 0; uiRowIndex < uiModel.getRowCount(); uiRowIndex++) {
for (int uiColumnIndex = 1; uiColumnIndex < uiModel.getColumnCount(); uiColumnIndex++) {
mapper.toDMNModel(uiRowIndex, uiColumnIndex, cellValueSupplier);
final LiteralExpression le = (LiteralExpression) relation.getRow().get(uiRowIndex).getExpression().get(uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT).getExpression();
assertNull(le.getText().getValue());
}
}
}
use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue in project kie-wb-common by kiegroup.
the class RelationUIModelMapperTest method testToDMNModelLiteralExpressionsNonEmptyValue.
@Test
public void testToDMNModelLiteralExpressionsNonEmptyValue() {
for (int uiRowIndex = 0; uiRowIndex < uiModel.getRowCount(); uiRowIndex++) {
for (int uiColumnIndex = 1; uiColumnIndex < uiModel.getColumnCount(); uiColumnIndex++) {
final String value = "(" + uiColumnIndex + "," + uiRowIndex + ")";
cellValueSupplier = () -> Optional.of(new BaseGridCellValue<>(value));
mapper.toDMNModel(uiRowIndex, uiColumnIndex, cellValueSupplier);
final LiteralExpression le = (LiteralExpression) relation.getRow().get(uiRowIndex).getExpression().get(uiColumnIndex - RelationUIModelMapperHelper.ROW_INDEX_COLUMN_COUNT).getExpression();
assertEquals(value, le.getText().getValue());
}
}
}
Aggregations