Search in sources :

Example 1 with ElementShape

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

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

the class BaseCanvasHandler method applyElementMutation.

@Override
@SuppressWarnings("unchecked")
public void applyElementMutation(final Shape shape, final Element candidate, final boolean applyPosition, final boolean applyProperties, final MutationContext mutationContext) {
    if (shape instanceof ElementShape) {
        final ElementShape graphShape = (ElementShape) shape;
        this.applyElementMutation(graphShape, candidate, applyPosition, applyProperties, mutationContext);
    } else {
        LOGGER.log(Level.WARNING, "The shape to handle must be type of [" + ElementShape.class.getName() + "]");
    }
}
Also used : ElementShape(org.kie.workbench.common.stunner.core.client.shape.ElementShape)

Aggregations

ElementShape (org.kie.workbench.common.stunner.core.client.shape.ElementShape)2 AbstractCanvas (org.kie.workbench.common.stunner.core.client.canvas.AbstractCanvas)1 EdgeShape (org.kie.workbench.common.stunner.core.client.shape.EdgeShape)1 Shape (org.kie.workbench.common.stunner.core.client.shape.Shape)1 Edge (org.kie.workbench.common.stunner.core.graph.Edge)1 Node (org.kie.workbench.common.stunner.core.graph.Node)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