Search in sources :

Example 46 with GridCellTuple

use of org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple in project kie-wb-common by kiegroup.

the class DecisionTableGridTest method testBodyTextAreaFactoryWhenNested.

@Test
public void testBodyTextAreaFactoryWhenNested() {
    setupGrid(makeHasNameForDecision(), 1);
    final GridCellTuple tupleWithoutValue = new GridCellTuple(0, 1, gridWidget);
    final GridCellValueTuple tupleWithValue = new GridCellValueTuple<>(0, 1, gridWidget, new BaseGridCellValue<>("value"));
    final TextAreaSingletonDOMElementFactory factory = grid.getBodyTextAreaFactory();
    assertThat(factory.getHasNoValueCommand().apply(tupleWithoutValue)).isInstanceOf(DeleteCellValueCommand.class);
    assertThat(factory.getHasValueCommand().apply(tupleWithValue)).isInstanceOf(SetCellValueCommand.class);
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) TextAreaSingletonDOMElementFactory(org.kie.workbench.common.dmn.client.widgets.grid.columns.factory.TextAreaSingletonDOMElementFactory) GridCellValueTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple) Test(org.junit.Test)

Example 47 with GridCellTuple

use of org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple in project kie-wb-common by kiegroup.

the class DecisionTableGridTest 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);
    this.definition = new DecisionTableEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, hitPolicyEditor, headerEditors, new DecisionTableEditorDefinitionEnricher(sessionManager, new DMNGraphUtils(sessionManager, dmnDiagramUtils, dmnDiagramsSession), itemDefinitionUtils), readOnlyProvider);
    expression = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, expression);
    when(session.getCanvasHandler()).thenReturn(canvasHandler);
    when(canvasHandler.getGraphExecutionContext()).thenReturn(graphCommandContext);
    when(parentGridWidget.getModel()).thenReturn(parentGridData);
    when(parentGridData.getColumns()).thenReturn(Collections.singletonList(parentGridColumn));
    parent = spy(new GridCellTuple(0, 0, parentGridWidget));
    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, 1000, 2000));
    when(gridLayer.getViewport()).thenReturn(viewport);
    when(viewport.getTransform()).thenReturn(transform);
    when(canvasHandler.getDiagram()).thenReturn(diagram);
    when(diagram.getGraph()).thenReturn(graph);
    when(graph.nodes()).thenReturn(Collections.singletonList(node));
    when(canvasHandler.getGraphIndex()).thenReturn(index);
    when(index.get(Mockito.<String>any())).thenReturn(element);
    when(element.getContent()).thenReturn(mock(Definition.class));
    when(definitionUtils.getNameIdentifier(any())).thenReturn("name");
    when(canvasCommandFactory.updatePropertyValue(any(Element.class), Mockito.<String>any(), any())).thenReturn(updateElementPropertyCommand);
    when(updateElementPropertyCommand.execute(canvasHandler)).thenReturn(CanvasCommandResultBuilder.SUCCESS);
    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());
}
Also used : DMNGraphUtils(org.kie.workbench.common.dmn.client.graph.DMNGraphUtils) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Element(org.kie.workbench.common.stunner.core.graph.Element) Iterator(java.util.Iterator) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) BaseBounds(org.uberfire.ext.wires.core.grids.client.model.impl.BaseBounds) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

Example 48 with GridCellTuple

use of org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple in project kie-wb-common by kiegroup.

the class DecisionTableGridTest method testBodyTextAreaFactoryWhenNotNested.

@Test
public void testBodyTextAreaFactoryWhenNotNested() {
    setupGrid(makeHasNameForDecision(), 0);
    final GridCellTuple tupleWithoutValue = new GridCellTuple(0, 1, gridWidget);
    final GridCellValueTuple tupleWithValue = new GridCellValueTuple<>(0, 1, gridWidget, new BaseGridCellValue<>("value"));
    final TextAreaSingletonDOMElementFactory factory = grid.getBodyTextAreaFactory();
    assertThat(factory.getHasNoValueCommand().apply(tupleWithoutValue)).isInstanceOf(DeleteCellValueCommand.class);
    assertThat(factory.getHasValueCommand().apply(tupleWithValue)).isInstanceOf(SetCellValueCommand.class);
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) TextAreaSingletonDOMElementFactory(org.kie.workbench.common.dmn.client.widgets.grid.columns.factory.TextAreaSingletonDOMElementFactory) GridCellValueTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple) Test(org.junit.Test)

Example 49 with GridCellTuple

use of org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple in project kie-wb-common by kiegroup.

the class InvocationUIModelMapperTest method assertFromDMNModelBindingExpression.

private void assertFromDMNModelBindingExpression(final boolean isOnlyVisualChangeAllowed) {
    mapper.fromDMNModel(0, 2);
    assertNotNull(uiModel.getCell(0, 2));
    assertTrue(uiModel.getCell(0, 2).getValue() instanceof ExpressionCellValue);
    final ExpressionCellValue dcv = (ExpressionCellValue) uiModel.getCell(0, 2).getValue();
    assertEquals(literalExpressionEditor, dcv.getValue().get());
    verify(literalExpressionEditorDefinition).getEditor(parentCaptor.capture(), eq(Optional.empty()), eq(invocation.getBinding().get(0)), eq(Optional.of(invocation.getBinding().get(0).getParameter())), eq(isOnlyVisualChangeAllowed), eq(1));
    final GridCellTuple parent = parentCaptor.getValue();
    assertEquals(0, parent.getRowIndex());
    assertEquals(2, parent.getColumnIndex());
    assertEquals(gridWidget, parent.getGridWidget());
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Example 50 with GridCellTuple

use of org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple in project kie-wb-common by kiegroup.

the class FunctionUIModelMapperTest method assertFromDMNModelEditor.

@SuppressWarnings("unchecked")
private void assertFromDMNModelEditor(final BaseExpressionGrid editor, final ExpressionEditorDefinition definition, final boolean isOnlyVisualChangeAllowedSupplier) {
    assertTrue(uiModel.getCell(0, 0).getValue() instanceof ExpressionCellValue);
    final ExpressionCellValue dcv = (ExpressionCellValue) uiModel.getCell(0, 0).getValue();
    assertEquals(editor, dcv.getValue().get());
    verify(definition).getEditor(parentCaptor.capture(), eq(Optional.empty()), eq(function), eq(Optional.empty()), eq(isOnlyVisualChangeAllowedSupplier), eq(1));
    final GridCellTuple parent = parentCaptor.getValue();
    assertEquals(0, parent.getRowIndex());
    assertEquals(0, parent.getColumnIndex());
    assertEquals(gridWidget, parent.getGridWidget());
}
Also used : GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) ExpressionCellValue(org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)

Aggregations

GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)57 Test (org.junit.Test)22 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)13 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)13 BaseGridCellValue (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue)13 Before (org.junit.Before)12 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)11 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)11 GridCellValueTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellValueTuple)11 Optional (java.util.Optional)10 HasName (org.kie.workbench.common.dmn.api.definition.HasName)9 BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)9 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)8 DMNGridData (org.kie.workbench.common.dmn.client.widgets.grid.model.DMNGridData)8 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)7 ExpressionEditorDefinition (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition)6 TextBoxSingletonDOMElementFactory (org.kie.workbench.common.dmn.client.widgets.grid.columns.factory.TextBoxSingletonDOMElementFactory)6 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)6 ExpressionEditorDefinitions (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions)5 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)5