Search in sources :

Example 1 with WiresConnectorView

use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView 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 2 with WiresConnectorView

use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView in project kie-wb-common by kiegroup.

the class WiresCanvasViewTest method testRemoveConnector.

@Test
public void testRemoveConnector() {
    final WiresConnectorView view = createConnector();
    canvas.addShape(view);
    assertTrue(canvas.getWiresManager().getConnectorList().contains(view));
    canvas.removeShape(view);
    assertFalse(canvas.getWiresManager().getConnectorList().contains(view));
}
Also used : WiresConnectorView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView) Test(org.junit.Test)

Example 3 with WiresConnectorView

use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView in project kie-wb-common by kiegroup.

the class WiresCanvasView method addShape.

@Override
public WiresCanvas.View addShape(final ShapeView<?> shapeView) {
    if (WiresUtils.isWiresShape(shapeView)) {
        WiresShape wiresShape = (WiresShape) shapeView;
        wiresManager.register(wiresShape);
        wiresManager.getMagnetManager().createMagnets(wiresShape, getMagnetCardinals());
        WiresUtils.assertShapeGroup(wiresShape.getGroup(), WiresCanvas.WIRES_CANVAS_GROUP_ID);
    } else if (WiresUtils.isWiresConnector(shapeView)) {
        WiresConnector wiresConnector = (WiresConnector) shapeView;
        final WiresConnectorControl connectorControl = wiresManager.register(wiresConnector);
        if (shapeView instanceof WiresConnectorView) {
            ((WiresConnectorView) shapeView).setControl(connectorControl);
        }
        WiresUtils.assertShapeGroup(wiresConnector.getGroup(), WiresCanvas.WIRES_CANVAS_GROUP_ID);
    } else {
        super.addShape(shapeView);
    }
    return this;
}
Also used : WiresShape(com.ait.lienzo.client.core.shape.wires.WiresShape) WiresConnector(com.ait.lienzo.client.core.shape.wires.WiresConnector) WiresConnectorView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView) WiresConnectorControl(com.ait.lienzo.client.core.shape.wires.handlers.WiresConnectorControl)

Example 4 with WiresConnectorView

use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView in project kie-wb-common by kiegroup.

the class WiresCanvasViewTest method assertStunnerConnectorGroupId.

@Test
public void assertStunnerConnectorGroupId() {
    final WiresConnectorView view = createConnector();
    canvas.addShape(view);
    assertEquals(WiresCanvas.WIRES_CANVAS_GROUP_ID, WiresUtils.getShapeGroup(view.getGroup()));
}
Also used : WiresConnectorView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView) Test(org.junit.Test)

Example 5 with WiresConnectorView

use of org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView in project kie-wb-common by kiegroup.

the class WiresCanvasViewTest method testAddConnector.

@Test
public void testAddConnector() {
    final WiresConnectorView view = createConnector();
    canvas.addShape(view);
    assertTrue(canvas.getWiresManager().getConnectorList().contains(view));
}
Also used : WiresConnectorView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView) Test(org.junit.Test)

Aggregations

WiresConnectorView (org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView)5 Test (org.junit.Test)3 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)1 WiresConnector (com.ait.lienzo.client.core.shape.wires.WiresConnector)1 WiresShape (com.ait.lienzo.client.core.shape.wires.WiresShape)1 WiresConnectorControl (com.ait.lienzo.client.core.shape.wires.handlers.WiresConnectorControl)1 WiresShapeView (org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView)1 DragProxyCallback (org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback)1 EdgeShape (org.kie.workbench.common.stunner.core.client.shape.EdgeShape)1 ShapeFactory (org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Node (org.kie.workbench.common.stunner.core.graph.Node)1 MagnetConnection (org.kie.workbench.common.stunner.core.graph.content.view.MagnetConnection)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1