Search in sources :

Example 41 with Node

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

the class SetConnectionTargetNodeCommandTest method testExecute.

@Test
@SuppressWarnings("unchecked")
public void testExecute() {
    final List lastTargetInEdges = mock(List.class);
    final List sourceOutEdges = mock(List.class);
    final List targetInEdges = mock(List.class);
    when(source.getOutEdges()).thenReturn(sourceOutEdges);
    when(lastTargetNode.getInEdges()).thenReturn(lastTargetInEdges);
    when(node.getInEdges()).thenReturn(targetInEdges);
    CommandResult<RuleViolation> result = tested.execute(graphCommandExecutionContext);
    final ArgumentCaptor<RuleEvaluationContext> contextCaptor = ArgumentCaptor.forClass(RuleEvaluationContext.class);
    verify(ruleManager, times(3)).evaluate(eq(ruleSet), contextCaptor.capture());
    final List<RuleEvaluationContext> contexts = contextCaptor.getAllValues();
    assertEquals(3, contexts.size());
    verifyConnection((GraphConnectionContext) contexts.get(0), edge, source, node);
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(1), graph, lastTargetNode, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.DELETE));
    verifyConnectorCardinality((ConnectorCardinalityContext) contexts.get(2), graph, node, edge, EdgeCardinalityContext.Direction.INCOMING, Optional.of(CardinalityContext.Operation.ADD));
    assertEquals(CommandResult.Type.INFO, result.getType());
    verify(lastTargetInEdges, times(1)).remove(eq(edge));
    verify(targetInEdges, times(1)).add(eq(edge));
    verify(edgeContent, times(1)).setTargetConnection(any(Connection.class));
    verify(edge, times(1)).setTargetNode(eq(node));
    verify(targetInEdges, times(0)).remove(any(Edge.class));
    verify(sourceOutEdges, times(0)).add(any(Edge.class));
    verify(graphIndex, times(0)).removeEdge(any(Edge.class));
    verify(graphIndex, times(0)).addEdge(any(Edge.class));
    verify(graphIndex, times(0)).addNode(any(Node.class));
    verify(graphIndex, times(0)).removeNode(any(Node.class));
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) Connection(org.kie.workbench.common.stunner.core.graph.content.view.Connection) TestingGraphUtils.verifyConnection(org.kie.workbench.common.stunner.core.TestingGraphUtils.verifyConnection) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) List(java.util.List) RuleEvaluationContext(org.kie.workbench.common.stunner.core.rule.RuleEvaluationContext) RuleViolation(org.kie.workbench.common.stunner.core.rule.RuleViolation) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 42 with Node

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

the class TreeWalkTraverseProcessorImplTest method testTraverseGraph2UsingRootNode.

@Test
@SuppressWarnings("unchecked")
public void testTraverseGraph2UsingRootNode() {
    final TestingGraphInstanceBuilder.TestGraph2 result = TestingGraphInstanceBuilder.newGraph2(graphTestHandler);
    Node anotherNode = graphTestHandler.newNode("anotherNode", "anotherId", Optional.empty());
    final TreeTraverseCallback callback = mock(TreeTraverseCallback.class);
    when(callback.startEdgeTraversal(any(Edge.class))).thenReturn(true);
    when(callback.startNodeTraversal(any(Node.class))).thenReturn(true);
    tested.traverse(result.graph, result.parentNode, callback);
    verify(callback, never()).startNodeTraversal(eq(anotherNode));
    verify(callback, never()).endNodeTraversal(eq(anotherNode));
    verify(callback, times(1)).startGraphTraversal(eq(result.graph));
    verify(callback, times(1)).startNodeTraversal(eq(result.parentNode));
    verify(callback, times(1)).startNodeTraversal(eq(result.startNode));
    verify(callback, times(1)).startNodeTraversal(eq(result.intermNode));
    verify(callback, times(1)).startNodeTraversal(eq(result.endNode));
    verify(callback, times(1)).endNodeTraversal(eq(result.parentNode));
    verify(callback, times(1)).endNodeTraversal(eq(result.startNode));
    verify(callback, times(1)).endNodeTraversal(eq(result.intermNode));
    verify(callback, times(1)).endNodeTraversal(eq(result.endNode));
    verify(callback, times(1)).startEdgeTraversal(eq(result.edge1));
    verify(callback, times(1)).endEdgeTraversal(eq(result.edge1));
    verify(callback, times(1)).startEdgeTraversal(eq(result.edge2));
    verify(callback, times(1)).endEdgeTraversal(eq(result.edge2));
    verify(callback, times(1)).endGraphTraversal();
}
Also used : TestingGraphInstanceBuilder(org.kie.workbench.common.stunner.core.TestingGraphInstanceBuilder) Node(org.kie.workbench.common.stunner.core.graph.Node) Edge(org.kie.workbench.common.stunner.core.graph.Edge) Test(org.junit.Test)

Example 43 with Node

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

the class AbstractGraphRuleHandlerTest method mockNode.

@SuppressWarnings("unchecked")
protected Node mockNode(String id, Set<String> labels) {
    Node e = mock(Node.class);
    View v = mock(View.class);
    Object d = mock(Object.class);
    when(e.getContent()).thenReturn(v);
    when(v.getDefinition()).thenReturn(d);
    when(definitionAdapter.getId(eq(d))).thenReturn(id);
    when(definitionAdapter.getLabels(eq(d))).thenReturn(labels);
    when(e.getLabels()).thenReturn(labels);
    return e;
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View)

Example 44 with Node

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

the class ResizeControlImpl method doResize.

