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;
}
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() + "]");
}
}
Aggregations