Search in sources :

Example 36 with BaseGridData

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData in project kie-wb-common by kiegroup.

the class InvocationUIModelMapperTest method setup.

@SuppressWarnings("unchecked")
public void setup(final boolean isOnlyVisualChangeAllowedSupplier) {
    this.uiModel = new BaseGridData();
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiNameColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    when(uiRowNumberColumn.getIndex()).thenReturn(0);
    when(uiNameColumn.getIndex()).thenReturn(1);
    when(uiExpressionEditorColumn.getIndex()).thenReturn(2);
    when(gridWidget.getModel()).thenReturn(uiModel);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
    when(literalExpressionEditor.getExpression()).thenReturn(() -> Optional.of(literalExpression));
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    final LiteralExpression invocationExpression = new LiteralExpression();
    invocationExpression.getText().setValue("invocation-expression");
    final LiteralExpression bindingExpression = new LiteralExpression();
    bindingExpression.getText().setValue("binding-expression");
    final Binding binding = new Binding();
    final InformationItem parameter = new InformationItem();
    parameter.setName(new Name("p0"));
    binding.setParameter(parameter);
    binding.setExpression(bindingExpression);
    this.invocation = new Invocation();
    this.invocation.setExpression(invocationExpression);
    this.invocation.getBinding().add(binding);
    this.mapper = new InvocationUIModelMapper(gridWidget, () -> uiModel, () -> Optional.of(invocation), () -> isOnlyVisualChangeAllowedSupplier, expressionEditorDefinitionsSupplier, listSelector, 0);
    this.cellValueSupplier = Optional::empty;
}
Also used : Binding(org.kie.workbench.common.dmn.api.definition.model.Binding) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) Invocation(org.kie.workbench.common.dmn.api.definition.model.Invocation) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 37 with BaseGridData

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData in project kie-wb-common by kiegroup.

the class InvocationGridTest method setup.

@Before
@SuppressWarnings("unchecked")
public void setup() {
    when(parent.getGridWidget()).thenReturn(parentGridWidget);
    when(parentGridWidget.getModel()).thenReturn(parentGridData);
    when(parentGridData.getColumns()).thenReturn(Collections.singletonList(parentGridColumn));
    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 InvocationEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, expressionEditorDefinitionsSupplier, headerEditor, readOnlyProvider);
    expression = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, expression);
    expression.ifPresent(invocation -> ((LiteralExpression) invocation.getExpression()).getText().setValue("invocation-expression"));
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add((ExpressionEditorDefinition) definition);
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    when(undefinedExpressionEditor.getParentInformation()).thenReturn(parent);
    when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
    when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));
    when(sessionManager.getCurrentSession()).thenReturn(session);
    when(session.getCanvasHandler()).thenReturn(canvasHandler);
    when(canvasHandler.getGraphExecutionContext()).thenReturn(graphContext);
    final Decision decision = new Decision();
    decision.setName(new Name("name"));
    hasName = Optional.of(decision);
    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, 100, 200));
    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(mock(UpdateElementPropertyCommand.class));
    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 : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Optional(java.util.Optional) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) Element(org.kie.workbench.common.stunner.core.graph.Element) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) UndefinedExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.undefined.UndefinedExpressionEditorDefinition) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) BaseBounds(org.uberfire.ext.wires.core.grids.client.model.impl.BaseBounds) Decision(org.kie.workbench.common.dmn.api.definition.model.Decision) UpdateElementPropertyCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand) HasName(org.kie.workbench.common.dmn.api.definition.HasName) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) Iterator(java.util.Iterator) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) BaseGridCellValue(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridCellValue) Before(org.junit.Before)

Example 38 with BaseGridData

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData in project kie-wb-common by kiegroup.

the class ExpressionContainerUIModelMapperTest method setup.

