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;
}
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;
}
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;
}
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);
}
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);
}
}
Aggregations