Search in sources :

Example 56 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class DMNDocumentationDRDsFactory method setExpressionContainerGrid.

void setExpressionContainerGrid(final Diagram diagram, final String uuid) {
    final Node<View, Edge> node = getNode(diagram, uuid);
    final Object definition = DefinitionUtils.getElementDefinition(node);
    final HasExpression hasExpression = expressionHelper.getHasExpression(node);
    final Optional<HasName> hasName = Optional.of((HasName) definition);
    final ExpressionContainerGrid grid = getExpressionContainerGrid();
    grid.setExpression(node.getUUID(), hasExpression, hasName, false);
    clearSelections(grid);
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasName(org.kie.workbench.common.dmn.api.definition.HasName) ExpressionContainerGrid(org.kie.workbench.common.dmn.client.editors.expressions.ExpressionContainerGrid) View(org.kie.workbench.common.stunner.core.graph.content.view.View) ExpressionEditorView(org.kie.workbench.common.dmn.client.editors.expressions.ExpressionEditorView) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 57 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class ListPropertyConverter method wbFromDMN.

public static List wbFromDMN(final JSITList dmn, final BiConsumer<String, HasComponentWidths> hasComponentWidthsConsumer) {
    final Id id = IdPropertyConverter.wbFromDMN(dmn.getId());
    final Description description = DescriptionPropertyConverter.wbFromDMN(dmn.getDescription());
    final QName typeRef = QNamePropertyConverter.wbFromDMN(dmn.getTypeRef());
    final java.util.List<HasExpression> expression = new ArrayList<>();
    final List result = new List(id, description, typeRef, expression);
    final java.util.List<JSITExpression> jsiExpressions = dmn.getExpression();
    for (int i = 0; i < jsiExpressions.size(); i++) {
        final JSITExpression jsitExpression = Js.uncheckedCast(jsiExpressions.get(i));
        final Expression eConverted = ExpressionPropertyConverter.wbFromDMN(jsitExpression, Js.uncheckedCast(dmn), hasComponentWidthsConsumer);
        final HasExpression hasExpression = HasExpression.wrap(result, eConverted);
        expression.add(hasExpression);
    }
    for (HasExpression hasExpression : expression) {
        final Expression e = hasExpression.getExpression();
        if (Objects.nonNull(e)) {
            e.setParent(result);
        }
    }
    return result;
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Description(org.kie.workbench.common.dmn.api.property.dmn.Description) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) QName(org.kie.workbench.common.dmn.api.property.dmn.QName) ArrayList(java.util.ArrayList) List(org.kie.workbench.common.dmn.api.definition.model.List) ArrayList(java.util.ArrayList) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) Id(org.kie.workbench.common.dmn.api.property.dmn.Id) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)

Example 58 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class ListPropertyConverter method dmnFromWB.

public static JSITList dmnFromWB(final List wb, final Consumer<JSITComponentWidths> componentWidthsConsumer) {
    final JSITList result = new JSITList();
    result.setId(wb.getId().getValue());
    final Optional<String> description = Optional.ofNullable(DescriptionPropertyConverter.dmnFromWB(wb.getDescription()));
    description.ifPresent(result::setDescription);
    QNamePropertyConverter.setDMNfromWB(wb.getTypeRef(), result::setTypeRef);
    for (HasExpression hasExpression : wb.getExpression()) {
        final Expression e = hasExpression.getExpression();
        final JSITExpression eConverted = ExpressionPropertyConverter.dmnFromWB(e, componentWidthsConsumer);
        result.addExpression(eConverted);
    }
    return result;
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) JSITList(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITList) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) JSITExpression(org.kie.workbench.common.dmn.webapp.kogito.marshaller.js.model.dmn12.JSITExpression)

Example 59 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class DecisionNavigatorNestedItemFactoryTest method testMakeEditExpressionEvent.

