Search in sources :

Example 1 with EdgeShape

use of org.kie.workbench.common.stunner.core.client.shape.EdgeShape in project kie-wb-common by kiegroup.

the class NodeDragProxyImpl method show.

@Override
@SuppressWarnings("unchecked")
public DragProxy<AbstractCanvasHandler, Item, NodeDragProxyCallback> show(final Item item, final int x, final int y, final NodeDragProxyCallback callback) {
    final AbstractCanvas canvas = canvasHandler.getAbstractCanvas();
    final Node<View<?>, Edge> node = item.getNode();
    final ShapeFactory<Object, ?> nodeShapeFactory = item.getNodeShapeFactory();
    final Edge<View<?>, Node> inEdge = item.getInEdge();
    final Node<View<?>, Edge> inEdgeSourceNode = item.getInEdgeSourceNode();
    final ShapeFactory<Object, ?> edgeShapeFactory = item.getInEdgeShapeFactory();
    final Shape nodeShape = nodeShapeFactory.newShape(node.getContent().getDefinition());
    if (nodeShape instanceof ElementShape) {
        ((ElementShape) nodeShape).applyProperties(node, MutationContext.STATIC);
    }
    this.transientEdgeShape = (EdgeShape) edgeShapeFactory.newShape(inEdge.getContent().getDefinition());
    canvas.addTransientShape(this.transientEdgeShape);
    this.transientEdgeShape.applyProperties(inEdge, MutationContext.STATIC);
    final Shape<?> edgeSourceNodeShape = canvasHandler.getCanvas().getShape(inEdgeSourceNode.getUUID());
    shapeDragProxyFactory.show(nodeShape, x, y, new DragProxyCallback() {

        @Override
        public void onStart(final int x, final int y) {
            callback.onStart(x, y);
            drawEdge();
        }

        @Override
        public void onMove(final int x, final int y) {
            callback.onMove(x, y);
            drawEdge();
        }

        @Override
        public void onComplete(final int x, final int y) {
            final MagnetConnection[] connections = createShapeConnections();
            callback.onComplete(x, y);
            callback.onComplete(x, y, connections[0], connections[1]);
            deleteTransientEdgeShape();
            canvas.draw();
        }

        private void drawEdge() {
            if (inEdge.getContent() instanceof ViewConnector) {
                final ViewConnector viewConnector = (ViewConnector) inEdge.getContent();
                final MagnetConnection[] connections = createShapeConnections();
                viewConnector.setSourceConnection(connections[0]);
                viewConnector.setTargetConnection(connections[1]);
            }
            NodeDragProxyImpl.this.transientEdgeShape.applyConnections(inEdge, edgeSourceNodeShape.getShapeView(), nodeShape.getShapeView(), MutationContext.STATIC);
            canvas.draw();
        }

        private MagnetConnection[] createShapeConnections() {
            return new MagnetConnection[] { MagnetConnection.Builder.forElement(inEdgeSourceNode), MagnetConnection.Builder.forElement(node) };
        }
    });
    return this;
}
Also used : ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) ViewConnector(org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector) Node(org.kie.workbench.common.stunner.core.graph.Node) View(org.kie.workbench.common.stunner.core.graph.content.view.View) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 2 with EdgeShape

use of org.kie.workbench.common.stunner.core.client.shape.EdgeShape in project kie-wb-common by kiegroup.

the class ShapeUtils method applyConnections.

@SuppressWarnings("unchecked")
public static void applyConnections(final Edge<?, ?> edge, final CanvasHandler canvasHandler, final MutationContext mutationContext) {
    final Canvas<?> canvas = canvasHandler.getCanvas();
    final Node sourceNode = edge.getSourceNode();
    final Node targetNode = edge.getTargetNode();
    final Shape<?> source = sourceNode != null ? canvas.getShape(sourceNode.getUUID()) : null;
    final Shape<?> target = targetNode != null ? canvas.getShape(targetNode.getUUID()) : null;
    EdgeShape connector = (EdgeShape) canvas.getShape(edge.getUUID());
    connector.applyConnections(edge, source != null ? source.getShapeView() : null, target != null ? target.getShapeView() : null, mutationContext);
}
Also used : EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) Node(org.kie.workbench.common.stunner.core.graph.Node)

Example 3 with EdgeShape

use of org.kie.workbench.common.stunner.core.client.shape.EdgeShape in project kie-wb-common by kiegroup.

the class ConnectorDragProxyImpl method show.

