Search in sources :

Example 1 with WiresShapeView

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

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

the class LocationControlImplTest method testLocationAcceptor.

@Test
@SuppressWarnings("unchecked")
public void testLocationAcceptor() {
    tested.enable(canvasHandler);
    tested.register(element);
    ArgumentCaptor<ILocationAcceptor> locationAcceptorArgumentCaptor = ArgumentCaptor.forClass(ILocationAcceptor.class);
    verify(wiresManager, times(1)).setLocationAcceptor(locationAcceptorArgumentCaptor.capture());
    final ILocationAcceptor locationAcceptor = locationAcceptorArgumentCaptor.getValue();
    final WiresShapeView wiresContainer = mock(WiresShapeView.class);
    when(wiresContainer.getUUID()).thenReturn(ELEMENT_UUID);
    final com.ait.lienzo.client.core.types.Point2D point = new com.ait.lienzo.client.core.types.Point2D(40d, 50d);
    locationAcceptor.accept(new WiresContainer[] { wiresContainer }, new com.ait.lienzo.client.core.types.Point2D[] { point });
    ArgumentCaptor<CanvasCommand> commandArgumentCaptor = ArgumentCaptor.forClass(CanvasCommand.class);
    verify(commandManager, times(1)).execute(eq(canvasHandler), commandArgumentCaptor.capture());
    final UpdateElementPositionCommand command = (UpdateElementPositionCommand) commandArgumentCaptor.getValue();
    assertEquals(element, command.getElement());
    assertEquals(new Point2D(40d, 50d), command.getLocation());
}
Also used : ILocationAcceptor(com.ait.lienzo.client.core.shape.wires.ILocationAcceptor) Point2D(org.kie.workbench.common.stunner.core.graph.content.view.Point2D) WiresShapeView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView) UpdateElementPositionCommand(org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand) CanvasCommand(org.kie.workbench.common.stunner.core.client.command.CanvasCommand) Test(org.junit.Test)

Example 3 with WiresShapeView

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

the class WiresCanvasViewTest method testAddShape.

@Test
public void testAddShape() {
    final WiresShapeView view = createShape();
    canvas.addShape(view);
    assertNotNull(canvas.getWiresManager().getShape(view.uuid()));
}
Also used : WiresShapeView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView) Test(org.junit.Test)

Example 4 with WiresShapeView

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

the class WiresCanvasViewTest method assertStunnerShapeGroupId.

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

Example 5 with WiresShapeView

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

the class WiresCanvasViewTest method testRemoveShape.

@Test
public void testRemoveShape() {
    final WiresShapeView view = createShape();
    canvas.addShape(view);
    assertNotNull(canvas.getWiresManager().getShape(view.uuid()));
    canvas.removeShape(view);
    assertNull(canvas.getWiresManager().getShape(view.uuid()));
}
Also used : WiresShapeView(org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView) Test(org.junit.Test)

Aggregations

WiresShapeView (org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresShapeView)5 Test (org.junit.Test)4 MultiPath (com.ait.lienzo.client.core.shape.MultiPath)1 ILocationAcceptor (com.ait.lienzo.client.core.shape.wires.ILocationAcceptor)1 WiresConnectorView (org.kie.workbench.common.stunner.client.lienzo.shape.view.wires.WiresConnectorView)1 UpdateElementPositionCommand (org.kie.workbench.common.stunner.core.client.canvas.command.UpdateElementPositionCommand)1 CanvasCommand (org.kie.workbench.common.stunner.core.client.command.CanvasCommand)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 Point2D (org.kie.workbench.common.stunner.core.graph.content.view.Point2D)1 View (org.kie.workbench.common.stunner.core.graph.content.view.View)1