@Test
public void testMakeEditExpressionEvent() {
    final ClientSession currentSession = mock(ClientSession.class);
    final HasName hasName = mock(HasName.class);
    final HasExpression hasExpression = mock(HasExpression.class);
    final View view = mock(View.class);
    final String uuid = "uuid";
    when(node.getUUID()).thenReturn(uuid);
    when(sessionManager.getCurrentSession()).thenReturn(currentSession);
    when(node.getContent()).thenReturn(view);
    when(view.getDefinition()).thenReturn(hasName);
    when(boxedExpressionHelper.getHasExpression(node)).thenReturn(hasExpression);
    final EditExpressionEvent expressionEvent = factory.makeEditExpressionEvent(node);
    assertEquals(uuid, expressionEvent.getNodeUUID());
    assertEquals(currentSession, expressionEvent.getSession());
    assertEquals(Optional.of(hasName), expressionEvent.getHasName());
    assertEquals(hasExpression, expressionEvent.getHasExpression());
    assertFalse(expressionEvent.isOnlyVisualChangeAllowed());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasName(org.kie.workbench.common.dmn.api.definition.HasName) ClientSession(org.kie.workbench.common.stunner.core.client.session.ClientSession) EditExpressionEvent(org.kie.workbench.common.dmn.client.events.EditExpressionEvent) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

Example 60 with HasExpression

use of org.kie.workbench.common.dmn.api.definition.HasExpression in project kie-wb-common by kiegroup.

the class FunctionGridTest 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);
    definition = new FunctionEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, expressionEditorDefinitionsSupplier, supplementaryEditorDefinitionsSupplier, headerEditor, parametersEditor, kindEditor, readOnlyProvider);
    literalExpressionEditorDefinition = spy(new LiteralExpressionEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, headerEditor, readOnlyProvider));
    expression = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, expression);
    expression.get().getFormalParameter().add(parameter);
    parameter.getName().setValue(PARAMETER_NAME);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add((ExpressionEditorDefinition) definition);
    expressionEditorDefinitions.add((ExpressionEditorDefinition) literalExpressionEditorDefinition);
    expressionEditorDefinitions.add(supplementaryExpressionEditorDefinition);
    final Decision decision = new Decision();
    decision.setName(new Name("name"));
    hasName = Optional.of(decision);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(supplementaryEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    // Setup LiteralExpression definition and editor
    doReturn(Optional.of(literalExpressionEditor)).when(literalExpressionEditorDefinition).getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt());
    when(literalExpressionEditor.getGridPanel()).thenReturn(gridPanel);
    when(literalExpressionEditor.getLayer()).thenReturn(gridLayer);
    when(literalExpressionEditor.getModel()).thenReturn(new BaseGridData(false));
    doCallRealMethod().when(literalExpressionEditor).resize(any(Function.class));
    doCallRealMethod().when(literalExpressionEditor).doResize(any(PrioritizedCommand.class), any(Function.class));
    doCallRealMethod().when(literalExpressionEditor).selectFirstCell();
    when(literalExpressionEditor.getParentInformation()).thenReturn(parent);
    // Setup Supplementary expression definition and editor
    when(supplementaryExpressionEditorDefinition.getModelClass()).thenReturn(Optional.of(supplementaryExpression));
    when(supplementaryExpressionEditorDefinition.getEditor(any(GridCellTuple.class), any(Optional.class), any(HasExpression.class), any(Optional.class), anyBoolean(), anyInt())).thenReturn(Optional.of(supplementaryExpressionEditor));
    when(supplementaryExpressionEditor.getGridPanel()).thenReturn(gridPanel);
    when(supplementaryExpressionEditor.getLayer()).thenReturn(gridLayer);
    when(supplementaryExpressionEditor.getModel()).thenReturn(new BaseGridData(false));
    doCallRealMethod().when(supplementaryExpressionEditor).resize(any(Function.class));
    doCallRealMethod().when(supplementaryExpressionEditor).doResize(any(PrioritizedCommand.class), any(Function.class));
    doCallRealMethod().when(supplementaryExpressionEditor).selectFirstCell();
    when(supplementaryExpressionEditor.getParentInformation()).thenReturn(parent);
    when(session.getCanvasHandler()).thenReturn(canvasHandler);
    when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
    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));
    when(canvasHandler.getGraphExecutionContext()).thenReturn(graphCommandExecutionContext);
    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) Element(org.kie.workbench.common.stunner.core.graph.Element) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) ExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) LiteralExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.literal.LiteralExpressionEditorDefinition) LiteralExpressionEditorDefinition(org.kie.workbench.common.dmn.client.editors.expressions.types.literal.LiteralExpressionEditorDefinition) 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) Function(java.util.function.Function) GridCellTuple(org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple) PrioritizedCommand(org.uberfire.ext.wires.core.grids.client.widget.layer.impl.GridLayerRedrawManager.PrioritizedCommand) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) Before(org.junit.Before)

Aggregations

HasExpression (org.kie.workbench.common.dmn.api.definition.HasExpression)78 Test (org.junit.Test)41 Expression (org.kie.workbench.common.dmn.api.definition.model.Expression)30 LiteralExpression (org.kie.workbench.common.dmn.api.definition.model.LiteralExpression)24 HasName (org.kie.workbench.common.dmn.api.definition.HasName)18 BaseExpressionGrid (org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid)15 BaseUIModelMapper (org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper)15 GridCellTuple (org.kie.workbench.common.dmn.client.widgets.grid.model.GridCellTuple)15 GridData (org.uberfire.ext.wires.core.grids.client.model.GridData)15 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)13 Optional (java.util.Optional)12 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)12 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)10 GridWidget (org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget)10 ExpressionEditorDefinition (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinition)8 ExpressionEditorDefinitions (org.kie.workbench.common.dmn.client.editors.expressions.types.ExpressionEditorDefinitions)8 ArrayList (java.util.ArrayList)7 EditExpressionEvent (org.kie.workbench.common.dmn.client.events.EditExpressionEvent)6 Before (org.junit.Before)5