Search in sources :

Example 21 with HasExpression

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

the class PropertiesPanelNotifier method notifyExpressions.

void notifyExpressions(final Node node, final Object definition) {
    if (definition instanceof HasExpression) {
        final HasExpression hasExpression = asHasExpression(definition);
        final List<HasTypeRef> hasTypeRefs = getNotNullHasTypeRefs(hasExpression.getExpression());
        for (final HasTypeRef hasTypeRef : hasTypeRefs) {
            notifyOutdatedElement(node, hasTypeRef);
        }
    }
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) HasTypeRef(org.kie.workbench.common.dmn.api.definition.HasTypeRef)

Example 22 with HasExpression

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

the class ListGridTest 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 ListEditorDefinition(definitionUtils, sessionManager, sessionCommandManager, canvasCommandFactory, editorSelectedEvent, refreshFormPropertiesEvent, domainObjectSelectionEvent, listSelector, translationService, expressionEditorDefinitionsSupplier, headerEditor, readOnlyProvider);
    final Decision decision = new Decision();
    decision.setName(new Name(NAME));
    hasName = Optional.of(decision);
    expression = definition.getModelClass();
    definition.enrich(Optional.empty(), hasExpression, expression);
    final ExpressionEditorDefinitions expressionEditorDefinitions = new ExpressionEditorDefinitions();
    expressionEditorDefinitions.add((ExpressionEditorDefinition) definition);
    expressionEditorDefinitions.add(literalExpressionEditorDefinition);
    expressionEditorDefinitions.add(undefinedExpressionEditorDefinition);
    when(expressionEditorDefinitionsSupplier.get()).thenReturn(expressionEditorDefinitions);
    when(literalExpressionEditor.getParentInformation()).thenReturn(parent);
    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(session.getCanvasHandler()).thenReturn(canvasHandler);
    when(canvasHandler.getGraphExecutionContext()).thenReturn(graphCommandExecutionContext);
    when(gridWidget.getModel()).thenReturn(new BaseGridData(false));
    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 : 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) Optional(java.util.Optional) 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) BaseGridData(org.uberfire.ext.wires.core.grids.client.model.impl.BaseGridData) 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) Name(org.kie.workbench.common.dmn.api.property.dmn.Name) Before(org.junit.Before)

Example 23 with HasExpression

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

the class LiteralExpressionEditorDefinitionTest method testEditor.

@Test
public void testEditor() {
    when(hasExpression.getExpression()).thenReturn(definition.getModelClass().get());
    final Optional<BaseExpressionGrid<? extends Expression, ? extends GridData, ? extends BaseUIModelMapper>> oEditor = definition.getEditor(parent, Optional.empty(), hasExpression, hasName, false, 0);
    assertThat(oEditor).isPresent();
    final GridWidget editor = oEditor.get();
    assertThat(editor).isInstanceOf(LiteralExpressionGrid.class);
}
Also used : GridWidget(org.uberfire.ext.wires.core.grids.client.widget.grid.GridWidget) BaseExpressionGrid(org.kie.workbench.common.dmn.client.widgets.grid.BaseExpressionGrid) LiteralExpression(org.kie.workbench.common.dmn.api.definition.model.LiteralExpression) HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) Expression(org.kie.workbench.common.dmn.api.definition.model.Expression) BaseUIModelMapper(org.kie.workbench.common.dmn.client.widgets.grid.model.BaseUIModelMapper) GridData(org.uberfire.ext.wires.core.grids.client.model.GridData) Test(org.junit.Test)

Example 24 with HasExpression

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

the class DecisionNavigatorNestedItemFactoryTest method testMakeEditExpressionEventWhenIsReadOnly.

@Test
public void testMakeEditExpressionEventWhenIsReadOnly() {
    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(readOnlyProvider.isReadOnlyDiagram()).thenReturn(true);
    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());
    assertTrue(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 25 with HasExpression

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

the class BoxedExpressionHelperTest method testGetOptionalHasExpressionWhenNodeIsBusinessKnowledgeModel.

@Test
public void testGetOptionalHasExpressionWhenNodeIsBusinessKnowledgeModel() {
    final View content = mock(View.class);
    final BusinessKnowledgeModel businessKnowledgeModel = new BusinessKnowledgeModel();
    final FunctionDefinition encapsulatedLogic = mock(FunctionDefinition.class);
    businessKnowledgeModel.setEncapsulatedLogic(encapsulatedLogic);
    when(node.getContent()).thenReturn(content);
    when(content.getDefinition()).thenReturn(businessKnowledgeModel);
    final Optional<HasExpression> actualHasExpression = helper.getOptionalHasExpression(node);
    assertTrue(actualHasExpression.isPresent());
    assertEquals(businessKnowledgeModel, actualHasExpression.get().asDMNModelInstrumentedBase());
    assertEquals(encapsulatedLogic, actualHasExpression.get().getExpression());
}
Also used : HasExpression(org.kie.workbench.common.dmn.api.definition.HasExpression) BusinessKnowledgeModel(org.kie.workbench.common.dmn.api.definition.model.BusinessKnowledgeModel) FunctionDefinition(org.kie.workbench.common.dmn.api.definition.model.FunctionDefinition) View(org.kie.workbench.common.stunner.core.graph.content.view.View) Test(org.junit.Test)

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