Search in sources :

Example 1 with AbstractCanvas

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas 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 AbstractCanvas

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas 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)

Example 3 with AbstractCanvas

use of org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas 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 AbstractCanvas canvas = canvasHandler.getAbstractCanvas();
    final LienzoLayer lienzoLayer = (LienzoLayer) canvas.getLayer();
    final String viewUUID = LienzoLayerUtils.getUUID_At(lienzoLayer, x, y);
    if (null != viewUUID && viewUUID.trim().length() > 0) {
        final Shape<?> shape = canvas.getShape(viewUUID);
        if (null != shape) {
            return canvasHandler.getGraphIndex().getNode(shape.getUUID());
        }
    }
    return null;
}
Also used : LienzoLayer(org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)

Example 4 with AbstractCanvas

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

the class DiagramPresenterFactoryImpl method newViewer.

@Override
@SuppressWarnings("unchecked")
public DiagramViewer<Diagram, ?> newViewer(final Diagram diagram) {
    final CanvasFactory<AbstractCanvas, AbstractCanvasHandler> canvasFactory = shapeManager.getCanvasFactory(diagram);
    final AbstractCanvas canvas = canvasFactory.newCanvas();
    final AbstractCanvasHandler canvasHandler = canvasFactory.newCanvasHandler();
    final ZoomControl<AbstractCanvas> zoomControl = canvasFactory.newControl(ZoomControl.class);
    final SelectionControl<AbstractCanvasHandler, Element> selectionControl = canvasFactory.newControl(SelectionControl.class);
    return new DiagramViewerImpl<>(canvas, canvasHandler, viewInstances.get(), zoomControl, selectionControl, canvasControlDisposer);
}
Also used : AbstractCanvasHandler(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler) AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas) Element(org.kie.workbench.common.stunner.core.graph.Element)

Example 5 with AbstractCanvas

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

the class BaseSessionScreen method onSessionDiagramOpenedEvent.

void onSessionDiagramOpenedEvent(@Observes final SessionDiagramOpenedEvent sessionDiagramOpenedEvent) {
    checkNotNull("sessionDiagramOpenedEvent", sessionDiagramOpenedEvent);
    final AbstractCanvas canvas = getCanvas();
    if (canvas != null && canvas.equals(sessionDiagramOpenedEvent.getSession().getCanvas())) {
        // Force to reload current session, for example, when a new diagram is just created.
        open(session);
    }
}
Also used : AbstractCanvas(org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)

Aggregations

AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)7 Test (org.junit.Test)2 LienzoLayer (org.kie.workbench.common.stunner.client.lienzo.canvas.LienzoLayer)2 AbstractCanvasHandler (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvasHandler)2 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)2 Node (org.kie.workbench.common.stunner.core.graph.Node)2 Layer (org.kie.workbench.common.stunner.core.client.canvas.Layer)1 Transform (org.kie.workbench.common.stunner.core.client.canvas.Transform)1 EdgeShape (org.kie.workbench.common.stunner.core.client.shape.EdgeShape)1 ElementShape (org.kie.workbench.common.stunner.core.client.shape.ElementShape)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Element (org.kie.workbench.common.stunner.core.graph.Element)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 ViewConnector (org.kie.workbench.common.stunner.core.graph.content.view.ViewConnector)1