@SuppressWarnings("unchecked")
private CommandResult<CanvasViolation> doResize(final Element<? extends View<?>> element, final Double x, final Double y, final double w, final double h) {
    // Calculate the new graph element's bounds.
    final Point2D current = (null != x && null != y) ? new Point2D(x, y) : GraphUtils.getPosition(element.getContent());
    final BoundsImpl newBounds = new BoundsImpl(new BoundImpl(current.getX(), current.getY()), new BoundImpl(current.getX() + w, current.getY() + h));
    // Check the new bound values that come from the user's action do not exceed graph ones.
    if (!GraphUtils.checkBoundsExceeded(canvasHandler.getDiagram().getGraph(), newBounds)) {
        final CanvasViolation cv = CanvasViolationImpl.Builder.build(new BoundsExceededViolation(newBounds).setUUID(canvasHandler.getUuid()));
        return new CommandResultImpl<>(CommandResult.Type.ERROR, Collections.singleton(cv));
    }
    // Execute the update position and update property/ies command/s on the bean instance to achieve the new bounds.
    final List<Command<AbstractCanvasHandler, CanvasViolation>> commands = getResizeCommands(element, w, h);
    final CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation> commandBuilder = new CompositeCommand.Builder<AbstractCanvasHandler, CanvasViolation>();
    if (null != commands) {
        if (null != x && null != y) {
            commandBuilder.addCommand(canvasCommandFactory.updatePosition((Node<View<?>, Edge>) element, new Point2D(x, y)));
        }
        commands.forEach(commandBuilder::addCommand);
    }
    final CommandResult<CanvasViolation> resizeResults = getCommandManager().execute(canvasHandler, commandBuilder.build());
    // Update the view bounds on the node content after successful resize.
    if (!CommandUtils.isError(resizeResults)) {
        element.getContent().setBounds(newBounds);
    }
    return resizeResults;
}
Also used : CanvasViolation(org.kie.workbench.common.stunner.core.client.command.CanvasViolation) BoundImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl) Node(org.kie.workbench.common.stunner.core.graph.Node) BoundsExceededViolation(org.kie.workbench.common.stunner.core.rule.violations.BoundsExceededViolation) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) Command(org.kie.workbench.common.stunner.core.command.Command) CompositeCommand(org.kie.workbench.common.stunner.core.command.impl.CompositeCommand) BoundsImpl(org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl) CommandResultImpl(org.kie.workbench.common.stunner.core.command.impl.CommandResultImpl)

Example 45 with Node

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

the class CanvasBoundsIndexerImpl method getAt.

@Override
@SuppressWarnings("unchecked")
public Node<View<?>, Edge> getAt(final double x, final double y, final double width, final double height, final Element parentNode) {
    final AbstractCanvas canvas = canvasHandler.getAbstractCanvas();
    final LienzoLayer lienzoLayer = (LienzoLayer) canvas.getLayer();
    Node node;
    final String viewUUID_UL = LienzoLayerUtils.getUUID_At(lienzoLayer, x, y);
    final String viewUUID_UR = LienzoLayerUtils.getUUID_At(lienzoLayer, x + width, y);
    final String viewUUID_CC = LienzoLayerUtils.getUUID_At(lienzoLayer, x + (width / 2), y + (height / 2));
    final String viewUUID_LL = LienzoLayerUtils.getUUID_At(lienzoLayer, x, y + height);
    final String viewUUID_LR = LienzoLayerUtils.getUUID_At(lienzoLayer, x + width, y + height);
    if (null != viewUUID_UL && viewUUID_UL.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID_UL);
        if (null != shape) {
            node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
            if (node != parentNode) {
                return node;
            }
        }
    } else if (null != viewUUID_UR && viewUUID_UR.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID_UR);
        if (null != shape) {
            node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
            if (node != parentNode) {
                return node;
            }
        }
    } else if (null != viewUUID_CC && viewUUID_CC.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID_CC);
        if (null != shape) {
            node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
            if (node != parentNode) {
                return node;
            }
        }
    } else if (null != viewUUID_LL && viewUUID_LL.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID_LL);
        if (null != shape) {
            node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
            if (node != parentNode) {
                return node;
            }
        }
    } else if (null != viewUUID_LR && viewUUID_LR.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID_LR);
        if (null != shape) {
            node = canvasHandler.getGraphIndex().getNode(shape.getUUID());
            if (node != parentNode) {
                return node;
            }
        }
    }
    return null;
}
Also used : LienzoLayer(org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) Node(org.kie.workbench.common.stunner.core.graph.Node)

Aggregations

Node (org.kie.workbench.common.stunner.core.graph.Node)153 Edge (org.kie.workbench.common.stunner.core.graph.Edge)85 View (org.kie.workbench.common.stunner.core.graph.content.view.View)59 Test (org.junit.Test)38 Graph (org.kie.workbench.common.stunner.core.graph.Graph)32 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)24 RuleViolation (org.kie.workbench.common.stunner.core.rule.RuleViolation)21 Bounds (org.kie.workbench.common.stunner.core.graph.content.Bounds)17 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)15 Element (org.kie.workbench.common.stunner.core.graph.Element)14 Metadata (org.kie.workbench.common.stunner.core.diagram.Metadata)13 DefinitionSet (org.kie.workbench.common.stunner.core.graph.content.definition.DefinitionSet)13 EdgeImpl (org.kie.workbench.common.stunner.core.graph.impl.EdgeImpl)13 Matchers.anyString (org.mockito.Matchers.anyString)13 List (java.util.List)12 BoundImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundImpl)12 BoundsImpl (org.kie.workbench.common.stunner.core.graph.content.view.BoundsImpl)12 Before (org.junit.Before)11 Definition (org.kie.workbench.common.stunner.core.graph.content.definition.Definition)11 Child (org.kie.workbench.common.stunner.core.graph.content.relationship.Child)11