@SuppressWarnings("unchecked")
public void setup(final boolean isOnlyVisualChangeAllowed) {
    uiModel = new BaseGridData();
    uiModel.appendRow(new BaseGridRow());
    uiModel.appendColumn(uiExpressionColumn);
    when(uiExpressionColumn.getIndex()).thenReturn(0);
    when(uiExpressionColumn.getMinimumWidth()).thenReturn(MINIMUM_COLUMN_WIDTH);
    parent = new GridCellTuple(0, 0, expressionContainerGrid);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
    when(literalExpressionEditor.isCacheable()).thenReturn(true);
    when(literalExpressionEditor.getExpression()).thenReturn(() -> Optional.of(literalExpression));
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
    when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));
    expressionGridCache = spy(new ExpressionGridCacheImpl());
    mapper = new ExpressionContainerUIModelMapper(parent, () -> uiModel, () -> Optional.ofNullable(expression), () -> NODE_UUID, () -> hasExpression, () -> Optional.of(hasName), () -> isOnlyVisualChangeAllowed, expressionEditorDefinitionsSupplier, () -> expressionGridCache, listSelector);
}
Also used : ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) ExpressionGridCacheImpl(org.kie.workbench.common.dmn.client.widgets.grid.ExpressionGridCacheImpl) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)

Example 39 with BaseGridData

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData in project kie-wb-common by kiegroup.

the class BaseContextUIModelMapperTest method setup.

@SuppressWarnings("unchecked")
public void setup(final boolean isOnlyVisualChangeAllowedSupplier) {
    this.uiModel = new BaseGridData();
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendRow(new BaseGridRow());
    this.uiModel.appendColumn(uiRowNumberColumn);
    this.uiModel.appendColumn(uiNameColumn);
    this.uiModel.appendColumn(uiExpressionEditorColumn);
    when(uiRowNumberColumn.getIndex()).thenReturn(0);
    when(uiNameColumn.getIndex()).thenReturn(1);
    when(uiExpressionEditorColumn.getIndex()).thenReturn(2);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(literalExpression));
    when(literalExpressionEditor.getExpression()).thenReturn(() -> Optional.of(literalExpression));
    when(literalExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(literalExpressionEditor));
    when(undefinedExpressionEditorDefinition.getModelClass()).thenReturn(Optional.empty());
    when(undefinedExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(undefinedExpressionEditor));
    this.context = new Context();
    this.context.getContextEntry().add(new ContextEntry() {

        {
            setVariable(new InformationItem() {

                {
                    setName(new Name("ii1"));
                }
            });
        }
    });
    this.context.getContextEntry().add(new ContextEntry() {

        {
            setExpression(new LiteralExpression());
        }
    });
    this.mapper = getMapper(isOnlyVisualChangeAllowedSupplier);
    this.cellValueSupplier = Optional::empty;
}
Also used : Context(org.kie.workbench.common.dmn.api.definition.model.Context) ExpressionEditorDefinitions(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) BaseGridRow(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow) Optional(java.util.Optional) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) InformationItem(org.kie.workbench.common.dmn.api.definition.model.InformationItem) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) ContextEntry(org.kie.workbench.common.dmn.api.definition.model.ContextEntry) Name(org.kie.workbench.common.dmn.api.property.dmn.Name)

Example 40 with BaseGridData

use of org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData 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)

Aggregations

BaseGridData (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData)56 Before (org.junit.Before)41 BaseGridRow (org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridRow)24 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)23 Optional (java.util.Optional)20 HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)19 ExpressionEditorDefinitions (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions)18 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)13 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)10 HasName (org.kie.workbench.common.dmn.api.definition.HasName)7 InformationItem (org.kie.workbench.common.dmn.api.definition.model.InformationItem)7 Element (org.kie.workbench.common.stunner.core.graph.Element)7 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)7 Test (org.junit.Test)6 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)6 UpdateElementPropertyCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPropertyCommand)6 List (org.kie.workbench.common.dmn.api.definition.model.List)5 ExpressionCellValue (org.kie.workbench.common.dmn.client.editors.expressions.types.context.ExpressionCellValue)5 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)5 BaseBounds (org.uberfire.ext.wires.core.grids.client.model.impl.BaseBounds)5