@Override
@SuppressWarnings("unchecked")
public DragProxy<AbstractCanvasHandler, Item, DragProxyCallback> show(final Item item, final int x, final int y, final DragProxyCallback callback) {
    // Source connector's shape - Obtain the shape for the source node.
    final Node<View<?>, Edge> sourceNode = item.getSourceNode();
    final Shape<?> sourceNodeShape = getCanvas().getShape(sourceNode.getUUID());
    // Target connector's shape - Create a temporary shape view, that will act as the connector's target node.
    final WiresShapeView transientShapeView = new WiresShapeView<>(new MultiPath().rect(0, 0, 1, 1).setFillAlpha(0).setStrokeAlpha(0));
    getWiresManager().getMagnetManager().createMagnets(transientShapeView);
    // Create the transient connector's shape and view.
    final Edge<View<?>, Node> edge = item.getEdge();
    final Shape<?> edgeShape = ((ShapeFactory<Object, ?>) item.getShapeFactory()).newShape(edge.getContent().getDefinition());
    final EdgeShape connectorShape = (EdgeShape) edgeShape;
    this.connectorShapeView = (WiresConnectorView<?>) edgeShape.getShapeView();
    // Register and update shape's view as for edge bean's state.
    getWiresManager().register(connectorShapeView);
    connectorShape.applyProperties(edge, MutationContext.STATIC);
    // Apply connector's connections for both source and target shapes.
    // Using center connector strategy, so magnet index 0.
    final MagnetConnection centerConnection = new MagnetConnection.Builder().atX(0).atY(0).magnet(0).build();
    connectorShapeView.connect(sourceNodeShape.getShapeView(), centerConnection, transientShapeView, centerConnection);
    // Optimize the index and show the drag proxy for the temporary shape view.
    graphBoundsIndexer.build(canvasHandler.getDiagram().getGraph());
    shapeViewDragProxyFactory.show(transientShapeView, x, y, new DragProxyCallback() {

        @Override
        public void onStart(final int x, final int y) {
            callback.onStart(x, y);
            // As using center magnet, update the connection.
            connectorShapeView.updateForCenterConnection();
        }

        @Override
        public void onMove(final int x, final int y) {
            callback.onMove(x, y);
            // As using center magnet, update the connection.
            connectorShapeView.updateForCenterConnection();
        }

        @Override
        public void onComplete(final int x, final int y) {
            callback.onComplete(x, y);
            deregisterTransientConnector();
            getCanvas().draw();
        }
    });
    return this;
}
Also used : MultiPath(com.ait.lienzo.client.core.shape.MultiPath) EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) Node(org.kie.workbench.common.stunner.core.graph.Node) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory) WiresShapeView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView) View(org.kie.workbench.common.stunner.core.graph.content.view.View) WiresConnectorView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView) MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) WiresShapeView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView) DragProxyCallback(org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback) Edge(org.kie.workbench.common.stunner.core.graph.Edge)

Example 4 with EdgeShape

use of org.kie.workbench.common.stunner.core.client.shape.EdgeShape in project kie-wb-common by kiegroup.

the class ShapeUtilsTest method testApplyConnections.

@Test
@SuppressWarnings("unchecked")
public void testApplyConnections() {
    final Shape startNodeShape = mock(Shape.class);
    final ShapeView startNodeShapeView = mock(ShapeView.class);
    final Shape intermNodeShape = mock(Shape.class);
    final ShapeView intermNodeShapeView = mock(ShapeView.class);
    final EdgeShape edge1EdgeShape = mock(EdgeShape.class);
    when(canvas.getShape(eq(instance2.startNode.getUUID()))).thenReturn(startNodeShape);
    when(canvas.getShape(eq(instance2.intermNode.getUUID()))).thenReturn(intermNodeShape);
    when(canvas.getShape(eq(instance2.edge1.getUUID()))).thenReturn(edge1EdgeShape);
    when(startNodeShape.getShapeView()).thenReturn(startNodeShapeView);
    when(intermNodeShape.getShapeView()).thenReturn(intermNodeShapeView);
    when(edge1EdgeShape.getShapeView()).thenReturn(edge1ShapeView);
    ShapeUtils.applyConnections(instance2.edge1, canvasHandler, MutationContext.STATIC);
    verify(edge1EdgeShape, times(1)).applyConnections(eq(instance2.edge1), eq(startNodeShapeView), eq(intermNodeShapeView), eq(MutationContext.STATIC));
}
Also used : EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) ConnectorShape(org.kie.workbench.common.stunner.core.client.shape.impl.ConnectorShape) Shape(org.kie.workbench.common.stunner.core.client.shape.Shape) EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) ShapeView(org.kie.workbench.common.stunner.core.client.shape.view.ShapeView) Test(org.junit.Test)

Example 5 with EdgeShape

use of org.kie.workbench.common.stunner.core.client.shape.EdgeShape in project kie-wb-common by kiegroup.

the class ConnectorProxyTest method testStart.

@Test
@SuppressWarnings("unchecked")
public void testStart() {
    CanvasCommand<AbstractCanvasHandler> command = mock(CanvasCommand.class);
    doReturn(command).when(commandFactory).addConnector(eq(sourceNode), eq(edge), any(MagnetConnection.class), eq(SHAPE_SET_ID));
    double x = 1d;
    double y = 2d;
    tested.init();
    tested.start(x, y);
    verify(proxy, times(1)).start(eq(x), eq(y));
    EdgeShape edgeShape = view.getShapeBuilder().get();
    assertEquals(connector, edgeShape);
    verify(proxy, times(1)).execute(eq(command));
}
Also used : MagnetConnection(org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection) EdgeShape(org.kie.workbench.common.stunner.core.client.shape.EdgeShape) AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) Test(org.junit.Test)

Aggregations

EdgeShape (org.kie.workbench.common.stunner.core.client.shape.EdgeShape)8 Node (org.kie.workbench.common.stunner.core.graph.Node)5 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)3 Test (org.junit.Test)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)2 View (org.kie.workbench.common.stunner.core.graph.content.view.View)2 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)2 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)1 WiresConnectorView (org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView)1 WiresShapeView (org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView)1 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)1 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 DragProxyCallback (org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback)1 ElementShape (org.kie.workbench.common.stunner.core.client.shape.ElementShape)1 ShapeFactory (org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory)1 ConnectorShape (org.kie.workbench.common.stunner.core.client.shape.impl.ConnectorShape)1 ShapeView (org.kie.workbench.common.stunner.core.client.shape.view.ShapeView)1