Search in sources :

Example 1 with DragProxyCallback

use of org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback in project kie-wb-common by kiegroup.

the class CreateConnectorAction method showDragProxy.

@SuppressWarnings("unchecked")
private DragProxy<AbstractCanvasHandler, ConnectorDragProxy.Item, DragProxyCallback> showDragProxy(final AbstractCanvasHandler canvasHandler, final Edge<? extends ViewConnector<?>, Node> connector, final Node<? extends View<?>, Edge> sourceNode, final int x, final int y) {
    // Built and show the drag proxy.
    final String ssid = canvasHandler.getDiagram().getMetadata().getShapeSetId();
    final ShapeFactory shapeFactory = canvasHandler.getShapeFactory(ssid);
    final ConnectorDragProxy.Item connectorDragItem = new ConnectorDragProxy.Item() {

        @Override
        public Edge<? extends ViewConnector<?>, Node> getEdge() {
            return connector;
        }

        @Override
        public Node<? extends View<?>, Edge> getSourceNode() {
            return sourceNode;
        }

        @Override
        public ShapeFactory<?, ?> getShapeFactory() {
            return shapeFactory;
        }
    };
    return connectorDragProxyFactory.proxyFor(canvasHandler).show(connectorDragItem, x, y, new DragProxyCallback() {

        @Override
        public void onStart(final int x, final int y) {
            start(canvasHandler);
        }

        @Override
        public void onMove(final int x, final int y) {
            final Node targetNode = graphBoundsIndexer.getAt(x, y);
            final boolean allow = allow(x, y, connector, sourceNode, targetNode);
            canvasHighlight.unhighLight();
            if (null != targetNode && allow) {
                canvasHighlight.highLight(targetNode);
            } else if (null != targetNode) {
                canvasHighlight.invalid(targetNode);
            }
        }

        @Override
        public void onComplete(final int x, final int y) {
            final Node targetNode = graphBoundsIndexer.getAt(x, y);
            accept(x, y, connector, sourceNode, targetNode);
        }
    });
}
Also used : Node(org.kie.workbench.common.stunner.core.graph.Node) ShapeFactory(org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory) DragProxyCallback(org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback) Edge(org.kie.workbench.common.stunner.core.graph.Edge) ConnectorDragProxy(org.kie.workbench.common.stunner.core.client.components.drag.ConnectorDragProxy)

Example 2 with DragProxyCallback

use of org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback in project kie-wb-common by kiegroup.

the class CreateConnectorActionTest method testStartDrag.

@SuppressWarnings("unchecked")
private DragProxyCallback testStartDrag() {
    final MouseClickEvent event = mock(MouseClickEvent.class);
    when(event.getX()).thenReturn(100d);
    when(event.getY()).thenReturn(500d);
    when(graphBoundsIndexer.getAt(eq(100d), eq(500d))).thenReturn(targetNode);
    ToolboxAction<AbstractCanvasHandler> cascade = tested.onMouseClick(canvasHandler, NODE_UUID, event);
    assertEquals(tested, cascade);
    verify(edge, times(1)).setSourceNode(eq(element));
    verify(connectorDragProxyFactory, times(1)).proxyFor(eq(canvasHandler));
    ArgumentCaptor<DragProxyCallback> proxyArgumentCaptor = ArgumentCaptor.forClass(DragProxyCallback.class);
    verify(connectorDragProxyFactory, times(1)).show(any(ConnectorDragProxy.Item.class), eq(100), eq(500), proxyArgumentCaptor.capture());
    final DragProxyCallback callback = proxyArgumentCaptor.getValue();
    // Verify drag proxy start.
    callback.onStart(0, 0);
    assertNotNull(tested.getCanvasHighlight());
    verify(graphBoundsIndexer, times(1)).setRootUUID(eq(ROOT_UUID));
    verify(graphBoundsIndexer, times(1)).build(eq(graph));
    verify(edgeBuilderControl, times(1)).enable(eq(canvasHandler));
    ArgumentCaptor<RequiresCommandManager.CommandManagerProvider> providerArgumentCaptor = ArgumentCaptor.forClass(RequiresCommandManager.CommandManagerProvider.class);
    verify(edgeBuilderControl, times(1)).setCommandManagerProvider(providerArgumentCaptor.capture());
    RequiresCommandManager.CommandManagerProvider cmProvider = providerArgumentCaptor.getValue();
    assertEquals(sessionCommandManager, cmProvider.getCommandManager());
    return callback;
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) RequiresCommandManager(org.kie.workbench.common.stunner.core.client.command.RequiresCommandManager) DragProxyCallback(org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback) MouseClickEvent(org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)

Example 3 with DragProxyCallback

use of org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback in project kie-wb-common by kiegroup.

the class CreateConnectorActionTest method testCancelConnector.

@Test
public void testCancelConnector() {
    DragProxyCallback callback = testStartDrag();
    assertTrue(dragProxy == tested.getDragProxy());
    testMoveDrag(callback);
    tested.cancelConnector(cancelCanvasAction);
    verify(dragProxy, times(1)).clear();
    assertNull(tested.getDragProxy());
}
Also used : DragProxyCallback(org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback) Test(org.junit.Test)

Example 4 with DragProxyCallback

use of org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback in project kie-wb-common by kiegroup.

the class CreateConnectorActionTest method testAction.

@Test
@SuppressWarnings("unchecked")
public void testAction() {
    final DragProxyCallback callback = testStartDrag();
    testMoveDrag(callback);
    testCompleteDrag(callback);
}
Also used : DragProxyCallback(org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback) Test(org.junit.Test)

Example 5 with DragProxyCallback

use of org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback 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)

Aggregations

DragProxyCallback (org.kie.workbench.common.stunner.core.client.components.drag.DragProxyCallback)8 Test (org.junit.Test)3 ShapeFactory (org.kie.workbench.common.stunner.core.client.shape.factory.ShapeFactory)2 Edge (org.kie.workbench.common.stunner.core.graph.Edge)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 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 CountDownLatch (java.util.concurrent.CountDownLatch)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 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)1 RequiresCommandManager (org.kie.workbench.common.stunner.core.client.command.RequiresCommandManager)1 ConnectorDragProxy (org.kie.workbench.common.stunner.core.client.components.drag.ConnectorDragProxy)1 EdgeShape (org.kie.workbench.common.stunner.core.client.shape.EdgeShape)1 MouseClickEvent (org.kie.workbench.common.stunner.core.client.shape.view.event.MouseClickEvent)1 Glyph (org.kie.workbench.common.stunner.core.definition.shape.Glyph)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 AbstractDragProxy (org.kie.workbench.common.stunner.lienzo.primitive.AbstractDragProxy)1