Search in sources :

Example 71 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class DMNSetConnectionSourceNodeCommandTest method createNode.

private Node createNode(final String diagramId) {
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final HasContentDefinitionId hasContentDefinitionId = mock(HasContentDefinitionId.class);
    when(node.getContent()).thenReturn(definition);
    when(hasContentDefinitionId.getDiagramId()).thenReturn(diagramId);
    when(definition.getDefinition()).thenReturn(hasContentDefinitionId);
    return node;
}
Also used : HasContentDefinitionId(org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition)

Example 72 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class DMNSetConnectionTargetNodeCommandTest method createNode.

private Node createNode(final String diagramId) {
    final Node node = mock(Node.class);
    final Definition definition = mock(Definition.class);
    final HasContentDefinitionId hasContentDefinitionId = mock(HasContentDefinitionId.class);
    when(node.getContent()).thenReturn(definition);
    when(hasContentDefinitionId.getDiagramId()).thenReturn(diagramId);
    when(definition.getDefinition()).thenReturn(hasContentDefinitionId);
    return node;
}
Also used : HasContentDefinitionId(org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition)

Example 73 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class MorphActionsToolboxFactory method getActions.

@Override
@SuppressWarnings("unchecked")
public Collection<ToolboxAction<AbstractCanvasHandler>> getActions(final AbstractCanvasHandler canvasHandler, final Element<?> e) {
    final Set<ToolboxAction<AbstractCanvasHandler>> actions = new LinkedHashSet<>();
    if (null != e.asNode()) {
        final Element<? extends Definition<?>> element = (Element<? extends Definition<?>>) e;
        final Object definition = element.getContent().getDefinition();
        if (definitionUtils.hasMorphTargets(definition)) {
            final String id = getDefinitionManager().adapters().forDefinition().getId(definition).value();
            final MorphAdapter<Object> morphAdapter = getDefinitionManager().adapters().registry().getMorphAdapter(definition.getClass());
            final Iterable<MorphDefinition> morphDefinitions = morphAdapter.getMorphDefinitions(definition);
            if (null != morphDefinitions && morphDefinitions.iterator().hasNext()) {
                final Metadata metadata = canvasHandler.getDiagram().getMetadata();
                final Predicate<String> definitionsAllowedFilter = profileManager.isDefinitionIdAllowed(metadata);
                final Map<String, MorphDefinition> definitionMap = new LinkedHashMap<>();
                for (final MorphDefinition morphDefinition : morphDefinitions) {
                    final Iterable<String> morphTargets = morphAdapter.getTargets(definition, morphDefinition);
                    if (null != morphTargets && morphTargets.iterator().hasNext()) {
                        for (final String morphTarget : morphTargets) {
                            if (!id.equals(morphTarget) && definitionsAllowedFilter.test(morphTarget)) {
                                definitionMap.put(morphTarget, morphDefinition);
                            }
                        }
                    }
                }
                // Create a morph toolbox action for each target morph candidate.
                definitionMap.forEach((targetMorphId, morphDefinition) -> actions.add(morphNodeActions.get().setMorphDefinition(morphDefinition).setTargetDefinitionId(targetMorphId)));
            }
        }
    }
    return actions;
}
Also used : LinkedHashSet(java.util.LinkedHashSet) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) Element(org.kie.workbench.common.stunner.core.graph.Element) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition) MorphDefinition(org.kie.workbench.common.stunner.core.definition.morph.MorphDefinition) Metadata(org.kie.workbench.common.stunner.core.diagram.Metadata) LinkedHashMap(java.util.LinkedHashMap)

Example 74 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition in project kie-wb-common by kiegroup.

the class NodeDefinitionHelperTest method createNode.

private Node createNode(final String contentDefinitionId, final String diagramId) {
    final Node node = mock(Node.class);
    final Definition content = mock(Definition.class);
    final HasContentDefinitionId hasContentDefinitionId = mock(HasContentDefinitionId.class);
    when(hasContentDefinitionId.getContentDefinitionId()).thenReturn(contentDefinitionId);
    when(hasContentDefinitionId.getDiagramId()).thenReturn(diagramId);
    when(node.getContent()).thenReturn(content);
    when(content.getDefinition()).thenReturn(hasContentDefinitionId);
    return node;
}
Also used : HasContentDefinitionId(org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId) Node(org.kie.workbench.common.stunner.core.graph.Node) Definition(org.kie.workbench.common.stunner.core.graph.content.definition.Definition)

Example 75 with Definition

use of org.kie.workbench.common.stunner.core.graph.content.definition.Definition 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

Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)111 Node (org.kie.workbench.common.stunner.core.graph.Node)61 Test (org.junit.Test)46 Element (org.kie.workbench.common.stunner.core.graph.Element)31 Edge (org.kie.workbench.common.stunner.core.graph.Edge)25 Graph (org.kie.workbench.common.stunner.core.graph.Graph)20 ArrayList (java.util.ArrayList)16 Optional (java.util.Optional)14 DRGElement (org.kie.workbench.common.dmn.api.definition.model.DRGElement)14 Name (org.kie.workbench.common.dmn.api.property.dmn.Name)14 Diagram (org.kie.workbench.common.stunner.core.diagram.Diagram)14 View (org.kie.workbench.common.stunner.core.graph.content.view.View)12 Decision (org.kie.workbench.common.dmn.api.definition.model.Decision)11 QName (org.kie.workbench.common.dmn.api.property.dmn.QName)10 List (java.util.List)9 Before (org.junit.Before)9 DMNDiagram (org.kie.workbench.common.dmn.api.definition.model.DMNDiagram)9 HasContentDefinitionId (org.kie.workbench.common.stunner.core.graph.content.HasContentDefinitionId)9 NodeImpl (org.kie.workbench.common.stunner.core.graph.impl.NodeImpl)9 Stream (java.util.stream.Stream)8